From 44a321cb8a42d6c0ea2d96a1086a17f2134c89cc Mon Sep 17 00:00:00 2001 From: Ethan Galstad Date: Thu, 28 Feb 2002 06:42:51 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c --- contrib/aix/check_ping | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 contrib/aix/check_ping (limited to 'contrib/aix/check_ping') diff --git a/contrib/aix/check_ping b/contrib/aix/check_ping new file mode 100644 index 00000000..aaa8c84e --- /dev/null +++ b/contrib/aix/check_ping @@ -0,0 +1,117 @@ +#!/usr/bin/perl -w + +#================================================================ +# +# This perl script will accept an argument and simply pass it +# to ping. It works by sending 2 ping to the specified host +# and evaluating on the average delta time of those 2 pings. +# +# Author: SpEnTBoY +# Email: lonny@abyss.za.org +# April 5,2000 +# +#================================================================ + +#============================ +# State predefined stuff and +# requirements +#============================ + +require 5.004; +use POSIX; +use strict; + +sub usage; + +my $ipaddr = $ARGV[0]; + +my $TIMEOUT = 15; + +my %ERRORS = ('UNKNOWN' , '-1', + 'OK' , '0', + 'WARNING', '1', + 'CRITICAL', '2'); + +my $remote = shift || &usage(%ERRORS); +my $warning = shift || 750; +my $critical = shift || 1000; + +my $state = "OK"; +my $answer = undef; +my $offset = undef; +my $line = undef; + +#============================================================ +# If theres no response we can exit the bloody thing cleanly +# last thing I want to do is hang an AIX system ;-) +#============================================================ + +$SIG{'ALRM'} = sub { + print ("ERROR: No response from PING! (alarm)\n"); + exit $ERRORS{"UNKNOWN"}; +}; +alarm($TIMEOUT); + +#================================================ +# Pass stddn from $ARGV to the command and parse +# the info we need (namely the value for "max" +#================================================ + + + +open(PING,"/usr/sbin/ping -c 2 '$ipaddr' >&1|"); +while () { + $line = $_; + if (/round-trip min\/avg\/max = (.+)\/(.+)\/(.+) ms/) { + $offset = $3; + last; + } +} + +#================================================== +# Do some error checking on the output of the file +# and implement values for and +# deffinitions if they were specified by the user +# or sub in the predefined ones +#================================================== + +if (defined $offset) { + if (abs($offset) > $warning) { + if (abs($offset) > $critical) { + $state = "CRITICAL"; + $answer = ": Ping Time $offset MS greater than +/- $critical MS\n"; + } else { + $state = "WARNING"; + $answer = ": Ping Time $offset MS greater than +/- $warning MS\n"; + } + } else { + $state = "OK"; + $answer = ": Ping Time $offset MS\n"; + } +} else { + $state = "UNKNOWN"; + $answer = ": $line\n"; +} +print ("$state$answer"); +exit $ERRORS{$state}; + +sub usage { + print "\n"; + print "#=========================================\n"; + print "Check_Ping 0.02 script by Lonny Selinger\n"; + print "Made with AIX in mind ;-)\n"; + print "#=========================================\n"; + print "\n"; + print "#================================================\n"; + print " I'm going to need a few more arguments from you\n"; + print "#================================================\n"; + print "\n"; + print "#================================================\n"; + print "Usage: check_ping [ []\n"; + print "#================================================\n"; + print "\n"; + print " = Ping in MS at which a warning message will be generated.\n Defaults to 750.\n"; + print " = Ping in MS at which a critical message will be generated.\n Defaults to 1000.\n\n"; + exit $ERRORS{"UNKNOWN"}; +} + -- cgit v1.2.3-74-g34f1