| 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; |
|---|