3
#================================================================
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.
10
# Email: lonny@abyss.za.org
13
#================================================================
15
#============================
16
# State predefined stuff and
18
#============================
26
my $ipaddr = $ARGV[0];
30
my %ERRORS = ('UNKNOWN' , '-1',
35
my $remote = shift || &usage(%ERRORS);
36
my $warning = shift || 750;
37
my $critical = shift || 1000;
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
#============================================================
50
print ("ERROR: No response from PING! (alarm)\n");
51
exit $ERRORS{"UNKNOWN"};
55
#================================================
56
# Pass stddn from $ARGV to the command and parse
57
# the info we need (namely the value for "max"
58
#================================================
62
open(PING,"/usr/sbin/ping -c 2 '$ipaddr' >&1|");
65
if (/round-trip min\/avg\/max = (.+)\/(.+)\/(.+) ms/) {
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
#==================================================
78
if (defined $offset) {
79
if (abs($offset) > $warning) {
80
if (abs($offset) > $critical) {
82
$answer = ": Ping Time $offset MS greater than +/- $critical MS\n";
85
$answer = ": Ping Time $offset MS greater than +/- $warning MS\n";
89
$answer = ": Ping Time $offset MS\n";
93
$answer = ": $line\n";
95
print ("$state$answer");
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";
105
print "#================================================\n";
106
print " I'm going to need a few more arguments from you\n";
107
print "#================================================\n";
109
print "#================================================\n";
110
print "Usage: check_ping <host> [<warn> [<crit>]\n";
111
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"};