package Resmon::Module::NEWFILES;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
use File::Find;
@ISA = qw/Resmon::Module/;

# Checks to ensure that files exist in a directory that are younger than a
#   certain time
# Parameters:
#   minutes : how old can the newest file be before we alarm
#   filecount : how many new files do we require (default 1)
# Example:
#
# NEWFILES {
#   /test/dir : minutes => 5
#   /other/dir : minutes => 60, filecount => 2
# }

my $minutes;
my $newcount = 0;

sub handler {
    my $arg = shift;
    my $dir = $arg->{'object'};
    $minutes = $arg->{'minutes'};
    my $filecount = $arg->{'filecount'} || 1;

    # Then look for new files
    find(\&wanted, $dir);
    if ($newcount >= $filecount) {
        return "OK", "$newcount files";
    } else {
        return "BAD", "$newcount files";
    }
}

sub wanted {
    -f $_ && -M $_ < ($minutes / 1440) && $newcount++;
}

1;

package Resmon::Module::NEWFILES;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
use File::Find;
@ISA = qw/Resmon::Module/;

# Checks to ensure that files exist in a directory that are younger than a
#   certain time
# Parameters:
#   minutes : how old can the newest file be before we alarm
#   filecount : how many new files do we require (default 1)
# Example:
#
# NEWFILES {
#   /test/dir : minutes => 5
#   /other/dir : minutes => 60, filecount => 2
# }

my $minutes;
my $newcount = 0;

sub handler {
    my $arg = shift;
    my $dir = $arg->{'object'};
    $minutes = $arg->{'minutes'};
    my $filecount = $arg->{'filecount'} || 1;
    $newcount = 0;

    # Then look for new files
    find(\&wanted, $dir);
    if ($newcount >= $filecount) {
        return "OK", "$newcount files";
    } else {
        return "BAD", "$newcount files";
    }
}

sub wanted {
    -f $_ && -M $_ < ($minutes / 1440) && $newcount++;
}

1;

Make sure to reset the file count on each check
Make sure to reset the file count on each check


git-svn-id: f288825eac1cbbbc51b99d82d097385cba0e17f8@143 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
