- 论坛徽章:
- 0
|
本帖最后由 baroquesoul 于 2012-02-07 13:38 编辑
我之前写的监控脚本,,通过exit返回值来判断告警级别,分别是
3 Unknown
2 Critical
1 Warning
0 OK
具体数值可以通过print类似函数的输出,具体格式就是:
你期望的输出 | 监控项=当前值;Warning阀值;Critical阀值
其中 Warning阀值和Critical阀值可以通过外部输入获得。
-------------------------------------------------------------------------
#!/usr/bin/perl
use Digest::CRC;
use IO::Socket::INET;
use strict;
#===主程序================================================
if ($ARGV[0] == "-q" && $ARGV[2] == "-H" && $ARGV[4] == "-P" && $ARGV[6] == "-w" && $ARGV[8] == "-c" && $ARGV[10] == "-C" && $ARGV[11] !="")
{
my $check = 1;
my $recall = $ARGV[1];
my $HOST = $ARGV[3];
my $PORT = $ARGV[5];
my $WARN = $ARGV[7];
my $CRIT = $ARGV[9];
my $COU = $ARGV[11];
my $query = &CRC ($recall);
my @call = split(//,$recall);
my @dlen = (@call[8..11]);
my $lenth = join("",@dlen);
my $ll = hex($lenth)*2+5;
my $respon = "";
while ($check == "1")
{
sleep 1;
$respon = &TEL($HOST,$PORT,$query,$ll);
$check = &CRCCH($respon);
}
my $result = &CHAG($respon,$COU);
#=========数值判断==========================
if ($result < 1)
{
printf("UNKNOWN! - Current is %.1f A !|current=$result;$WARN;$CRIT\n",$result);
exit 3;
}
elsif ($result < $WARN)
{
printf("OK - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
exit 0;
}elsif ($result < $CRIT)
{
printf("WARNING! - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
exit 1;
}elsif ($result < 50)
{
printf("CRITICAL! - Current is %.1f A .|current=$result;$WARN;$CRIT\n",$result);
exit 2;
}else
{
printf("UNKNOWN! - Current is %.1f A !|current=$result;$WARN;$CRIT\n",$result);
exit 3;
}
}else{
&HELP;
}
exit;
#==子程序=====================================================
#==Telnet=取数据===============================================
sub TEL
{
}
#=CRC16=校验=================================================
sub CRC
{
}
#==CheckSum=返回值校=========================================
sub CRCCH
{
}
#=========HexToDec=十六进制转十进制=========================================
sub CHAG
{
}
#=========HELP=========================================
sub HELP
{
print "\nUsage: check_modubs [-h] -q query -H host -P port -w warn -c crit -C count\n";
print "-h help\n";
print "-q query Query command such as:010400010001 Don't get the CRC.\n";
print "-H host Host is such as:10.0.0.1.\n";
print "-P port The port of Host such as:1001.\n";
print "-w Warning Value.\n";
print "-c Critical Valeu.\n";
print "-C count The count for the result caclu.\n";
print "If any problem, Please connact dongyanqiong\@cnpc.com.cn\n\n";
|
|