| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #!/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"};
- }
|