check_file_age modification - state if it is size or age in the warning/crit output

Joseph McCarthy jmccarthy at simplextrading.com
Fri Jan 9 17:15:49 CET 2026


Recently we've had some developers complain that it's difficult to
determine at a glance what is wrong with certain checks so I've made a
slight modification to the output - I'm not an expert in perl but it's been
helpful so far, see attached :

 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, $perfdata);
+my ($result, $prepend, $message, $age, $size, $st, $perfdata);

 $PROGNAME="check_file_age";

@@ -91,7 +91,7 @@ $age = time - $st->mtime;
 $size = $st->size;

 $result = 'OK';
-
+$prepend = '';
 if ($opt_c !~ m/^\d+$/ or ($opt_C and $opt_C !~ m/^\d+$/)
                or $opt_w !~ m/^\d+$/ or ($opt_W and $opt_W !~ m/^\d+$/)) {
        # range has been specified so use M::P::R to process
@@ -103,34 +103,49 @@ if ($opt_c !~ m/^\d+$/ or ($opt_C and $opt_C !~
m/^\d+$/)
        if (Monitoring::Plugin::Range->parse_range_string($opt_c)
                ->check_range($age) == 1) { # 1 means it raises an alert
because it's OUTSIDE the range
                        $result = 'CRITICAL';
+                       $prepend = 'AGE';
        }
        elsif (Monitoring::Plugin::Range->parse_range_string($opt_C)
                ->check_range($size) == 1) {
                        $result = 'CRITICAL';
+                       $prepend = 'SIZE';
        }
        elsif (Monitoring::Plugin::Range->parse_range_string($opt_w)
                ->check_range($age) == 1) {
                        $result = 'WARNING';
+                       $prepend = 'AGE';
        }
        elsif (Monitoring::Plugin::Range->parse_range_string($opt_W)
                ->check_range($size) == 1) {
                        $result = 'WARNING';
+                       $prepend = 'SIZE';
        }
 }
 else {
        # use permissive defaults for size when none specified
        $opt_W = 0 unless ($opt_W);
        $opt_C = 0 unless ($opt_C);
-       if ($age > $opt_c or $size < $opt_C) {
-               $result = 'CRITICAL';
+       if ($age > $opt_c) {
+               $result = 'CRITICAL';
+               $prepend  = 'AGE';
+       }
+       elsif ($size < $opt_C) {
+               $result = 'CRITICAL';
+               $prepend = 'SIZE';
        }
-       elsif ($age > $opt_w or $size < $opt_W) {
-               $result = 'WARNING';
+       elsif ($age > $opt_w) {
+               $result = 'WARNING';
+               $prepend = "AGE";
        }
+       elsif ($size < $opt_W) {
+               $result = 'WARNING';
+               $prepend = 'SIZE';
+       }
+
 }

 $perfdata = "age=${age}s;${opt_w};${opt_c}
size=${size}B;${opt_W};${opt_C};0";
-print "FILE_AGE $result: $opt_f is $age seconds old and $size bytes |
$perfdata\n";
+print "FILE $prepend $result: $opt_f is $age seconds old and $size bytes |
$perfdata\n";
-- 
Thanks,

Joseph McCarthy | IT | Simplex | 312-754-3588
230 S. LaSalle St., Suite 8-500, Chicago, IL 60604

-- 
DISCLAIMER: NOTICE REGARDING PRIVACY AND CONFIDENTIALITY 

The information 
contained in and/or accompanying this communication is intended only for 
use by the addressee(s) named herein and may contain legally privileged 
and/or confidential information. If you are not the intended recipient of 
this e-mail, you are hereby notified that any dissemination, distribution 
or copying of this information, and any attachments thereto, is strictly 
prohibited. If you have received this e-mail in error, please immediately 
notify the sender and permanently delete the original and any copy of any 
e-mail and any printout thereof. Electronic transmissions cannot be 
guaranteed to be secure or error-free. The sender therefore does not accept 
liability for any errors or omissions in the contents of this message which 
arise as a result of e-mail transmission. Simplex Trading, LLC and its 
affiliates reserves the right to intercept, monitor, and retain electronic 
communications to and from its system as permitted by law. Simplex Trading, 
LLC is a registered Broker Dealer with CBOE and a Member of SIPC.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20260109/a0e14a8d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_file_age_mp.sh
Type: text/x-sh
Size: 5467 bytes
Desc: not available
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20260109/a0e14a8d/attachment.sh>


More information about the Devel mailing list