summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/check_appletalk.pl210
1 files changed, 210 insertions, 0 deletions
diff --git a/contrib/check_appletalk.pl b/contrib/check_appletalk.pl
new file mode 100644
index 0000000..0b7754f
--- /dev/null
+++ b/contrib/check_appletalk.pl
@@ -0,0 +1,210 @@
1#! /usr/bin/perl -wT
2#
3# check_atalk_ping plugin for nagios
4#
5# usage:
6# check_atalk_ping atalkaddress
7#
8# Checks if an atalkhost responds to an atalk echo
9# using "aecho"
10#
11# initial version: 23 October 2002 by Stefan Beck, IT Software Solutions
12# current status: $Revision$
13#
14# Copyright Notice: GPL
15#
16BEGIN {
17 if ( $0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/ ) {
18 $runtimedir = $1;
19 $PROGNAME = $2;
20 }
21 delete $ENV{'LANG'};
22}
23
24use strict;
25use lib utils.pm;
26
27use utils qw($TIMEOUT %ERRORS &print_revision &support);
28use vars qw($PROGNAME);
29
30$PROGNAME = "check_atalk";
31
32my (
33 $verbose, $host, $warning_avg, $warning_loss,
34 $critical_avg, $critical_loss, $count, $cmd,
35 $avg, $loss, $line
36);
37my ( $opt_c, $opt_w, $opt_H, $opt_p );
38$opt_c = $opt_w = $opt_p = $opt_H = '';
39
40sub print_help ();
41sub print_usage ();
42sub help ();
43sub version ();
44
45# Just in case of problems, let's not hang NetSaint
46$SIG{'ALRM'} = sub {
47 print "Plugin Timeout\n";
48 exit 2;
49};
50alarm($TIMEOUT);
51
52delete @ENV{ 'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
53
54use Getopt::Long;
55Getopt::Long::Configure( 'bundling', 'no_ignore_case' );
56GetOptions(
57 "V|version" => \&version,
58 "h|help" => \&help,
59 "p|packets=i" => \$opt_p,
60 "c|critical=s" => \$opt_c,
61 "w|warning=s" => \$opt_w,
62 "H|hostname=s" => \$opt_H
63);
64
65
66# appletalk hostname ot address
67$opt_H = shift unless ($opt_H);
68unless ($opt_H) { print_usage (); exit $ERRORS{'UNKNOWN'}; }
69if ( $opt_H && $opt_H =~ m/^([-a-zA-Z\.\:0-9]+)$/ ) {
70 $host = $1;
71}
72else {
73 print "$opt_H is not a valid host name\n";
74 exit $ERRORS{'UNKNOWN'};
75}
76
77# number of packets
78$opt_p = 5 unless $opt_p;
79if ( $opt_p && $opt_p =~ m/^([1-9]+[0-9]*)$/ ) {
80 $count = $1;
81}
82else {
83 print "$opt_p is not a valid packet number\n";
84 exit $ERRORS{'UNKNOWN'};
85}
86
87if ( $opt_w && $opt_w =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
88 $warning_avg = $1;
89 $warning_loss = $2;
90}
91else {
92 print "$opt_w is not a valid threshold\n";
93 exit $ERRORS{'UNKNOWN'};
94}
95
96if ( $opt_c && $opt_c =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
97 $critical_avg = $1;
98 $critical_loss = $2;
99}
100else {
101 print "$opt_c is not a valid threshold\n";
102 exit $ERRORS{'UNKNOWN'};
103}
104
105$cmd = "/usr/bin/aecho -c $count $host 2>&1 |";
106print "$cmd\n" if ($verbose);
107open CMD, $cmd;
108
109while (<CMD>) {
110 print $_ if ($verbose);
111 $line = $_;
112
113 # 5 packets sent, 5 packets received, 0% packet loss
114 # round-trip (ms) min/avg/max = 0/0/0
115
116 if (/received, ([0-9]+)% packet loss/) {
117 $loss = $1;
118 }
119 if (/min\/avg\/max = [0-9]+\/([0-9]+)\/[0-9]+/) {
120 $avg = $1;
121 }
122}
123
124sub print_help() {
125 print_revision( $PROGNAME, '$Revision$ ' );
126 print "Copyright (c) 2002 Stefan Beck\n";
127 print "\n";
128 print "Check if an atalkhost responds to an atalk echo using\n";
129 print " aecho -c <packets> <atalkhost>\n";
130 print "\n";
131 print_usage ();
132 print "\n";
133 print "-H, --hostname=HOST\n";
134 print " host to ping\n";
135 print "-w, --warning=THRESHOLD\n";
136 print " warning threshold pair\n";
137 print "-c, --critical=THRESHOLD\n";
138 print " critical threshold pair\n";
139 print "-p, --packets=INTEGER\n";
140 print " number of ICMP ECHO packets to send (Default: 5)\n";
141 print "\n";
142 print
143 "THRESHOLD is <rta>,<pl>% where <rta> is the round trip average
144travel\n";
145 print
146 "time (ms) which triggers a WARNING or CRITICAL state, and <pl>
147is the\n";
148 print "percentage of packet loss to trigger an alarm state.\n";
149 print "\n";
150
151 support();
152}
153
154sub print_usage () {
155 print "$PROGNAME -H atalkhost -w <wrta>,<wpl>% -c <crta>,<cpl>%\n";
156 print " [-p packets] [-t timeout] [-L]\n";
157 print "$PROGNAME [-h | --help]\n";
158 print "$PROGNAME [-V | --version]\n";
159}
160
161sub version () {
162 print_revision( $PROGNAME, '$Revision$ ' );
163 exit $ERRORS{'OK'};
164}
165
166sub help () {
167 print_help ();
168 exit $ERRORS{'OK'};
169}
170
171my $state = "OK";
172my $answer = undef;
173
174if ( defined $loss && defined $avg ) {
175 if ( $loss >= $critical_loss ) {
176 $state = "CRITICAL";
177 }
178 elsif ( $avg >= $critical_avg ) {
179 $state = "CRITICAL";
180 }
181 elsif ( $loss >= $warning_loss ) {
182 $state = "WARNING";
183 }
184 elsif ( $avg >= $warning_avg ) {
185 $state = "WARNING";
186 }
187 else {
188 $state = "OK";
189 }
190 $answer = "Appletalk PING $state - Packet loss = $loss%, RTA = $avg
191ms\n";
192}
193else {
194 $state = "UNKNOWN";
195 $answer = "UNKNOWN - $line";
196}
197print $answer;
198exit $ERRORS{$state};
199
200
201
202
203-------------------------------------------------------
204This sf.net email is sponsored by:ThinkGeek
205Welcome to geek heaven.
206http://thinkgeek.com/sf
207_______________________________________________
208Nagios-devel mailing list
209Nagios-devel@lists.sourceforge.net
210https://lists.sourceforge.net/lists/listinfo/nagios-devel