=================================================================== RCS file: /cvs/nagios/check_bioctl/check_bioctl,v retrieving revision 1.7 retrieving revision 1.10 diff -u -r1.7 -r1.10 --- nagios/check_bioctl/check_bioctl 2009/11/09 18:00:09 1.7 +++ nagios/check_bioctl/check_bioctl 2009/11/12 18:54:38 1.10 @@ -1,13 +1,10 @@ #!/usr/bin/perl -T -# $RedRiver: check_bioctl,v 1.6 2009/11/09 17:58:29 andrew Exp $ +# $RedRiver: check_bioctl,v 1.9 2009/11/09 20:22:43 andrew Exp $ ######################################################################## # check_bioctl *** A nagios check for OpenBSD bioctl # -# 2006.07.26 #*#*# andrew fresh +# 2006.07.26 #*#*# andrew fresh ######################################################################## -# TODO: -# Really need real documentation. -######################################################################## use strict; use warnings; @@ -15,16 +12,43 @@ use constant NAGIOS_OUTPUT => 1; -use POSIX; -use lib "/usr/local/libexec/nagios"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); +my $License = <<'EOL'; +Copyright (c) 2009 Andrew Fresh +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. -use Getopt::Long; -Getopt::Long::Configure('bundling'); +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +EOL my $PROGNAME = "check_bioctl"; my $BIOCTL = '/sbin/bioctl'; +use POSIX; +my $PREFIX; +BEGIN { + ## no critic 'warnings' + no warnings 'uninitialized'; + $PREFIX = "${PREFIX}" || '/usr/local'; # Magic for OpenBSD ports tree +} +use lib $PREFIX . '/libexec/nagios'; +use utils qw($TIMEOUT %ERRORS &support); + +$SIG{'ALRM'} = sub { + print ("ERROR: $PROGNAME timeout\n"); + exit $ERRORS{'UNKNOWN'}; +}; +alarm($TIMEOUT); + +use Getopt::Long; +Getopt::Long::Configure('bundling'); + # This maps the status we get from bioctl to something nagios can use my %Status_Map = ( Online => 'OK', @@ -58,7 +82,7 @@ } if ($opt_V) { - print_revision( $PROGNAME, '$Revision: 1.7 $ ' ); + print_revision( $PROGNAME, '$Revision: 1.10 $ ' ); exit $ERRORS{'OK'}; } @@ -69,7 +93,7 @@ my %VOLUMES; foreach my $device (@devices) { - open my $bioctl, "-|", $BIOCTL, $device or die "Couldn't open bioctl: $!"; + open my $bioctl, '-|', $BIOCTL, $device or die "Couldn't open bioctl: $!"; my $volume_id; while (<$bioctl>) { @@ -141,6 +165,7 @@ } my $have_results = 0; +$state = 'OK'; foreach my $error ( sort { $ERRORS{$b} <=> $ERRORS{$a} } keys %ERRORS ) { if ( exists $states{$error} ) { $have_results++; @@ -148,7 +173,7 @@ if (NAGIOS_OUTPUT) { print "$error (" . scalar( @{ $states{$error} } ) . ")"; - unless ( $error eq 'OK' ) { + if ( $error ne 'OK' ) { print '
'; print map {" - $_
"} @{ $states{$error} }; } @@ -165,7 +190,7 @@ exit $ERRORS{$state}; sub print_help { - print < [ -d [ -d ... ] ] @@ -177,6 +202,15 @@ EOL - print_revision( $PROGNAME, '$Revision: 1.7 $' ); + print_revision( $PROGNAME, '$Revision: 1.10 $' ); + + print $License; } + +sub print_revision { + my ($prog, $rev) = @_; + $rev =~ s/^\D+([\d\.]+)\D+$/v$1/xms; + + print "$prog $rev\n"; +}