Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / plugins-scripts / check_wave.pl
1 #!/usr/bin/perl -wT
2 #
5 use strict;
6 use lib utils.pm;
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);
14 $PROGNAME = "check_wave";
15 sub print_help ();
16 sub print_usage ();
18 $ENV{'PATH'}='';
19 $ENV{'BASH_ENV'}='';
20 $ENV{'ENV'}='';
22 Getopt::Long::Configure('bundling');
23 GetOptions
24         ("V"   => \$opt_V, "version"    => \$opt_V,
25          "h"   => \$opt_h, "help"       => \$opt_h,
26          "v" => \$verbose, "verbose"  => \$verbose,
27          "w=s" => \$opt_w, "warning=s"  => \$opt_w,
28          "c=s" => \$opt_c, "critical=s" => \$opt_c,
29          "H=s" => \$opt_H, "hostname=s" => \$opt_H);
31 if ($opt_V) {
32         print_revision($PROGNAME,'@NP_VERSION@'); #'
33         exit $ERRORS{'OK'};
34 }
36 if ($opt_h) {
37         print_help();
38         exit $ERRORS{'OK'};
39 }
41 $opt_H = shift unless ($opt_H);
42 print_usage() unless ($opt_H);
43 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]+)*)$/);
44 print_usage() unless ($host);
46 ($opt_c) || ($opt_c = shift) || ($opt_c = 120);
47 my $critical = $1 if ($opt_c =~ /([0-9]+)/);
49 ($opt_w) || ($opt_w = shift) || ($opt_w = 60);
50 my $warning = $1 if ($opt_w =~ /([0-9]+)/);
52 $low1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
53 @test = split(/ /,$low1);
54 $low1 = $test[2];
56 $med1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
57 @test = split(/ /,$med1);
58 $med1 = $test[2];
60 $high1 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
61 @test = split(/ /,$high1);
62 $high1 = $test[2];
64 sleep(2);
66 $snr = `snmpget $host public .1.3.6.1.4.1.762.2.5.2.1.17.1`;
67 @test = split(/ /,$snr);
68 $snr = $test[2];
69 $snr = int($snr*25);
71 $low2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.8.1`;
72 @test = split(/ /,$low2);
73 $low2 = $test[2];
75 $med2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.9.1`;
76 @test = split(/ /,$med2);
77 $med2 = $test[2];
79 $high2 = `snmpget $host public .1.3.6.1.4.1.74.2.21.1.2.1.10.1`;
80 @test = split(/ /,$high2);
81 $high2 = $test[2];
83 $low = $low2 - $low1;
84 $med = $med2 - $med1;
85 $high = $high2 - $high1;
87 $tot = $low + $med + $high;
89 if ($tot==0) {
90         $ss = 0;
91 } else {
92         $lowavg = $low / $tot;
93         $medavg = $med / $tot;
94         $highavg = $high / $tot;
95         $ss = ($medavg*50) + ($highavg*100);
96 }
98 printf("Signal Strength at: %3.0f%,  SNR at $snr%",$ss);
100 if ($ss<$critical) {
101         exit(2);
102 } elsif ($ss<$warning) {
103         exit(1);
104 } else {
105         exit(0);
109 sub print_usage () {
110         print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
113 sub print_help () {
114         print_revision($PROGNAME,'@NP_VERSION@');
115         print "Copyright (c) 2000 Jeffery Blank/Karl DeBisschop\n";
116         print "\n";
117         print_usage();
118         print "\n";
119         print "<warn> = Signal strength at which a warning message will be generated.\n";
120         print "<crit> = Signal strength at which a critical message will be generated.\n\n";
121         support();