File check_webio_temp.pl of Package monitoring-plugins-webio_temp
#!/usr/bin/perl -w
#
#
# Nagios plugin to check Web-IO Thermometer
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
use strict;
use lib "/usr/lib/nagios/plugins";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME);
use Carp;
use Data::Dumper;
use English qw( -no_match_vars );
use Getopt::Long;
use Net::SNMP;
use Pod::Usage;
#######################################################################
## Init Area
#######################################################################
$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin:';
$ENV{'BASH_ENV'} = '';
$ENV{'ENV'} = '';
our %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
our $conf={
VERSION => '0.1.0',
PROGNAME => 'check_webio-temp',
debug => 0,
community => 'public',
host => '127.0.0.1', #'localhost',
sensorno => 1,
warning => '15:26',
critical => '10:30',
oid => '.1.3.6.1.4.1.5040.1.2.1.1.4.1.1',
ret_str => 'UNKOWN',
exitcode => $ERRORS{'UNKNOWN'},
timeout => 15,
};
my $print_help=0;
my $session;
#######################################################################
## Function Area
#######################################################################
sub cleanup_and_exit($$){
my ($session,$conf)=@_;
if (defined($session) && $session ne ''){
$session->close;
}
print $conf->{'ret_str'}." degrees|temp=".$conf->{'ret_str'}."\n";
exit $conf->{'exitcode'};
}
sub split_values($){
my ($value)=@_;
if ( $value =~ /:/){
my ($min,$max)=split(':',$value,2);
return ($min,$max);
}
else {
return($value,$value);
}
}
#######################################################################
## Main Area
#######################################################################
Getopt::Long::Configure('bundling');
GetOptions( "h|help" => \$print_help,
"d|debug" => \$conf->{'debug'},
"H|hostname=s" => \$conf->{'host'},
"C|community=s" => \$conf->{'community'},
"s|sensornumber=i" => \$conf->{'sensorno'},
"w|warning=s" => \$conf->{'warning'},
"c|critical=s" => \$conf->{'critical'},
) or pod2usage(2);
pod2usage( -exitstatus => 0,
-verbose => 1, # 2 to print full pod
) if $print_help;
my $error;
# some checks
my ($warning_min,$warning_max)=split_values($conf->{'warning'});
my ($critical_min,$critical_max)=split_values($conf->{'critical'});
if ($conf->{'debug'}){
print STDERR "Config:\n".Data::Dumper->Dump([$conf])."\n";
}
if ($warning_min < $critical_min){
print "ERROR: critical value ($critical_min) must be lower than warning ($warning_min)\n";
$conf->{'ret_str'}="0";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
if ($warning_max > $critical_max){
print "ERROR: value of warning ($warning_max) must be lower than critical ($critical_max)\n";
$conf->{'ret_str'}="0";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
($session, $error)=Net::SNMP->session(
-hostname => $conf->{'host'},
-community => $conf->{'community'},
);
if ("$error" ne ""){
print "ERROR opening SNMP session to $conf->{'host'} failed: $error\n";
$conf->{'ret_str'}="0";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
my $resultref=$session->get_request( -varbindlist => ["$conf->{'oid'}.$conf->{'sensorno'}"] );
my $result;
if ($resultref && $resultref ne ''){
$result=$resultref->{"$conf->{'oid'}.$conf->{'sensorno'}"}/10;
}
else {
$conf->{'ret_str'}="0";
print "ERROR: no result\n";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
if ($conf->{'debug'}){
print STDERR "Session: \n".Data::Dumper->Dump([$session])."\n";
print STDERR "Result: \n".Data::Dumper->Dump([$result])."\n";
}
# compare the result
if ($result < $critical_min){
$conf->{'ret_str'}="$result";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
if ($result < $warning_min){
$conf->{'ret_str'}="$result";
$conf->{'exitcode'}=$ERRORS{'WARNING'};
cleanup_and_exit($session,$conf);
}
if ($result > $critical_max){
$conf->{'ret_str'}="$result";
$conf->{'exitcode'}=$ERRORS{'CRITICAL'};
cleanup_and_exit($session,$conf);
}
if ($result > $warning_max){
$conf->{'ret_str'}="$result";
$conf->{'exitcode'}=$ERRORS{'WARNING'};
cleanup_and_exit($session,$conf);
}
$conf->{'ret_str'}="$result";
$conf->{'exitcode'}=$ERRORS{'OK'};
cleanup_and_exit($session,$conf);
__END__
=head1 check_webio_temp
Check values of a WuT Web-Thermometer.
=head1 SYNOPSIS
./check_webio_temp -H <HOSTNAME> -C <snmp_community> -s <sensor> -w <min_warn>:<max_warn> -c <min_crit>:<max_crit> [-d]
Options:
-H <HOSTNAME> | --hostname <HOSTNAME>
-C <community> | --community <community>
-s <sensor> | --sensornumber <sensor>
-w <min:max> | --warning <min:max>
-c <min:max> | --critical <min:max>
-h | --help
-d | --debug
=head1 OPTIONS
=over 4
=item B<--hostname> F<hostname>
The name of one host. The check will check if there is a problem reported for this single host
and return with "OK" if no problem is found - or "CRITICAL" if a problem is found.
=item B<--community> F<community>
The SNMP community with read access to the device. Only SNMP version 1 or 2 is supported.
Defaults to "public" if not given.
=item B<--sensornumber> F<number>
The number of the sensor to query. Should be something from 1 to 8.
=item B<--warning> F<min:max>
Temperature levels for warning. Set minimal and maximal temperatures separated by a ':'.
=item B<--critical> F<min:max>
Temperature levels for critical: Set minimal and maximal temperatures separated by a ':'.
Note: critical values should be below and above the warning levels. Otherwise the script
will exit with an error message.
=back
=head1 DESCRIPTION
This plugin allows to check a Web-IO 2x/8x Thermometer via SNMP, including
defined warning and critical temperature levels, and integrate them into
a monitoring solution like Nagios, Icinga or Naemon.
Tested with WuT devices 57603 and 57604 - others might need adaptions regarding
the SNMP OID values inside the script.
=cut