From a52fa9dc3db79627e1654766a752db5c62ccf499 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Fri, 12 Nov 2010 17:36:40 -0500 Subject: add an option to directly pipe results to nagios to avoid timeouts --- files/checkbackups.pl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index 106463a..0ea4805 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -44,10 +44,11 @@ our $opt_c = 48 * 60 * 60; our $opt_w = 24 * 60 * 60; our $opt_v = 0; our $opt_o; +our $opt_s; -if (!getopts('d:c:w:vo')) { +if (!getopts('d:c:w:s:vo')) { print < ] [ -c ] [ -w ] [ -o ] [ -v ] +Usage: $0 [ -d ] [ -c ] [ -w ] [ -o ] [ -s ] [ -v ] EOF ; exit(); @@ -122,7 +123,16 @@ sub print_status { if (!$service) { $service = 'backups'; } - printf "$host\t$service\t$state\t$state_msg $message\n"; + $line = "$host\t$service\t$state\t$state_msg $message\n"; + if ($opt_s) { + $opt_v && print STDERR "sending results to nagios...\n"; + open(NSCA, "|/usr/sbin/send_nsca -H $opt_s") or die("cannot start send_nsca: $!\n"); + print NSCA $line; + close(NSCA) or warn("could not close send_nsca pipe correctly: $!\n"); + } + if (!$opt_s || $opt_v) { + printf $line; + } } sub check_flag { -- cgit v1.2.3