This article describe howto get a 1-wire humidity probe to work with Nagios or op5 Monitor.
In an earlier article I have described a 1-wire temperature plugin.
Pre requriments
To get it working you need:
- 1-wire humidity probe i.e. this, it is based on DS2438 & HIH-4000
- A working owfs installation, instructions can be found here
- Nagios or op5 Monitor
check_1-wirehumid
The plugin is written in perl and version 1.0 can be downloaded here
#!/usr/bin/perl -w
#
# Check humidity of 1Wire device
# Requires use of Fuse and owfs
#
#
# By Peter Andersson
# peter@it-slav.net
# http://www.it-slav.net/blogs/?p=802
# Licence GPLv2
# Version 1.0
use strict;
use Getopt::Std;
use OW;
my $owserver = "127.0.0.1:3001";
my(%ERRORS) = ( OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3 );
my $humidity;
my $status=$ERRORS{OK};;
my $message;
my $debug_flag=0;
our($opt_c, $opt_w, $opt_W, $opt_C, $opt_h, $opt_o, $opt_i);
getopts("w:W:c:C:ho:i:");
sub printhelp () {
print "Usage: check_1-wirehumid [-h] -c lowhumidcritical -w lowhumidwarning -W highhumidwarning -C highhumidcritical -i id [-o owserver:port]\n";
print "-h Help, this text\n-c num Critical threshold for low humidity\n-w num Warning threshold for low humidity\n";
print "-W num Warning threshold for high humidity\n-C num Critical threshold for high humidity\n";
print "-o <name|ip>:port, Servername of 1-wire server and portnumber the owserver use, default 127.0.0.1:3001\n";
print "-i 1-wire ID, i.e. 10.DEF05F01080015\n";
print "\n\t\tby Peter Andersson\n\t\tpeter\@it-slav.net\n\t\thttp://www.it-slav.net/blogs/?p=802\n";
exit $status;
}
#sanity check
if (!$opt_c||!$opt_w||!$opt_W||!$opt_C||$opt_h) {
$status= $ERRORS{UNKNOWN};
&printhelp;
} elsif ($opt_c > $opt_w) {
print "Critical low threshold must be higher or equal to warning low threshold\n";
$status= $ERRORS{UNKNOWN};
&printhelp;
} elsif ($opt_w > $opt_W || $opt_c > $opt_C) {
print "Lower tresholds must be lower then higher thresholds\n";
$status= $ERRORS{UNKNOWN};
&printhelp;
} elsif ($opt_C < $opt_W) {
print "Higher critical threshold must be higher or equal to higher warning threshold\n";
$status= $ERRORS{UNKNOWN};
&printhelp;
}
if ($opt_o) {
$owserver = $opt_o;
}
unless(OW::init($owserver)) {
$status = $ERRORS{CRIT};
$message = "OWServer not running at $owserver\n";
exit $status;
}
$humidity = OW::get("$opt_i/humidity");
$humidity =~ s/^\s*(.*?)\s*$/$1/; #remove whitespaces
unless (($humidity =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) || ($humidity =~ /^[+-]?\d+$/)) #check that it is an integer or decimal returned
{
$message="Did not got an integer or a decimal from humidity probe";
$status=$ERRORS{CRITICAL};
}
$humidity = sprintf("%.0f", $humidity);
if ($debug_flag) {
print "opt_c:$opt_c opt_w:$opt_w opt_W:$opt_W opt_C:$opt_C opt_h:$opt_h owserver:$owserver opt_i:$opt_i Humidity:$humidity\n";
}
if ($humidity <= $opt_c) {
$status=$ERRORS{CRITICAL};
$message="CRITICAL";
} elsif ($humidity > $opt_c && $humidity <= $opt_w) {
$status=$ERRORS{WARNING};
$message="WARNING";
} elsif ($humidity > $opt_w && $humidity < $opt_W) {
$status=$ERRORS{OK};
$message="OK";
} elsif ($humidity >= $opt_W && $humidity < $opt_C) {
$status=$ERRORS{WARNING};
$message="WARNING";
} elsif ($humidity >= $opt_C) {
$status=$ERRORS{CRITICAL};
$message="CRITICAL";
} else { #This should never happend
$status=$ERRORS{UNKNOWN};
$message="UNKNOW";
}
print "$message: $humidity \%\|humidity=$humidity\%\;$opt_c;$opt_w;$opt_W;$opt_C\n";
exit $status;
Test the plugin by run:
[root@op5 custom]# ./check_1-wirehumid -c 10 -w 20 -W 90 -C 95 -i 26.D7EABC000000 OK: 31 %|humidity=31%;10;20;90;95
So I have 31 % humidity.
Nagios config files
In checkcommands.cfg, define check_1-wirehumid
# command 'check_1-wirehumid'
define command{
command_name check_1-wirehumid
command_line $USER1$/custom/check_1-wirehumid -c $ARG1$ -w $ARG2$ -W$ARG3$ -C$ARG4$ -i $ARG5$ -o $ARG6$
}
In serviced.cfg, define the check. I have a service group called Environemnt where all my Environments probes are.
# service 'Washroom Humidity'
define service{
use default-service
host_name monitor
service_description Washroom Humidity
check_command check_1-wirehumid!10!20!80!90!26.D7EABC000000!127.0.0.1:3001
servicegroups Environment
contact_groups it-slav_msn,it-slav_mail,call_it-slav
}
Screenshots
This is a screen shoot from op5 Monitor showing my Servicegroup Environment.
If you have op5 Monitor or PNP for Nagios, graphs like this will automatically be created. Note that I had a shower 6.20 and the humidity went from approx 25% to 95% in a couple of minutes.
One Response to “Nagios or op5 Monitor plugin for 1-wire humidity measurement”
Leave a Reply
You must be logged in to post a comment.






March 4th, 2009 at 8:38 am
[…] Go here to see the original: Nagios or op5 Monitor plugin for 1-wire humidity measurement | An … […]