From cdb0c8f5dc8a840d4915dfffa9978e4e586e85ff Mon Sep 17 00:00:00 2001
From: Chris Nehren <cnehren@omniti.com>
Date: Wed, 19 Jun 2013 13:44:27 -0400
Subject: [PATCH] Add an optional cache argument to the WatchOutput command,
 and test this value to determine whether to use cache_command or run_command.

---
 lib/Core/WatchOutput.pm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/Core/WatchOutput.pm b/lib/Core/WatchOutput.pm
index dd59002..d8f099d 100644
--- a/lib/Core/WatchOutput.pm
+++ b/lib/Core/WatchOutput.pm
@@ -16,7 +16,7 @@ Core::WatchOutout - watch a command's output, reporting it
 =head1 SYNOPSIS
 
  Core::WatchOutput {
-     ls: command => "/bin/ls"
+     ls: command => "/bin/ls", cache => 3600
  }
 
 =head1 DESCRIPTION
@@ -32,6 +32,11 @@ This check will run a given command and return the output as the
 
 This is a string of the command name and any arguments.
 
+=item cache
+
+The duration, in seconds, to cache the output of the command. If this
+value is missing, there is no caching.
+
 =back
 
 =head1 METRICS
@@ -62,8 +67,14 @@ sub handler {
     my $self = shift;
     my $config = $self->{config};
     my $command = $config->{command};
-
-    my $output = run_command($command);
+    my $cache = exists $config->{cache} ? $config->{cache} : 0;
+
+    my $output;
+    if($cache) {
+        $output = cache_command($command, $cache);
+    } else {
+        my $output = run_command($command);
+    }
     chomp $output;
     my $status = $? >> 8;
 
-- 
GitLab