Fixed bug in tools/setup if docbook was run
[monitoring-plugins.git] / contrib / check_appletalk.pl
blob6df4c7a1d0708b7dff9ef1cfd79857fe1849bdf0
1 #! /usr/bin/perl -wT
3 # check_atalk_ping plugin for nagios
5 # usage:
6 # check_atalk_ping atalkaddress
8 # Checks if an atalkhost responds to an atalk echo
9 # using "aecho"
11 # initial version: 23 October 2002 by Stefan Beck, IT Software Solutions
12 # current status: $Revision$
14 # Copyright Notice: GPL
16 BEGIN {
17 if ( $0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/ ) {
18 $runtimedir = $1;
19 $PROGNAME = $2;
21 delete $ENV{'LANG'};
24 use strict;
25 use lib "/usr/local/nagios/libexec";
27 use utils qw($TIMEOUT %ERRORS &print_revision &support);
28 use vars qw($PROGNAME);
30 $PROGNAME = "check_atalk";
32 my (
33 $verbose, $host, $warning_avg, $warning_loss,
34 $critical_avg, $critical_loss, $count, $cmd,
35 $avg, $loss, $line
37 my ( $opt_c, $opt_w, $opt_H, $opt_p );
38 $opt_c = $opt_w = $opt_p = $opt_H = '';
40 sub print_help ();
41 sub print_usage ();
42 sub help ();
43 sub version ();
45 # Just in case of problems, let's not hang NetSaint
46 $SIG{'ALRM'} = sub {
47 print "Plugin Timeout\n";
48 exit 2;
50 alarm($TIMEOUT);
52 delete @ENV{ 'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
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
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;
72 else {
73 print "$opt_H is not a valid host name\n";
74 exit $ERRORS{'UNKNOWN'};
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;
82 else {
83 print "$opt_p is not a valid packet number\n";
84 exit $ERRORS{'UNKNOWN'};
87 if ( $opt_w && $opt_w =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
88 $warning_avg = $1;
89 $warning_loss = $2;
91 else {
92 print "$opt_w is not a valid threshold\n";
93 exit $ERRORS{'UNKNOWN'};
96 if ( $opt_c && $opt_c =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
97 $critical_avg = $1;
98 $critical_loss = $2;
100 else {
101 print "$opt_c is not a valid threshold\n";
102 exit $ERRORS{'UNKNOWN'};
105 $cmd = "/usr/bin/aecho -c $count $host 2>&1 |";
106 print "$cmd\n" if ($verbose);
107 open CMD, $cmd;
109 while (<CMD>) {
110 print $_ if ($verbose);
111 $line = $_;
113 # 5 packets sent, 5 packets received, 0% packet loss
114 # round-trip (ms) min/avg/max = 0/0/0
116 if (/received, ([0-9]+)% packet loss/) {
117 $loss = $1;
119 if (/min\/avg\/max = [0-9]+\/([0-9]+)\/[0-9]+/) {
120 $avg = $1;
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 print
143 "THRESHOLD is <rta>,<pl>% where <rta> is the round trip average
144 travel\n";
145 print
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";
151 support();
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";
161 sub version () {
162 print_revision( $PROGNAME, '$Revision$ ' );
163 exit $ERRORS{'OK'};
166 sub help () {
167 print_help ();
168 exit $ERRORS{'OK'};
171 my $state = "OK";
172 my $answer = undef;
174 if ( defined $loss && defined $avg ) {
175 if ( $loss >= $critical_loss ) {
176 $state = "CRITICAL";
178 elsif ( $avg >= $critical_avg ) {
179 $state = "CRITICAL";
181 elsif ( $loss >= $warning_loss ) {
182 $state = "WARNING";
184 elsif ( $avg >= $warning_avg ) {
185 $state = "WARNING";
187 else {
188 $state = "OK";
190 $answer = "Appletalk PING $state - Packet loss = $loss%, RTA = $avg
191 ms\n";
193 else {
194 $state = "UNKNOWN";
195 $answer = "UNKNOWN - $line";
197 print $answer;
198 exit $ERRORS{$state};
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