~ubuntu-branches/ubuntu/precise/nagios-plugins/precise-proposed

« back to all changes in this revision

Viewing changes to contrib/aix/check_ping

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2004-06-15 15:37:48 UTC
  • Revision ID: james.westby@ubuntu.com-20040615153748-pq7702qdzghqfcns
Tags: upstream-1.3.1.0
ImportĀ upstreamĀ versionĀ 1.3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
#================================================================
 
4
#
 
5
# This perl script will accept an argument and simply pass it
 
6
# to ping.  It works by sending 2 ping to the specified host
 
7
# and evaluating on the average delta time of those 2 pings.
 
8
#
 
9
#    Author: SpEnTBoY 
 
10
#    Email: lonny@abyss.za.org
 
11
#    April 5,2000
 
12
#
 
13
#================================================================
 
14
 
 
15
#============================
 
16
# State predefined stuff and
 
17
#       requirements
 
18
#============================
 
19
 
 
20
require 5.004;
 
21
use POSIX;
 
22
use strict;
 
23
 
 
24
sub usage;
 
25
 
 
26
my $ipaddr = $ARGV[0];
 
27
 
 
28
my $TIMEOUT = 15;
 
29
 
 
30
my %ERRORS = ('UNKNOWN' , '-1',
 
31
              'OK' , '0',
 
32
              'WARNING', '1',
 
33
              'CRITICAL', '2');
 
34
 
 
35
my $remote = shift || &usage(%ERRORS);
 
36
my $warning = shift || 750;
 
37
my $critical = shift || 1000;
 
38
 
 
39
my $state = "OK";
 
40
my $answer = undef;
 
41
my $offset = undef;
 
42
my $line = undef;
 
43
 
 
44
#============================================================
 
45
# If theres no response we can exit the bloody thing cleanly
 
46
# last thing I want to do is hang an AIX system ;-)
 
47
#============================================================
 
48
 
 
49
$SIG{'ALRM'} = sub {
 
50
     print ("ERROR: No response from PING! (alarm)\n");
 
51
     exit $ERRORS{"UNKNOWN"};
 
52
};
 
53
alarm($TIMEOUT);
 
54
 
 
55
#================================================
 
56
# Pass stddn from $ARGV to the command and parse
 
57
# the info we need (namely the value for "max"
 
58
#================================================
 
59
 
 
60
 
 
61
 
 
62
open(PING,"/usr/sbin/ping -c 2 '$ipaddr' >&1|");
 
63
while (<PING>) {
 
64
        $line = $_;
 
65
        if (/round-trip min\/avg\/max = (.+)\/(.+)\/(.+) ms/) {
 
66
        $offset = $3;
 
67
        last;
 
68
    }
 
69
}
 
70
 
 
71
#==================================================
 
72
# Do some error checking on the output of the file
 
73
# and implement values for <crit> and <warn> 
 
74
# deffinitions if they were specified by the user
 
75
# or sub in the predefined ones
 
76
#==================================================
 
77
 
 
78
if (defined $offset) {
 
79
    if (abs($offset) > $warning) {
 
80
        if (abs($offset) > $critical) {
 
81
            $state = "CRITICAL";
 
82
            $answer = ": Ping Time $offset MS greater than +/- $critical MS\n";
 
83
        } else {
 
84
            $state = "WARNING";
 
85
            $answer = ": Ping Time $offset MS greater than +/- $warning MS\n";
 
86
        }
 
87
    } else {
 
88
        $state = "OK";
 
89
        $answer = ": Ping Time $offset MS\n";
 
90
    }
 
91
} else {
 
92
    $state = "UNKNOWN";
 
93
    $answer = ": $line\n";
 
94
}
 
95
print ("$state$answer");
 
96
exit $ERRORS{$state};
 
97
 
 
98
sub usage {
 
99
        print "\n";
 
100
        print "#=========================================\n";
 
101
        print "Check_Ping 0.02 script by Lonny Selinger\n";
 
102
        print "Made with AIX in mind ;-)\n";
 
103
        print "#=========================================\n";
 
104
        print "\n";
 
105
        print "#================================================\n";
 
106
        print " I'm going to need a few more arguments from you\n";
 
107
        print "#================================================\n";
 
108
        print "\n";
 
109
        print "#================================================\n";
 
110
        print "Usage: check_ping <host> [<warn> [<crit>]\n";
 
111
        print "#================================================\n";
 
112
        print "\n";
 
113
        print "<warn> = Ping in MS at which a warning message will be generated.\n      Defaults to 750.\n";
 
114
        print "<crit> = Ping in MS at which a critical message will be generated.\n     Defaults to 1000.\n\n";
 
115
        exit $ERRORS{"UNKNOWN"};
 
116
}
 
117