aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/check_uptime.pl
diff options
context:
space:
mode:
authorGravatar Andreas Motl <andreas.motl@elmyra.de> 2022-02-12 14:41:54 +0100
committerGravatar Sven Nierlein <sven@nierlein.org> 2022-02-15 16:09:47 +0100
commitc99a166a43fb9da42ba68073224921124a435aab (patch)
tree559d6b1a6dd822004d5f1e2becf822ed7838edea /plugins-scripts/check_uptime.pl
parent5943528121033579033c5a372df6c5e91b22e723 (diff)
downloadmonitoring-plugins-c99a166a43fb9da42ba68073224921124a435aab.tar.gz
check_uptime: Add option to report uptime in days instead of seconds
Currently, the plugin output is: CRITICAL: Uptime is 38829029 seconds. When using the proposed `--days|-d` option, it will be: CRITICAL: Uptime is 449 days.
Diffstat (limited to 'plugins-scripts/check_uptime.pl')
-rwxr-xr-xplugins-scripts/check_uptime.pl17
1 files changed, 15 insertions, 2 deletions
diff --git a/plugins-scripts/check_uptime.pl b/plugins-scripts/check_uptime.pl
index 4c9f22da..04324b2e 100755
--- a/plugins-scripts/check_uptime.pl
+++ b/plugins-scripts/check_uptime.pl
@@ -25,7 +25,7 @@ use POSIX;
use strict;
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c
- $opt_f $opt_s
+ $opt_f $opt_s $opt_d
$lower_warn_threshold $upper_warn_threshold
$lower_crit_threshold $upper_crit_threshold
$status $state $msg);
@@ -137,9 +137,20 @@ if ( $uptime_seconds > $upper_crit_threshold ) {
$state_str = "OK";
}
+# Prepare uptime value (seconds or days)
+my $uptime_text = "";
+my $uptime_unit = "";
+if ( $opt_d ) {
+ $uptime_text = floor($uptime_seconds / 60 / 60 / 24);
+ $uptime_unit = "days";
+} else {
+ $uptime_text = $uptime_seconds;
+ $uptime_unit = "seconds";
+}
+
$msg = "$state_str: ";
-$msg .= "uptime is $uptime_seconds seconds. ";
+$msg .= "uptime is $uptime_text $uptime_unit. ";
$msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text;
$msg .= "Running for $pretty_uptime. " if $opt_f;
if ( $opt_s ) {
@@ -167,6 +178,7 @@ sub process_arguments(){
"c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number
"f" => \$opt_f, "for" => \$opt_f, # show "running for ..."
"s" => \$opt_s, "since" => \$opt_s, # show "running since ..."
+ "d" => \$opt_d, "days" => \$opt_d, # report uptime in days
);
if ($opt_V) {
@@ -262,6 +274,7 @@ sub print_help () {
print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n";
print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n";
print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n";
+ print "-d (--days) = Show uptime in days\n";
print "-h (--help)\n";
print "-V (--version)\n";
print "-v (--verbose) = debugging output\n";