mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-09 08:42:17 -04:00
check_file_age: Provide performance data
This commit is contained in:
parent
849eb5725c
commit
3b02d7fafb
3 changed files with 11 additions and 3 deletions
1
NEWS
1
NEWS
|
|
@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases.
|
|||
check_disk shows now troubled partions in verbose mode
|
||||
check_dig has now support for drill and dig
|
||||
check_dig has now support for -6 option
|
||||
Add performance data to check_file_age
|
||||
|
||||
FIXES
|
||||
Fix check_jabber to work with Openfire servers
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ sub print_help ();
|
|||
sub print_usage ();
|
||||
|
||||
my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i);
|
||||
my ($result, $message, $age, $size, $st);
|
||||
my ($result, $message, $age, $size, $st, $perfdata);
|
||||
|
||||
$PROGNAME="check_file_age";
|
||||
|
||||
|
|
@ -92,6 +92,7 @@ unless (-e $opt_f) {
|
|||
$st = File::stat::stat($opt_f);
|
||||
$age = time - $st->mtime;
|
||||
$size = $st->size;
|
||||
$perfdata = "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0";
|
||||
|
||||
|
||||
$result = 'OK';
|
||||
|
|
@ -103,7 +104,7 @@ elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
|
|||
$result = 'WARNING';
|
||||
}
|
||||
|
||||
print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes\n";
|
||||
print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes | $perfdata\n";
|
||||
exit $ERRORS{$result};
|
||||
|
||||
sub print_usage () {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@
|
|||
#
|
||||
|
||||
use strict;
|
||||
use Test::More tests => 16;
|
||||
use Test::More tests => 17;
|
||||
use NPTest;
|
||||
|
||||
my $successOutput = '/^FILE_AGE OK: /';
|
||||
my $warningOutput = '/^FILE_AGE WARNING: /';
|
||||
my $criticalOutput = '/^FILE_AGE CRITICAL: /';
|
||||
my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
|
||||
my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/';
|
||||
|
||||
my $result;
|
||||
my $temp_file = "/tmp/check_file_age.tmp";
|
||||
|
|
@ -57,6 +58,11 @@ $result = NPTest->testCmd(
|
|||
);
|
||||
cmp_ok( $result->return_code, '==', 0, "Checking file size" );
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_file_age -f $temp_file -c 1000 -W 100"
|
||||
);
|
||||
like( $result->output, $performanceOutput, "Checking for performance Output" );
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_file_age -f /non/existent --ignore-missing"
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue