aboutsummaryrefslogtreecommitdiff
path: root/contrib/aix/check_ping
diff options
context:
space:
mode:
authorGravatar Ethan Galstad <egalstad@users.sourceforge.net> 2002-02-28 06:42:51 +0000
committerGravatar Ethan Galstad <egalstad@users.sourceforge.net> 2002-02-28 06:42:51 +0000
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/aix/check_ping
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/aix/check_ping')
-rw-r--r--contrib/aix/check_ping117
1 files changed, 117 insertions, 0 deletions
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 (<PING>) {
+ $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 <crit> and <warn>
+# 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 <host> [<warn> [<crit>]\n";
+ print "#================================================\n";
+ print "\n";
+ print "<warn> = Ping in MS at which a warning message will be generated.\n Defaults to 750.\n";
+ print "<crit> = Ping in MS at which a critical message will be generated.\n Defaults to 1000.\n\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+