Title: [opsview] [11583] Pretty print the total uptime.
- Revision
- 11583
- Author
- pknight
- Date
- 2013-02-25 12:09:40 +0000 (Mon, 25 Feb 2013)
Log Message
Pretty print the total uptime.
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_uptime
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_uptime 2013-02-25 06:20:13 UTC (rev 11582)
+++ trunk/opsview-core/nagios-plugins/check_snmp_uptime 2013-02-25 12:09:40 UTC (rev 11583)
@@ -91,8 +91,8 @@
require Opsview::Externalcommand;
my $cmd = Opsview::Externalcommand->new(
command => 'PROCESS_SERVICE_CHECK_RESULT',
- args =>
- join( ';', $np->opts->hosttitle, 'Uptime', '1', 'Uptime reset' ),
+ args => join( ';',
+ $np->opts->hosttitle, 'Uptime', '1', nice_ticks($timeticks) ),
);
$cmd->send_to_master;
}
@@ -222,3 +222,47 @@
print $statusfile_fh "$cur_uptime,$rolled_over_flag\n";
close $statusfile_fh;
}
+
+# Returns a human readable length of time string for timeticks.
+sub nice_ticks {
+ my $ticks = shift;
+
+ my @time_parts;
+ my $ticks_in_a_second = 100;
+ my $ticks_in_a_minute = $ticks_in_a_second * 60;
+ my $ticks_in_an_hour = $ticks_in_a_minute * 60;
+ my $ticks_in_a_day = $ticks_in_an_hour * 24;
+
+ if ( $ticks >= $ticks_in_a_day ) {
+ my $total_days = $ticks / 100 / 60 / 60 / 24;
+ my $rounded_days = sprintf( '%d', $total_days );
+ push @time_parts,
+ $rounded_days . ( $rounded_days > 1 ? ' days' : ' day' );
+ $ticks -= ( $rounded_days * $ticks_in_a_day );
+ }
+
+ if ( $ticks >= $ticks_in_an_hour ) {
+ my $total_hours = $ticks / 100 / 60 / 60;
+ my $rounded_hours = sprintf( '%d', $total_hours );
+ push @time_parts,
+ $rounded_hours . ( $rounded_hours > 1 ? ' hours' : 'hour' );
+ $ticks -= ( $rounded_hours * $ticks_in_an_hour );
+ }
+
+ if ( $ticks >= $ticks_in_a_minute ) {
+ my $total_minutes = $ticks / 100 / 60;
+ my $rounded_minutes = sprintf( '%d', $total_minutes );
+ push @time_parts,
+ $rounded_minutes . ( $rounded_minutes > 1 ? ' minutes' : ' minute' );
+ $ticks -= ( $rounded_minutes * $ticks_in_a_minute );
+ }
+
+ if ( $ticks >= $ticks_in_a_second ) {
+ my $total_seconds = $ticks / 100;
+ my $rounded_seconds = sprintf( '%d', $total_seconds );
+ push @time_parts,
+ $rounded_seconds . ( $rounded_seconds > 1 ? ' seconds' : ' second' );
+ }
+
+ return join( ', ', @time_parts );
+}
_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins