root/lib/Resmon/Module/NEWFILES.pm

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

Fix for perl's braindead 'let's measure file modified time from program start
instead of when we actually run the check' -M operator.

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

  • Property mode set to 100644
Line 
1 package Resmon::Module::NEWFILES;
2 use Resmon::ExtComm qw/cache_command/;
3 use vars qw/@ISA/;
4 use File::Find;
5 @ISA = qw/Resmon::Module/;
6
7 # Checks to ensure that files exist in a directory that are younger than a
8 #   certain time
9 # Parameters:
10 #   minutes : how old can the newest file be before we alarm
11 #   filecount : how many new files do we require (default 1)
12 # Example:
13 #
14 # NEWFILES {
15 #   /test/dir : minutes => 5
16 #   /other/dir : minutes => 60, filecount => 2
17 # }
18
19 my $minutes;
20 my $newcount = 0;
21
22 sub handler {
23     my $arg = shift;
24     my $dir = $arg->{'object'};
25     $minutes = $arg->{'minutes'};
26     my $filecount = $arg->{'filecount'} || 1;
27     $newcount = 0;
28
29     # Then look for new files
30     find(\&wanted, $dir);
31     if ($newcount >= $filecount) {
32         return "OK", "$newcount files";
33     } else {
34         return "BAD", "$newcount files";
35     }
36 }
37
38 sub wanted {
39     my @fstat = stat($_);
40     my $lastmodified = time() - $fstat[9];
41     -f $_ && $lastmodified < ($minutes * 60) && $newcount++;
42 }
43
44 1;
Note: See TracBrowser for help on using the browser.