[Resmon-devel] [resmon commit] r160 - trunk/lib/Resmon/Module
svn-commit at lists.omniti.com
svn-commit at lists.omniti.com
Mon Mar 9 17:49:00 EDT 2009
Author: mark
Date: 2009-03-09 17:48:59 -0400 (Mon, 09 Mar 2009)
New Revision: 160
Added:
trunk/lib/Resmon/Module/NAGIOS.pm
Log:
Module to run nagios scripts as resmon checks
Added: trunk/lib/Resmon/Module/NAGIOS.pm
===================================================================
--- trunk/lib/Resmon/Module/NAGIOS.pm (rev 0)
+++ trunk/lib/Resmon/Module/NAGIOS.pm 2009-03-09 21:48:59 UTC (rev 160)
@@ -0,0 +1,46 @@
+package Resmon::Module::NAGIOS;
+use vars qw/@ISA/;
+ at ISA = qw/Resmon::Module/;
+
+# Runs a nagios check script as a resmon check
+# Example config file:
+# NAGIOS {
+# /path/to/check_something : args => -a my args
+# /path/to/check_something_else : args => -a my args -w 10 -c 20
+# }
+
+sub handler {
+ my $arg = shift;
+ my $script = $arg->{'object'} || return "BAD", "No script specified";
+ my $scriptargs = $arg->{'args'};
+ my $output = `$script $scriptargs`;
+ my $retval = $?;
+ if ($retval == -1) {
+ return "BAD", "command returning -1";
+ }
+ $retval = $retval >> 8;
+ my $status = "BAD";
+ # 0 - OK, 1 - WARNING, 2 - CRITICAL, 3 - UNKNOWN
+ # Treat UNKNOWN (and any other return code) as bad
+ if ($retval == 0) {
+ $status = "OK";
+ } elsif ($retval == 1) {
+ $status = "WARNING";
+ } elsif ($retval == 3) {
+ $output = "UNKNOWN: $output";
+ }
+ if ($output) {
+ ($output, $perfdata) = split(/\s*\|\s*/, $output, 2);
+ chomp($output);
+ chomp($perfdata);
+ # This will show up in the resmon status page
+ if ($perfdata) {
+ $arg->{'perfdata'} = $perfdata;
+ }
+ return $status, $output;
+ } else {
+ return "BAD", "No output from check";
+ }
+}
+
+1;
More information about the Resmon-devel
mailing list