From a170ad2debac85a9558464405e5dd5e981be2dcb Mon Sep 17 00:00:00 2001 From: neophenix <neophenix@gmail.com> Date: Thu, 28 Feb 2013 10:19:36 -0500 Subject: [PATCH] Allow setting an absent => X config param for file checks. If set will return all the metrics the module normally would, but with their integer values set to whatever you defined for absent. present will still = 0 and text values will be undef --- lib/Core/File.pm | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/Core/File.pm b/lib/Core/File.pm index 4a356d7..ffca5e1 100644 --- a/lib/Core/File.pm +++ b/lib/Core/File.pm @@ -31,6 +31,13 @@ This module retrieves metrics on a single file such as file age and file size. The check name specifies which file to monitor. +=item absent + +Normally if the file is absent you will get back a single present = 0 metric. +If absent is set you will instead get back all of the metrics, strings will be +null and integers will be whatever value you set for absent (present will still +be 0). + =back =head1 METRICS @@ -84,9 +91,30 @@ sub handler { if (!@statinfo) { # File is missing - return { - "present" => [0, "i"] + my $ret = {}; + if ( defined $config->{absent} ) { + $ret = { + "present" => [0, "i"], + "permissions" => [undef, "s"], + "hardlinks" => [$config->{absent},"i"], + "uid" => [undef,"s"], + "gid" => [undef,"s"], + "size" => [$config->{absent},"i"], + "atime" => [$config->{absent},"i"], + "mtime" => [$config->{absent},"i"], + "ctime" => [$config->{absent},"i"], + "aage" => [$config->{absent},"i"], + "mage" => [$config->{absent},"i"], + "cage" => [$config->{absent},"i"] + }; } + else { + $ret = { + "present" => [0, "i"] + }; + } + + return $ret; } else { my $now = time; return { -- GitLab