#!/usr/bin/perl -w use strict; use Getopt::Long; my $verbose=0; my $help; my $TIMEOUT = 10; GetOptions("help" => \$help, "verbose|v+" => \$verbose ); my %ERRORS=(OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3, DEPENDENT=>4); my $QUERY_DB = "/usr/bin/queryDb"; if ( ! -x $QUERY_DB ) { print "ERROR: cannot execute $QUERY_DB: $!\n"; exit $ERRORS{"UNKNOWN"}; } my $result = $ERRORS{"UNKNOWN"}; my $message = ""; # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print "ERROR: alarm timeout\n"; exit $ERRORS{"UNKNOWN"}; }; alarm($TIMEOUT); ############################################################################## # # output of queryDb # my @job_states = ( "REGISTERED", "IDLE", "RUNNING", "REALLY-RUNNING" ); my $cmd = "$QUERY_DB -vS -s " . join( ",", @job_states ); if ( ! open QRY, "$cmd | " ) { print "ERROR: cannot read from command $cmd\n"; exit $ERRORS{"UNKNOWN"}; } my %state_count; while ( ) { if ( /^.(\w+).$/ ) { $state_count{$1}++; } } close QRY; alarm(0); $message = "OK"; $result = $ERRORS{"OK"}; # performance data my $perf = ""; foreach my $js ( @job_states ) { $state_count{$js} |= 0; $perf .= sprintf "'%s'=%d ", $js, $state_count{$js}; } # Write output and return exit code; print "$message|$perf\n"; exit($result);