Code

More edge testcases. Allow anything if ends with a . as long as correct
[nagiosplug.git] / plugins-scripts / check_wave.pl
1 #!/usr/bin/perl -wT
2 #
3 # $Id$
6 use strict;
7 use lib utils.pm;
8 use utils qw($TIMEOUT %ERRORS &print_revision &support);
9 use vars qw($PROGNAME);
10 use Getopt::Long;
11 use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H);
12 my (@test, $low1, $med1, $high1, $snr, $low2, $med2, $high2);
13 my ($low, $med, $high, $lowavg, $medavg, $highavg, $tot, $ss);
15 $PROGNAME = "check_wave";
16 sub print_help ();
17 sub print_usage ();
19 $ENV{'PATH'}='';
20 $ENV{'BASH_ENV'}='';
21 $ENV{'ENV'}='';
23 Getopt::Long::Configure('bundling');
24 GetOptions
25         ("V"   => \$opt_V, "version"    => \$opt_V,
26          "h"   => \$opt_h, "help"       => \$opt_h,
27          "v" => \$verbose, "verbose"  => \$verbose,
28          "w=s" => \$opt_w, "warning=s"  => \$opt_w,
29          "c=s" => \$opt_c, "critical=s" => \$opt_c,
30          "H=s" => \$opt_H, "hostname=s" => \$opt_H);
32 if ($opt_V) {
33         print_revision($PROGNAME,'$Revision$'); #'
34         exit $ERRORS{'OK'};
35 }
37 if ($opt_h) {
38         print_help();
39         exit $ERRORS{'OK'};
40 }
42 $opt_H = shift unless ($opt_H);
43 print_usage() unless ($opt_H);
44 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]+)*)$/);
45 print_usage() unless ($host);
47 ($opt_c) || ($opt_c = shift) || ($opt_c = 120);
48 my $critical = $1 if ($opt_c =~ /([0-9]+)/);
50 ($opt_w) || ($opt_w = shift) || ($opt_w = 60);
51 my $warning = $1 if ($opt_w =~ /([0-9]+)/);
53 $low1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
54 @test = split(/ /,$low1);
55 $low1 = $test[2];
57 $med1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
58 @test = split(/ /,$med1);
59 $med1 = $test[2];
61 $high1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
62 @test = split(/ /,$high1);
63 $high1 = $test[2];
65 sleep(2);
67 $snr = `snmpget $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`;
68 @test = split(/ /,$snr);
69 $snr = $test[2];
70 $snr = int($snr*25);
72 $low2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
73 @test = split(/ /,$low2);
74 $low2 = $test[2];
76 $med2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
77 @test = split(/ /,$med2);
78 $med2 = $test[2];
80 $high2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
81 @test = split(/ /,$high2);
82 $high2 = $test[2];
84 $low = $low2 - $low1;
85 $med = $med2 - $med1;
86 $high = $high2 - $high1;
88 $tot = $low + $med + $high;
90 if ($tot==0) {
91         $ss = 0;
92 } else {
93         $lowavg = $low / $tot;
94         $medavg = $med / $tot;
95         $highavg = $high / $tot;
96         $ss = ($medavg*50) + ($highavg*100);
97 }
99 printf("Signal Strength at: %3.0f%,  SNR at $snr%",$ss);
101 if ($ss<$critical) {
102         exit(2);
103 } elsif ($ss<$warning) {
104         exit(1);
105 } else {
106         exit(0);
110 sub print_usage () {
111         print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
114 sub print_help () {
115         print_revision($PROGNAME,'$Revision$');
116         print "Copyright (c) 2000 Jeffery Blank/Karl DeBisschop\n";
117         print "\n";
118         print_usage();
119         print "\n";
120         print "<warn> = Signal strength at which a warning message will be generated.\n";
121         print "<crit> = Signal strength at which a critical message will be generated.\n\n";
122         support();