root/lib/Resmon/Module/OLDFILES.pm

Revision ae22e3bd765158b778bd93baa267afae17fe7fa2, 1.5 kB (checked in by Mark Harrison <mark@omniti.com>, 6 years ago)

Moving the fresh_status and set_status code outside of the modules themselves,
making module development simpler. Also fixed an issue with the fresh_status
function where it didn't return a cached message, and resmon showed nothing
for the message. refs #1

git-svn-id: https://labs.omniti.com/resmon/trunk@135 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Resmon::Module::OLDFILES;
2 use Resmon::ExtComm qw/cache_command/;
3 use vars qw/@ISA/;
4 use File::Find;
5 @ISA = qw/Resmon::Module/;
6
7 # Checks for files in a directory older than a certain time
8 # Parameters:
9 #   minutes : how old can the files be before we alarm
10 #   checkmount : check to make sure the directory is mounted first
11 #                (only enable if the dir you are checking is the mountpoint of
12 #                a filesystem)
13 #   filecount : how many old files will we allow before alarming. If this is not
14 #           set, then we will alarm if any files are old.
15 # Example:
16 #
17 # OLDFILES {
18 #   /test/dir : minutes => 5, filecount => 2, checkmount => 1
19 #   /other/dir : minutes => 60
20 # }
21
22 my $minutes;
23 my $oldcount = 0;
24
25 sub handler {
26     my $arg = shift;
27     my $dir = $arg->{'object'};
28     $minutes = $arg->{'minutes'};
29     my $filecount = $arg->{'filecount'} || 0;
30     my $checkmount = $arg->{'checkmount'} || 0;
31
32     # Check to make sure the directory is mounted first
33     if ($checkmount) {
34         my $output = cache_command("df -k", 600);
35         my ($line) = grep(/$dir\s*/, split(/\n/, $output));
36         if($line !~ /(\d+)%/) {
37             return "BAD", "0 dir not mounted";
38         }
39     }
40
41     # Then look for old files
42     find(\&wanted, $dir);
43     if ($oldcount <= $filecount) {
44         return "OK", "$oldcount files";
45     } else {
46         return "BAD", "$oldcount files";
47     }
48 }
49
50 sub wanted {
51     -f $_ && -M $_ > ($minutes / 1440) && $oldcount++;
52 }
53
54 1;
Note: See TracBrowser for help on using the browser.