#!/usr/bin/perl -wT


require 5.004;
use POSIX;
use strict;
use lib utils.pm ;
use Plugin;
use Plugin::Parameter qw($helpparameterlist $versionparameterlist $hostnameparameter
			 $communityparameter $portparameter $warningparameter
			 $criticalparameter $timeoutparameter $verboseparameter);

use Net::SNMP;

use vars qw($opt_h $opt_w $opt_c $opt_H $opt_C $opt_p $opt_t $opt_v $xml $PROGNAME);
use utils qw(%ERRORS &usage);

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}=''; 
$ENV{'ENV'}='';

$portparameter->default(161);
$warningparameter->type("PERCENT");
$warningparameter->checker(\&Plugin::Parameter::_check_percent);
$warningparameter->description("Percentage strength below which a WARNING status will result");
$criticalparameter->type("PERCENT");
$criticalparameter->checker(\&Plugin::Parameter::_check_percent);
$criticalparameter->description("Percentage strength below which a CRITICAL status will result");

my @commandparameterlist = ( $hostnameparameter,
			     $communityparameter,
			     $portparameter,
			     $warningparameter,
			     $criticalparameter,
			     $timeoutparameter,
			     $verboseparameter );

my $plugin = new Plugin(-revision => '$Revision: 1.5 $',
			-copyright => "2000 Jeffrey Blank/Karl DeBisschop, 2004 Howard WIlkinson <howard\@cohtech.com>",
			-shortcomment => "This plugin reports the signal strength of Breezecom wireless equipment",
			-parameterlists => [ \@commandparameterlist, $helpparameterlist, $versionparameterlist ] );


$plugin->init();

my ($session, $error) = Net::SNMP->session(-hostname   => $opt_H,
					   -community  => $opt_C,
					   -timeout    => $opt_t,
					   -port       => $opt_p,
					   -version    => "snmpv1",
					   -translate  => undef);
if (!defined($session)) {
  print "$PROGNAME UNKNOWN: $error\n";
  exit $ERRORS{'UNKNOWN'};
}

my $snmpBreezeSigStrength = '1.3.6.1.4.1.710.3.2.3.1.3.0';

my $response = $session->get_request(-varbindlist => [ $snmpBreezeSigStrength ]);

if (!defined $response) {
  print "$PROGNAME UNKNOWN: ".$session->error."\n";
  exit $ERRORS{'UNKNOWN'};
}

$session->close;

my $SignalStrength = int($response->{$snmpBreezeSigStrength});

if ($SignalStrength>100){$SignalStrength=100}

my $status = (($SignalStrength < $opt_c)
	      ?'CRITICAL'
	      :(($SignalStrength < $opt_w)
		?'WARNING'
		:'OK'));

print "$PROGNAME $status: Signal Strength at: $SignalStrength%\n";

exit $ERRORS{$status};
