summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_uptime.pl
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-03-10 10:33:25 (GMT)
committerGitHub <noreply@github.com>2023-03-10 10:33:25 (GMT)
commit5077120a251980b4fafed61b4aa8fa5730a85443 (patch)
tree8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /plugins-scripts/check_uptime.pl
parenta3de84594104ac87a91e200d569fb57edacca928 (diff)
parent269718094177fb8a7e3d3005d1310495009fe8c4 (diff)
downloadmonitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz
Merge branch 'master' into master
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 4c9f22d..f954287 100755
--- a/plugins-scripts/check_uptime.pl
+++ b/plugins-scripts/check_uptime.pl
@@ -25,7 +25,7 @@ use POSIX;
25use strict; 25use strict;
26use Getopt::Long; 26use Getopt::Long;
27use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c 27use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c
28 $opt_f $opt_s 28 $opt_f $opt_s $opt_d
29 $lower_warn_threshold $upper_warn_threshold 29 $lower_warn_threshold $upper_warn_threshold
30 $lower_crit_threshold $upper_crit_threshold 30 $lower_crit_threshold $upper_crit_threshold
31 $status $state $msg); 31 $status $state $msg);
@@ -137,9 +137,20 @@ if ( $uptime_seconds > $upper_crit_threshold ) {
137 $state_str = "OK"; 137 $state_str = "OK";
138} 138}
139 139
140# Prepare uptime value (seconds or days)
141my $uptime_text = "";
142my $uptime_unit = "";
143if ( $opt_d ) {
144 $uptime_text = floor($uptime_seconds / 60 / 60 / 24);
145 $uptime_unit = "days";
146} else {
147 $uptime_text = $uptime_seconds;
148 $uptime_unit = "seconds";
149}
150
140$msg = "$state_str: "; 151$msg = "$state_str: ";
141 152
142$msg .= "uptime is $uptime_seconds seconds. "; 153$msg .= "Uptime is $uptime_text $uptime_unit. ";
143$msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text; 154$msg .= "Exceeds $out_of_bounds_text threshold. " if $out_of_bounds_text;
144$msg .= "Running for $pretty_uptime. " if $opt_f; 155$msg .= "Running for $pretty_uptime. " if $opt_f;
145if ( $opt_s ) { 156if ( $opt_s ) {
@@ -167,6 +178,7 @@ sub process_arguments(){
167 "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number 178 "c=s" => \$opt_c, "critical=s" => \$opt_c, # critical if above this number
168 "f" => \$opt_f, "for" => \$opt_f, # show "running for ..." 179 "f" => \$opt_f, "for" => \$opt_f, # show "running for ..."
169 "s" => \$opt_s, "since" => \$opt_s, # show "running since ..." 180 "s" => \$opt_s, "since" => \$opt_s, # show "running since ..."
181 "d" => \$opt_d, "days" => \$opt_d, # report uptime in days
170 ); 182 );
171 183
172 if ($opt_V) { 184 if ($opt_V) {
@@ -262,6 +274,7 @@ sub print_help () {
262 print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n"; 274 print "-c (--critical) = Min. number of uptime to generate critical alert ( w < c )\n";
263 print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n"; 275 print "-f (--for) = Show uptime in a pretty format (Running for x weeks, x days, ...)\n";
264 print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n"; 276 print "-s (--since) = Show last boot in yyyy-mm-dd HH:MM:SS format (output from 'uptime -s')\n";
277 print "-d (--days) = Show uptime in days\n";
265 print "-h (--help)\n"; 278 print "-h (--help)\n";
266 print "-V (--version)\n"; 279 print "-V (--version)\n";
267 print "-v (--verbose) = debugging output\n"; 280 print "-v (--verbose) = debugging output\n";