# HG changeset patch # User arnold # Date 1344343876 -7200 # Node ID 4a92d15de9dd3e348c34937423f04cb632ae5def import to mercurial diff -r 000000000000 -r 4a92d15de9dd .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Aug 07 14:51:16 2012 +0200 @@ -0,0 +1,8 @@ +syntax: glob +*.swp +debian/files +check_roomtemp + +syntax: regexp +(build|configure)-stamp$ +debian/nagios-plugin-roomtemp[./] diff -r 000000000000 -r 4a92d15de9dd .perltitdy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.perltitdy Tue Aug 07 14:51:16 2012 +0200 @@ -0,0 +1,2 @@ +--paren-tightness=2 +--square-bracket-tightness=2 diff -r 000000000000 -r 4a92d15de9dd Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Tue Aug 07 14:51:16 2012 +0200 @@ -0,0 +1,22 @@ +SCRIPTS = check_roomtemp +CLEANFILES = ${SCRIPTS} +DESTDIR = +prefix = /usr + +plugindir = ${prefix}/lib/nagios/plugins/ius + +.PHONY: all clean install + +all: ${SCRIPTS} + +clean: + -rm -f ${CLEANFILES} + +install: all + install -d -m 0755 ${DESTDIR}/${plugindir} + install -m 0755 $(SCRIPTS) ${DESTDIR}/${plugindir}/ + +%: %.pl + @perl -c $< + @cp -f $< $@ + @chmod +x $@ diff -r 000000000000 -r 4a92d15de9dd check_roomtemp.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_roomtemp.pl Tue Aug 07 14:51:16 2012 +0200 @@ -0,0 +1,195 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use LWP::Simple; +use File::Basename; +use Getopt::Long; +use Pod::Usage; + +delete @ENV{ grep /^LC_/ => keys %ENV }; +$ENV{LANG} = "C"; +$ENV{LC_ALL} = "C"; + +sub version($$); +sub get_temp($$); +sub report($$$); + +my %ERRORS = ( + OK => 0, + WARNING => 1, + CRITICAL => 2, + UNKNOWN => 3, + DEPENDENT => 4 +); + +my $ME = basename $0; +my $NAME = "ROOMTEMP"; +my $VERSION = "0.1"; + +my %opt = ( + warning => 35.00, + critical => 40.00, + url => 'http://thermo.local.site/status.xml', + search => '[+-]\s+([\d\.]+)' +); + +MAIN: { + Getopt::Long::Configure('bundling'); + GetOptions( + "w|warning=f" => \$opt{warning}, + "c|critical=f" => \$opt{critical}, + "u|url=s" => \$opt{url}, + "s|search=s" => \$opt{search}, + "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, + "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, + "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } + ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); + + my ($temp) = get_temp( \$opt{url}, \$opt{search} ); + report( \$temp, \$opt{warning}, \$opt{critical} ); +} + +sub get_temp($$) { + my ( $url, $search ) = @_; + my $temp; + my $content = get($$url); + if ( !$content ) { + print "$NAME UNKNOWN: can't get status informations from URL\n"; + exit $ERRORS{UNKNOWN}; + } + $content =~ /$$search/; + + if ( !$1 ) { + print "$NAME UNKNOWN: can't get temperature from search string\n"; + exit $ERRORS{UNKNOWN}; + } + $temp = sprintf( "%.2f", $1 ); + return $temp; +} + +sub report($$$) { + my ( $temp, $warning, $critical ) = @_; + $warning = sprintf( "%.2f", $$warning ); + $critical = sprintf( "%.2f", $$critical ); + + $$temp =~ /^(\d+)\.(\d+)/; + my $ta = $1; + my $tb = $2; + + $warning =~ /^(\d+)\.(\d+)/; + my $wa = $1; + my $wb = $2; + + $critical =~ /^(\d+)\.(\d+)/; + my $ca = $1; + my $cb = $2; + + if ( $ta > $ca ) { + print + "$NAME CRITICAL: +$$temp C | roomtemp=$$temp;$warning;$critical\n"; + exit $ERRORS{CRITICAL}; + } + if ( ( $ta == $ca ) && ( $tb >= $cb ) ) { + print + "$NAME CRITICAL: +$$temp C | roomtemp=$$temp;$warning;$critical\n"; + exit $ERRORS{CRITICAL}; + } + if ( $ta > $wa ) { + print "$NAME WARNING: +$$temp C | roomtemp=$$temp;$warning;$critical\n"; + exit $ERRORS{WARNING}; + } + if ( ( $ta == $wa ) && ( $tb >= $wb ) ) { + print "$NAME WARNING: +$$temp C | roomtemp=$$temp;$warning;$critical\n"; + exit $ERRORS{WARNING}; + } + print "$NAME OK: +$$temp C | roomtemp=$$temp;$warning;$critical\n"; + exit $ERRORS{OK}; +} + +sub version($$) { + my ( $progname, $version ) = @_; + + print <<_VERSION; +$progname version $version +Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. + +$ME comes with ABSOLUTELY NO WARRANTY. This is free software, +and you are welcome to redistribute it under certain conditions. +See the GNU General Public Licence for details. +_VERSION +} + +__END__ + +=head1 NAME + +check_roomtemp - nagios plugin to check room temperature + +=head1 SYNOPSIS + +check_roomtemp [B<-w>|B<--warning> I] [B<-c>|B<--critical> I] + +check_roomtemp [B<-u>|B<--url> I] + +check_roomtemp [B<-s>|B<--search> I] + +check_roomtemp [B<-h>|B<--help>] + +check_roomtemp [B<-m>|B<--man>] + +check_roomtemp [B<-V>|B<--version>] + +=head1 OPTIONS + +=over + +=item B<-w>|B<--warning> I + +Exit with WARNING status if temperature is greater than or equal this value (default: 35.00) + +=item B<-c>|B<--critical> I + +Exit with CRITICAL status if temperature is greater than or equal this value (default: 40.00) + +=item B<-u>|B<--url> I + +URL for geting status information (default: 'http://thermo1.vic.site/status.xml') + +=item B<-s>|B<--search> I + +Search string for the temperature on the given url (default: '[+-]\s+([\d\.]+)') + +=item B<-h>|B<--help> + +Print detailed help screen. + +=item B<-m>|B<--man> + +Print manual page. + +=item B<-V>|B<--version> + +Print version information. + +=back + +=head1 DESCRIPTION + +This nagios plugin check the room temperature. + +=head1 VERSION + +This man page is current for version 0.1 of B. + +=head1 AUTHOR + +Written by Christian Arnold L + +=head1 COPYRIGHT + +Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. +This is free software, and you are welcome to redistribute it under certain conditions. +See the GNU General Public Licence for details. + +=cut