From 488858af8e3900be24c4acfced5c92258db3cd3e Mon Sep 17 00:00:00 2001
From: Mark Harrison <mark@omniti.com>
Date: Tue, 20 May 2008 17:20:25 +0000
Subject: [PATCH] Adding a filecount parameter to the oldfiles module to only
 alarm after a specific number of files are 'old'.

git-svn-id: https://labs.omniti.com/resmon/trunk@102 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
---
 lib/Resmon/Module/OLDFILES.pm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/Resmon/Module/OLDFILES.pm b/lib/Resmon/Module/OLDFILES.pm
index 331ee30..4deebab 100644
--- a/lib/Resmon/Module/OLDFILES.pm
+++ b/lib/Resmon/Module/OLDFILES.pm
@@ -9,10 +9,12 @@ use vars qw/@ISA/;
 #   checkmount : check to make sure the directory is mounted first
 #                (only enable if the dir you are checking is the mountpoint of
 #                a filesystem)
+#   filecount : how many old files will we allow before alarming. If this is not
+#           set, then we will alarm if any files are old.
 # Example:
 #
 # OLDFILES {
-#   /test/dir : minutes => 5, checkmount => 1
+#   /test/dir : minutes => 5, filecount => 2, checkmount => 1
 #   /other/dir : minutes => 60
 # }
 
@@ -22,6 +24,7 @@ sub handler {
     return $os if $os;
     my $dir = $arg->{'object'};
     my $minutes = $arg->{'minutes'};
+    my $filecount = $arg->{'filecount'} || 0;
     my $checkmount = $arg->{'checkmount'} || 0;
 
     # Check to make sure the directory is mounted first
@@ -36,8 +39,8 @@ sub handler {
     # Then look for old files
     my $output = cache_command("find $dir -mmin +$minutes | wc -l", 600);
     chomp($output);
-    if ($output == 0) {
-        return "OK", "0 files over $minutes minutes";
+    if ($output <= $filecount) {
+        return "OK", "$output files over $minutes minutes";
     } else {
         return "BAD", "$output files over $minutes minutes";
     }
-- 
GitLab