diff options
-rw-r--r-- | contrib/check_appletalk.pl | 210 |
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 | # | ||
16 | BEGIN { | ||
17 | if ( $0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/ ) { | ||
18 | $runtimedir = $1; | ||
19 | $PROGNAME = $2; | ||
20 | } | ||
21 | delete $ENV{'LANG'}; | ||
22 | } | ||
23 | |||
24 | use strict; | ||
25 | use lib utils.pm; | ||
26 | |||
27 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | ||
28 | use vars qw($PROGNAME); | ||
29 | |||
30 | $PROGNAME = "check_atalk"; | ||
31 | |||
32 | my ( | ||
33 | $verbose, $host, $warning_avg, $warning_loss, | ||
34 | $critical_avg, $critical_loss, $count, $cmd, | ||
35 | $avg, $loss, $line | ||
36 | ); | ||
37 | my ( $opt_c, $opt_w, $opt_H, $opt_p ); | ||
38 | $opt_c = $opt_w = $opt_p = $opt_H = ''; | ||
39 | |||
40 | sub print_help (); | ||
41 | sub print_usage (); | ||
42 | sub help (); | ||
43 | sub 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 | }; | ||
50 | alarm($TIMEOUT); | ||
51 | |||
52 | delete @ENV{ 'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' }; | ||
53 | |||
54 | use Getopt::Long; | ||
55 | Getopt::Long::Configure( 'bundling', 'no_ignore_case' ); | ||
56 | GetOptions( | ||
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); | ||
68 | unless ($opt_H) { print_usage (); exit $ERRORS{'UNKNOWN'}; } | ||
69 | if ( $opt_H && $opt_H =~ m/^([-a-zA-Z\.\:0-9]+)$/ ) { | ||
70 | $host = $1; | ||
71 | } | ||
72 | else { | ||
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; | ||
79 | if ( $opt_p && $opt_p =~ m/^([1-9]+[0-9]*)$/ ) { | ||
80 | $count = $1; | ||
81 | } | ||
82 | else { | ||
83 | print "$opt_p is not a valid packet number\n"; | ||
84 | exit $ERRORS{'UNKNOWN'}; | ||
85 | } | ||
86 | |||
87 | if ( $opt_w && $opt_w =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) { | ||
88 | $warning_avg = $1; | ||
89 | $warning_loss = $2; | ||
90 | } | ||
91 | else { | ||
92 | print "$opt_w is not a valid threshold\n"; | ||
93 | exit $ERRORS{'UNKNOWN'}; | ||
94 | } | ||
95 | |||
96 | if ( $opt_c && $opt_c =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) { | ||
97 | $critical_avg = $1; | ||
98 | $critical_loss = $2; | ||
99 | } | ||
100 | else { | ||
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 |"; | ||
106 | print "$cmd\n" if ($verbose); | ||
107 | open CMD, $cmd; | ||
108 | |||
109 | while (<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 | |||
124 | sub 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 | |||
143 | "THRESHOLD is <rta>,<pl>% where <rta> is the round trip average | ||
144 | travel\n"; | ||
145 | |||
146 | "time (ms) which triggers a WARNING or CRITICAL state, and <pl> | ||
147 | is the\n"; | ||
148 | print "percentage of packet loss to trigger an alarm state.\n"; | ||
149 | print "\n"; | ||
150 | |||
151 | support(); | ||
152 | } | ||
153 | |||
154 | sub 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 | |||
161 | sub version () { | ||
162 | print_revision( $PROGNAME, '$Revision$ ' ); | ||
163 | exit $ERRORS{'OK'}; | ||
164 | } | ||
165 | |||
166 | sub help () { | ||
167 | print_help (); | ||
168 | exit $ERRORS{'OK'}; | ||
169 | } | ||
170 | |||
171 | my $state = "OK"; | ||
172 | my $answer = undef; | ||
173 | |||
174 | if ( 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 | ||
191 | ms\n"; | ||
192 | } | ||
193 | else { | ||
194 | $state = "UNKNOWN"; | ||
195 | $answer = "UNKNOWN - $line"; | ||
196 | } | ||
197 | print $answer; | ||
198 | exit $ERRORS{$state}; | ||
199 | |||
200 | |||
201 | |||
202 | |||
203 | ------------------------------------------------------- | ||
204 | This sf.net email is sponsored by:ThinkGeek | ||
205 | Welcome to geek heaven. | ||
206 | http://thinkgeek.com/sf | ||
207 | _______________________________________________ | ||
208 | Nagios-devel mailing list | ||
209 | Nagios-devel@lists.sourceforge.net | ||
210 | https://lists.sourceforge.net/lists/listinfo/nagios-devel | ||