老大的需求,对指定IP进行ping,当到达一定的阀值,如50ms,那么就cirtical,并且对其进行一次tracertroute,我们都知道对前面的需求,很好解决,那就是check_ping这个插件就能解决,但它还无法满足后面的需求,咋办?只有自己开发了,好了,那就干吧!~
[过程]
commands.cfg
define command{
command_name check_ping_dev
command_line $USER1$/check_ping_dev $HOSTADDRESS$ $ARG1$ $ARG2$ 10
}
services.cfg
define service {
name mrtg-services-init
service_description ping
check_command check_ping_dev!50,50%!50,50%
check_period 24x7
max_check_attempts 2
normal_check_interval 5
retry_check_interval 2
contact_groups sagroup
notification_interval 5
notification_period 24x7
notification_options w,u,c,r
register 0
}
define service {
use mrtg-services-init
host_name M-x.x.x.x,M-y.y.y.y
}
那么现在开发check_ping_dev
#!/usr/bin/perl
$USR1="/usr/local/nagios/libexec";
$ARG1=$ARGV[0];
$ARG2=$ARGV[1];
$ARG3=$ARGV[2];
$ARG4=$ARGV[3];
$result = `$USR1/check_ping -H $ARG1 -w $ARG2 -c $ARG3 -p $ARG4`;
@results=split(" ",$result);
if( grep(/CRITICAL/,@results) ){
printf($result);
print "\n";
`$USR1/save_log $ARG1`;
exit 2;
}
else{
printf($result);
print "\n";
exit 0;
}
save_log的作用就是记录tracert
#!/usr/bin/perl
use POSIX qw(strftime);
$dtime = strftime "%Y%m%d %H:%M:%S", localtime(time());
$SAVE_PATH="/tmp";
$RAG1=$ARGV[0];
$result=`/bin/traceroute $RAG1`;
open("FH",">>$SAVE_PATH/$RAG1");
print FH $dtime."\n";
print FH $result."\n";
close(FH);
好了,满足公司的需求,解决问题!~
开始搞python。。。