check_appletalk.pl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: 1771 $
  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. use strict;
  24. use lib "/usr/local/nagios/libexec";
  25. use utils qw($TIMEOUT %ERRORS &print_revision &support);
  26. use vars qw($PROGNAME);
  27. $PROGNAME = "check_atalk";
  28. my (
  29. $verbose, $host, $warning_avg, $warning_loss,
  30. $critical_avg, $critical_loss, $count, $cmd,
  31. $avg, $loss, $line
  32. );
  33. my ( $opt_c, $opt_w, $opt_H, $opt_p );
  34. $opt_c = $opt_w = $opt_p = $opt_H = '';
  35. sub print_help ();
  36. sub print_usage ();
  37. sub help ();
  38. sub version ();
  39. # Just in case of problems, let's not hang NetSaint
  40. $SIG{'ALRM'} = sub {
  41. print "Plugin Timeout\n";
  42. exit 2;
  43. };
  44. alarm($TIMEOUT);
  45. delete @ENV{ 'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
  46. use Getopt::Long;
  47. Getopt::Long::Configure( 'bundling', 'no_ignore_case' );
  48. GetOptions(
  49. "V|version" => \&version,
  50. "h|help" => \&help,
  51. "p|packets=i" => \$opt_p,
  52. "c|critical=s" => \$opt_c,
  53. "w|warning=s" => \$opt_w,
  54. "H|hostname=s" => \$opt_H
  55. );
  56. # appletalk hostname ot address
  57. $opt_H = shift unless ($opt_H);
  58. unless ($opt_H) { print_usage (); exit $ERRORS{'UNKNOWN'}; }
  59. if ( $opt_H && $opt_H =~ m/^([-a-zA-Z\.\:0-9]+)$/ ) {
  60. $host = $1;
  61. }
  62. else {
  63. print "$opt_H is not a valid host name\n";
  64. exit $ERRORS{'UNKNOWN'};
  65. }
  66. # number of packets
  67. $opt_p = 5 unless $opt_p;
  68. if ( $opt_p && $opt_p =~ m/^([1-9]+[0-9]*)$/ ) {
  69. $count = $1;
  70. }
  71. else {
  72. print "$opt_p is not a valid packet number\n";
  73. exit $ERRORS{'UNKNOWN'};
  74. }
  75. if ( $opt_w && $opt_w =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
  76. $warning_avg = $1;
  77. $warning_loss = $2;
  78. }
  79. else {
  80. print "$opt_w is not a valid threshold\n";
  81. exit $ERRORS{'UNKNOWN'};
  82. }
  83. if ( $opt_c && $opt_c =~ m/^([1-9]+[0-9]*),([1-9][0-9]*)%$/ ) {
  84. $critical_avg = $1;
  85. $critical_loss = $2;
  86. }
  87. else {
  88. print "$opt_c is not a valid threshold\n";
  89. exit $ERRORS{'UNKNOWN'};
  90. }
  91. $cmd = "/usr/bin/aecho -c $count $host 2>&1 |";
  92. print "$cmd\n" if ($verbose);
  93. open CMD, $cmd;
  94. while (<CMD>) {
  95. print $_ if ($verbose);
  96. $line = $_;
  97. # 5 packets sent, 5 packets received, 0% packet loss
  98. # round-trip (ms) min/avg/max = 0/0/0
  99. if (/received, ([0-9]+)% packet loss/) {
  100. $loss = $1;
  101. }
  102. if (/min\/avg\/max = [0-9]+\/([0-9]+)\/[0-9]+/) {
  103. $avg = $1;
  104. }
  105. }
  106. sub print_help() {
  107. print_revision( $PROGNAME, '$Revision: 1771 $ ' );
  108. print "Copyright (c) 2002 Stefan Beck\n";
  109. print "\n";
  110. print "Check if an atalkhost responds to an atalk echo using\n";
  111. print " aecho -c <packets> <atalkhost>\n";
  112. print "\n";
  113. print_usage ();
  114. print "\n";
  115. print "-H, --hostname=HOST\n";
  116. print " host to ping\n";
  117. print "-w, --warning=THRESHOLD\n";
  118. print " warning threshold pair\n";
  119. print "-c, --critical=THRESHOLD\n";
  120. print " critical threshold pair\n";
  121. print "-p, --packets=INTEGER\n";
  122. print " number of ICMP ECHO packets to send (Default: 5)\n";
  123. print "\n";
  124. print
  125. "THRESHOLD is <rta>,<pl>% where <rta> is the round trip average
  126. travel\n";
  127. print
  128. "time (ms) which triggers a WARNING or CRITICAL state, and <pl>
  129. is the\n";
  130. print "percentage of packet loss to trigger an alarm state.\n";
  131. print "\n";
  132. support();
  133. }
  134. sub print_usage () {
  135. print "$PROGNAME -H atalkhost -w <wrta>,<wpl>% -c <crta>,<cpl>%\n";
  136. print " [-p packets] [-t timeout] [-L]\n";
  137. print "$PROGNAME [-h | --help]\n";
  138. print "$PROGNAME [-V | --version]\n";
  139. }
  140. sub version () {
  141. print_revision( $PROGNAME, '$Revision: 1771 $ ' );
  142. exit $ERRORS{'OK'};
  143. }
  144. sub help () {
  145. print_help ();
  146. exit $ERRORS{'OK'};
  147. }
  148. my $state = "OK";
  149. my $answer = undef;
  150. if ( defined $loss && defined $avg ) {
  151. if ( $loss >= $critical_loss ) {
  152. $state = "CRITICAL";
  153. }
  154. elsif ( $avg >= $critical_avg ) {
  155. $state = "CRITICAL";
  156. }
  157. elsif ( $loss >= $warning_loss ) {
  158. $state = "WARNING";
  159. }
  160. elsif ( $avg >= $warning_avg ) {
  161. $state = "WARNING";
  162. }
  163. else {
  164. $state = "OK";
  165. }
  166. $answer = "Appletalk PING $state - Packet loss = $loss%, RTA = $avg
  167. ms\n";
  168. }
  169. else {
  170. $state = "UNKNOWN";
  171. $answer = "UNKNOWN - $line";
  172. }
  173. print $answer;
  174. exit $ERRORS{$state};
  175. -------------------------------------------------------
  176. This sf.net email is sponsored by:ThinkGeek
  177. Welcome to geek heaven.
  178. http://thinkgeek.com/sf
  179. _______________________________________________
  180. Nagios-devel mailing list
  181. Nagios-devel@lists.sourceforge.net
  182. https://lists.sourceforge.net/lists/listinfo/nagios-devel