Skip to content
Snippets Groups Projects
Commit a9ccc806 authored by Mark Harrison's avatar Mark Harrison
Browse files

Remove replaced modules

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@360 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 84f1edad
No related branches found
No related tags found
No related merge requests found
package Resmon::Module::FILEAGE;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;
sub handler {
my $arg = shift;
my $file = $arg->{'object'};
my @statinfo = stat($file);
if (@statinfo) {
my $age = time() - $statinfo[9];
return "BAD($age seconds, too old)"
if($arg->{maximum} && ($age > $arg->{maximum}));
return "BAD($age seconds, too new)"
if($arg->{minimum} && ($age > $arg->{minimum}));
return "OK($age seconds)";
} elsif ($arg->{'allowmissing'} eq "yes") {
return "OK", "No file";
} else {
return "BAD", "File missing";
}
}
1;
package Resmon::Module::FILECOUNT;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;
sub handler {
my $arg = shift;
my $dir = $arg->{'object'};
my $hlimit = $arg->{'hard_limit'};
my $slimit = $arg->{'soft_limit'};
my $output = cache_command("ls $dir | wc -l",30);
chomp($output);
if ($output > $hlimit) {
return "BAD", "$output files";
} elsif ($output > $slimit) {
return "WARNING", "$output files";
} else {
return "OK", "$output files";
}
}
1;
package Resmon::Module::FILESIZE;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;
sub handler {
my $arg = shift;
my $file = $arg->{'object'};
my @statinfo = stat($file);
my $size = $statinfo[7];
my $minsize = $arg->{minimum};
my $maxsize = $arg->{maximum};
return "BAD($size, too big)"
if($maxsize && ($size > $maxsize));
return "BAD($size, too small)"
if($minsize && ($size > $minsize));
return "OK($size)";
}
1;
package Resmon::Module::LARGEFILES;
use Resmon::Module;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;
sub handler {
my $arg = shift;
my $dir = $arg->{'object'};
opendir(DIR, $dir);
my @bigfiles = grep { my @fileinfo = stat; $fileinfo[7] > $arg->{'limit'} } readdir(DIR);
closedir(DIR);
if (scalar(@bigfiles) > 0) {
return "BAD(large files exist)";
} else {
return "OK(no large files)";
}
}
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 {
my @fstat = stat($_);
my $lastmodified = time() - $fstat[9];
-f $_ && $lastmodified < ($minutes * 60) && $newcount++;
}
1;
package Resmon::Module::OLDFILES;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
use File::Find;
@ISA = qw/Resmon::Module/;
# Checks for files in a directory older than a certain time
# Parameters:
# minutes : how old can the files be before we alarm
# checkmount : check to make sure the directory is mounted first
# (only enable if the dir you are checking is the mountpoint of
# a filesystem)
# filecount : how many old files will we allow before alarming. If this is not
# set, then we will alarm if any files are old.
# Example:
#
# OLDFILES {
# /test/dir : minutes => 5, filecount => 2, checkmount => 1
# /other/dir : minutes => 60
# }
my $minutes;
my $oldcount = 0;
sub handler {
my $arg = shift;
my $dir = $arg->{'object'};
$minutes = $arg->{'minutes'};
my $filecount = $arg->{'filecount'} || 0;
my $checkmount = $arg->{'checkmount'} || 0;
$oldcount = 0;
# Check to make sure the directory is mounted first
if ($checkmount) {
my $output = cache_command("df -k", 600);
my ($line) = grep(/$dir\s*/, split(/\n/, $output));
if($line !~ /(\d+)%/) {
return "BAD", "0 dir not mounted";
}
}
# Then look for old files
find(\&wanted, $dir);
if ($oldcount <= $filecount) {
return "OK", "$oldcount files";
} else {
return "BAD", "$oldcount files";
}
}
sub wanted {
my @fstat = stat($_);
my $lastmodified = time() - $fstat[9];
-f $_ && $lastmodified > ($minutes * 60) && $oldcount++;
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment