4
0

check_wave.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 = "check_wave";
  14. sub print_help ();
  15. sub print_usage ();
  16. $ENV{'PATH'}='@TRUSTED_PATH@';
  17. $ENV{'BASH_ENV'}='';
  18. $ENV{'ENV'}='';
  19. Getopt::Long::Configure('bundling');
  20. GetOptions
  21. ("V" => \$opt_V, "version" => \$opt_V,
  22. "h" => \$opt_h, "help" => \$opt_h,
  23. "v" => \$verbose, "verbose" => \$verbose,
  24. "w=s" => \$opt_w, "warning=s" => \$opt_w,
  25. "c=s" => \$opt_c, "critical=s" => \$opt_c,
  26. "H=s" => \$opt_H, "hostname=s" => \$opt_H);
  27. if ($opt_V) {
  28. print_revision($PROGNAME,'@NP_VERSION@'); #'
  29. exit $ERRORS{'OK'};
  30. }
  31. if ($opt_h) {
  32. print_help();
  33. exit $ERRORS{'OK'};
  34. }
  35. $opt_H = shift unless ($opt_H);
  36. print_usage() unless ($opt_H);
  37. 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]+)*)$/);
  38. print_usage() unless ($host);
  39. ($opt_c) || ($opt_c = shift) || ($opt_c = 120);
  40. my $critical = $1 if ($opt_c =~ /([0-9]+)/);
  41. ($opt_w) || ($opt_w = shift) || ($opt_w = 60);
  42. my $warning = $1 if ($opt_w =~ /([0-9]+)/);
  43. $low1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
  44. @test = split(/ /,$low1);
  45. $low1 = $test[2];
  46. $med1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
  47. @test = split(/ /,$med1);
  48. $med1 = $test[2];
  49. $high1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
  50. @test = split(/ /,$high1);
  51. $high1 = $test[2];
  52. sleep(2);
  53. $snr = `snmpget $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`;
  54. @test = split(/ /,$snr);
  55. $snr = $test[2];
  56. $snr = int($snr*25);
  57. $low2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
  58. @test = split(/ /,$low2);
  59. $low2 = $test[2];
  60. $med2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
  61. @test = split(/ /,$med2);
  62. $med2 = $test[2];
  63. $high2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
  64. @test = split(/ /,$high2);
  65. $high2 = $test[2];
  66. $low = $low2 - $low1;
  67. $med = $med2 - $med1;
  68. $high = $high2 - $high1;
  69. $tot = $low + $med + $high;
  70. if ($tot==0) {
  71. $ss = 0;
  72. } else {
  73. $lowavg = $low / $tot;
  74. $medavg = $med / $tot;
  75. $highavg = $high / $tot;
  76. $ss = ($medavg*50) + ($highavg*100);
  77. }
  78. printf("Signal Strength at: %3.0f%, SNR at $snr%",$ss);
  79. if ($ss<$critical) {
  80. exit(2);
  81. } elsif ($ss<$warning) {
  82. exit(1);
  83. } else {
  84. exit(0);
  85. }
  86. sub print_usage () {
  87. print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
  88. }
  89. sub print_help () {
  90. print_revision($PROGNAME,'@NP_VERSION@');
  91. print "Copyright (c) 2000 Jeffery Blank/Karl DeBisschop\n";
  92. print "\n";
  93. print_usage();
  94. print "\n";
  95. print "<warn> = Signal strength at which a warning message will be generated.\n";
  96. print "<crit> = Signal strength at which a critical message will be generated.\n\n";
  97. support();
  98. }