From abab5d634b66a61538a9e91dc29bf4324239d62d Mon Sep 17 00:00:00 2001
From: Mark Harrison <mark@omniti.com>
Date: Mon, 19 May 2008 17:56:40 +0000
Subject: [PATCH] Adding a 'run helper script and return the output' check, to
 deal with some custom helper scripts the bluestreak checks use.

git-svn-id: https://labs.omniti.com/resmon/trunk@99 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
---
 lib/Resmon/Module/SCRIPT.pm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 lib/Resmon/Module/SCRIPT.pm

diff --git a/lib/Resmon/Module/SCRIPT.pm b/lib/Resmon/Module/SCRIPT.pm
new file mode 100644
index 0000000..b2d6def
--- /dev/null
+++ b/lib/Resmon/Module/SCRIPT.pm
@@ -0,0 +1,29 @@
+package Resmon::Module::SCRIPT;
+use Resmon::ExtComm qw/cache_command/;
+use vars qw/@ISA/;
+@ISA = qw/Resmon::Module/;
+
+# Runs a custom helper script, returning the output.
+# Example config file:
+# SCRIPT {
+#   name : script => /path/to/perl_script.pl, cache => 30
+#   name2 : script => /path/to/another_script.pl, cache => 30
+# }
+
+sub handler {
+    my $arg = shift;
+    my $os = $arg->fresh_status();
+    return $os if $os;
+    my $object = $arg->{'object'};
+    my $script = $arg->{'script'} || return "BAD", "No script specified";
+    my $timeout = $arg->{'timeout'} || 30;
+    my $output = cache_command("$script", $timeout);
+    if ($output) {
+        chomp($output);
+        return $arg->set_status($output);
+    } else {
+        return "BAD", "No output from command";
+    }
+}
+
+1;
-- 
GitLab