check_wave.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!@PERL@ -w
  2. #
  3. use strict;
  4. use FindBin;
  5. use lib "$FindBin::Bin";
  6. use lib '@libexecdir@';
  7. use utils qw($TIMEOUT %ERRORS &print_revision &support);
  8. use vars qw($PROGNAME);
  9. use Getopt::Long;
  10. use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H);
  11. my (@test, $low1, $med1, $high1, $snr, $low2, $med2, $high2);
  12. my ($low, $med, $high, $lowavg, $medavg, $highavg, $tot, $ss);
  13. $PROGNAME = $0;
  14. chomp $PROGNAME;
  15. sub print_help ();
  16. sub print_usage ();
  17. $ENV{'PATH'}='@TRUSTED_PATH@';
  18. $ENV{'BASH_ENV'}='';
  19. $ENV{'ENV'}='';
  20. Getopt::Long::Configure('bundling');
  21. GetOptions
  22. ("V" => \$opt_V, "version" => \$opt_V,
  23. "h" => \$opt_h, "help" => \$opt_h,
  24. "v" => \$verbose, "verbose" => \$verbose,
  25. "w=s" => \$opt_w, "warning=s" => \$opt_w,
  26. "c=s" => \$opt_c, "critical=s" => \$opt_c,
  27. "H=s" => \$opt_H, "hostname=s" => \$opt_H);
  28. if ($opt_V) {
  29. print_revision($PROGNAME,'@NP_VERSION@'); #'
  30. exit $ERRORS{'OK'};
  31. }
  32. if ($opt_h) {
  33. print_help();
  34. exit $ERRORS{'OK'};
  35. }
  36. $opt_H = shift unless ($opt_H);
  37. unless ($opt_H) { print_usage(); exit -1; }
  38. my $host = $1 if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0]+(\.[a-zA-Z][-a-zA-Z0]+)*)$/);
  39. unless ($host) { print_usage(); exit -1; }
  40. ($opt_c) || ($opt_c = shift) || ($opt_c = 120);
  41. my $critical = $1 if ($opt_c =~ /([0-9]+)/);
  42. ($opt_w) || ($opt_w = shift) || ($opt_w = 60);
  43. my $warning = $1 if ($opt_w =~ /([0-9]+)/);
  44. $low1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1 2>/dev/null`;
  45. unless ($low1) {
  46. print "UNKNOWN - Could not find the 'snmpget' command Please install\n";
  47. print "the snmp commands (usually net-snmp) before using $PROGNAME\n";
  48. exit $ERRORS{'UNKNOWN'};
  49. }
  50. @test = split(/ /,$low1);
  51. $low1 = $test[2];
  52. $med1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
  53. @test = split(/ /,$med1);
  54. $med1 = $test[2];
  55. $high1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
  56. @test = split(/ /,$high1);
  57. $high1 = $test[2];
  58. sleep(2);
  59. $snr = `snmpget $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`;
  60. @test = split(/ /,$snr);
  61. $snr = $test[2];
  62. $snr = int($snr*25);
  63. $low2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
  64. @test = split(/ /,$low2);
  65. $low2 = $test[2];
  66. $med2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
  67. @test = split(/ /,$med2);
  68. $med2 = $test[2];
  69. $high2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
  70. @test = split(/ /,$high2);
  71. $high2 = $test[2];
  72. $low = $low2 - $low1;
  73. $med = $med2 - $med1;
  74. $high = $high2 - $high1;
  75. $tot = $low + $med + $high;
  76. if ($tot==0) {
  77. $ss = 0;
  78. } else {
  79. $lowavg = $low / $tot;
  80. $medavg = $med / $tot;
  81. $highavg = $high / $tot;
  82. $ss = ($medavg*50) + ($highavg*100);
  83. }
  84. printf("Signal Strength at: %3.0f%, SNR at $snr%\n",$ss);
  85. if ($ss<$critical) {
  86. exit(2);
  87. } elsif ($ss<$warning) {
  88. exit(1);
  89. } else {
  90. exit(0);
  91. }
  92. sub print_usage () {
  93. print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
  94. }
  95. sub print_help () {
  96. print_revision($PROGNAME,'@NP_VERSION@');
  97. print "Copyright (c) 2000 Jeffery Blank/Karl DeBisschop\n";
  98. print "\n";
  99. print_usage();
  100. print "\n";
  101. print "<warn> = Signal strength at which a warning message will be generated.\n";
  102. print "<crit> = Signal strength at which a critical message will be generated.\n\n";
  103. support();
  104. }