root/lib/Resmon/Module/OLDFILES.pm

Revision 09340b7c059b4f038beb3376f6e5c52b1fa0e2d3, 1.3 kB (checked in by Mark Harrison <mark@omniti.com>, 10 years ago)

Adding updated OLDFILES/DIRAGE check used in bluestreak ionmx monitoring.

git-svn-id: https://labs.omniti.com/resmon/trunk@97 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 @ISA = qw/Resmon::Module/;
5
6 # Checks for files in a directory older than a certain time
7 # Parameters:
8 #   minutes : how old can the files be before we alarm
9 #   checkmount : check to make sure the directory is mounted first
10 #                (only enable if the dir you are checking is the mountpoint of
11 #                a filesystem)
12 # Example:
13 #
14 # OLDFILES {
15 #   /test/dir : minutes => 5, checkmount => 1
16 #   /other/dir : minutes => 60
17 # }
18
19 sub handler {
20     my $arg = shift;
21     my $os = $arg->fresh_status();
22     return $os if $os;
23     my $dir = $arg->{'object'};
24     my $minutes = $arg->{'minutes'};
25     my $checkmount = $arg->{'checkmount'} || 0;
26
27     # Check to make sure the directory is mounted first
28     if ($checkmount) {
29         my $output = cache_command("df -k", 600);
30         my ($line) = grep(/$dir\s*/, split(/\n/, $output));
31         if($line !~ /(\d+)%/) {
32             return "BAD", "dir not mounted";
33         }
34     }
35
36     # Then look for old files
37     my $output = cache_command("find $dir -mmin +$minutes | wc -l", 600);
38     chomp($output);
39     if ($output == 0) {
40         return "OK", "0 files over $minutes minutes";
41     } else {
42         return "BAD", "$output files over $minutes minutes";
43     }
44 }
45
46 1;
Note: See TracBrowser for help on using the browser.