[Nagiosplug-devel] Check Plugin for WuT 57101 Web Thermometer

Jernejcic Alexander ajernejcic at leasfinanz.at
Mon Jul 28 03:13:14 CEST 2003


hi,
if somebody finds that usefull:
a little check for a Wiesemann & Theis 57101 web thermometer. it
tries to get the temperature and alarms on the given options.
should do its job with other WuT web thermometers if the readout
command string is adjusted. (eg 'GET /Single1' for 57601)

alexander

-- cut ---
#!/usr/bin/perl -w
# check_wt57101 - check the temperature from W&T 57101 WQEB Thermometer
#

# License Information:
# 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, or
# (at your option) any later version.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
############################################################################

use POSIX;
use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_H $opt_p $opt_w $opt_W $opt_c $opt_C $PROGNAME $host $port $loww $lowc $highw $highc $status $DEFAULT_LOW_WARN $DEFAULT_LOW_CRIT $DEFAULT_HIGH_WARN $DEFAULT_HIGH_CRIT $DEFAULT_PORT $opt_t);
use lib  "/usr/local/nagios/libexec" ;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use IO::Socket;

sub print_help ();
sub print_usage ();
sub process_arguments ();

# default temoeratures
# too cold
$DEFAULT_LOW_WARN=15.0;
$DEFAULT_LOW_CRIT=10.0;
# too hot
$DEFAULT_HIGH_WARN=28.0;
$DEFAULT_HIGH_CRIT=35.0;

# default port
$DEFAULT_PORT="80";

# ProgName
$PROGNAME="check_wt57101";

# littel helper
my $EOL = "\015\012";
Getopt::Long::Configure('bundling');
$status = process_arguments();
if ($status){
        print "ERROR: processing arguments\n";
        exit $ERRORS{"UNKNOWN"};
}

# Timeout
$SIG{'ALRM'} = sub {
        print ("ERROR: timed out witing for thermometer $host \n");
        exit $ERRORS{"WARNING"};
};
alarm($opt_t);

# here we get the temperature
my $remote;

if (! ($remote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $host, PeerPort => $port))) {
    print "Error: cannot connect to $port at $host !\n";
    exit $ERRORS{"UNKNOWN"};
}


$remote->autoflush(1);
# CHANGE READOUT COMAND HERE!
print $remote "GET /Single B".$EOL;
my ($byte,$answer);
ANSWER: while (sysread($remote, $byte, 1) == 1) { 
  $answer .= $byte;
  last ANSWER if ($byte eq 'C');
}
close $remote;


my ($temperatur,$junk)= split('°',$answer,2);
my $msg;
if ($temperatur <= $lowc || $temperatur >= $highc) {
  $status = $ERRORS{'CRITICAL'};
  $msg = "CRITICAL: ";
} elsif ($temperatur <= $loww || $temperatur >= $highw) {
  $status = $ERRORS{'WARNING'};
  $msg = "WARNING: ";
} else {
  $status = $ERRORS{'OK'};
  $msg = "OK: ";
}

print "$msg Temperature is $answer";
exit $status;

# Subs

sub process_arguments(){
        GetOptions
                ("V"   => \$opt_V, "version"    => \$opt_V,
                 "h"   => \$opt_h, "help"               => \$opt_h,
                 "H=s"   => \$opt_H, "hostname"         => \$opt_H,
                 "p=s"   => \$opt_p, "port"             => \$opt_p,
                 "w=s" => \$opt_w, "lowwarning=f"  => \$opt_w, # warning if below this
                 "W=s" => \$opt_W, "highwarning=f"  => \$opt_W, # warning if above this
                 "c=s" => \$opt_c, "lowcritical=f" => \$opt_c,  # critical if below this
                 "C=s" => \$opt_C, "highcritical=f" => \$opt_c, # critical if above this
                 "t=i" => \$opt_t, "timeout=i"  => \$opt_t 
                 );

        if ($opt_V) {
                print_revision($PROGNAME,'$Revision: 0.1 $ ');
                exit $ERRORS{'OK'};
        }

        if ($opt_h) {
                print_help();
                exit $ERRORS{'OK'};
        }

        unless (defined $opt_H ) {
                print_usage();
                exit $ERRORS{'UNKNOWN'};
        }

        unless (defined $opt_t) {
                $opt_t = $utils::TIMEOUT ;      # default timeout
        }
  
  $host = $opt_H;
  $port = $opt_p || $DEFAULT_PORT;
  $loww = $opt_w || $DEFAULT_LOW_WARN;
  $lowc = $opt_c || $DEFAULT_LOW_CRIT;
  $highw = $opt_W || $DEFAULT_HIGH_WARN;
  $highc = $opt_C || $DEFAULT_HIGH_CRIT;
  if ($loww !~ /\d+/) {
    print "Waring: invalid port!\n";
  }
  if (($lowc !~ /\d+/)  ||
      ($loww !~ /\d+/)  ||
      ($highw !~ /\d+/) ||
      ($highc !~ /\d+/) ) {
    print "Waring: invalid temperature!\n";
    exit $ERRORS{'UNKNOWN'};
  }
  if ($highw >= $highc) {
    print "Waring: high temp warning can not be abovbe  high temp critical!\n";
    exit $ERRORS{'UNKNOWN'};
  }
  if ($loww <= $lowc) {
    print "Waring: low temp warning can not be below low temp critical!\n";
    exit $ERRORS{'UNKNOWN'};
  }
  if ($loww >= $highw) {
    print "Warning: low temp warnung must be below high temp warning!\n";   
    exit $ERRORS{'UNKNOWN'};
  }
        return $ERRORS{'OK'};
}

sub print_usage () {
        print "Usage: $PROGNAME -H <host> [-p <port>][-w <lowwarningtemp>] [-c <lowcriticaltemp>] [-W <highwarningtemp>] [-C <highcriticaltemp>] [-t <timeout>]\n";
}

sub print_help () {
        print_revision($PROGNAME,'$Revision: 0.1 $');
        print "\nauthor: Alexander Jernejcic\n";
  print "significant parts of code are \"copy and paste\" \n";
  print "from check_mailq by Subhendu Ghosh !\n";
        print "\n";
        print_usage();
        print "\n";
        print "   Checks the tempereature from a W\&T 57101 WEB Thermometer (http://www.wut.de)\n";
        print "-H (--hostadress) = IP-Address of the WebThermometer\n";
        print "-p (--port) = port, the WebThermometer ist listening on (default=$DEFAULT_PORT)\n";
        print "-w (--lowwarning) = warning if below this Temperature (default=$DEFAULT_LOW_WARN °C)\n";
        print "-W (--highwarning) = warning if above Temperature (default=$DEFAULT_HIGH_WARN °C)\n";
        print "-c (--lowcritical) = critical if below Temperature  (default=$DEFAULT_LOW_CRIT °C)\n";
        print "-C (--highcritical) = critical if above Temperatur (default=$DEFAULT_HIGH_CRIT °C)\n";
  print "-t (--timeout)   = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
        print "-h (--help)\n";
        print "-V (--version)\n";
        print "\n\n";
        support();
}





More information about the Devel mailing list