From e22b73286bbf862090785adf022093dab751f62d Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 29 Jul 2010 23:41:47 +0200 Subject: Add icli -lq to list the scheduling queue --- bin/icli | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/icli b/bin/icli index b8fb7df..4721990 100755 --- a/bin/icli +++ b/bin/icli @@ -4,6 +4,7 @@ use strict; use warnings; use 5.010; +use Date::Format; use Getopt::Long qw/:config bundling/; use Term::ANSIColor; @@ -38,6 +39,11 @@ sub with_colour { } } +sub pretty_date { + my ($unix) = @_; + return time2str('%Y-%m-%d %H:%M:%S', $unix); +} + sub read_objects_line { my ($line, $ref) = @_; @@ -118,6 +124,37 @@ sub host_state { } } +sub display_queue { + my @queue = map { $_->[0] } + sort { $a->[1] <=> $b->[1] } + map { [$_, $_->{next_check}] } + (values %{$data->{hosts}}, + map { @{$_} } values %{$data->{services}}); + + printf( + "%-25.25s %-20.20s %-19s %-19s\n", + 'Host', + 'Service', + 'Last Check', + 'Next Check', + ); + + for my $e (@queue) { + + if ($e->{next_check} == 0) { + next; + } + + printf( + "%-25.25s %-20.20s %-19s %-19s\n", + $e->{host_name}, + $e->{service_description} // q{}, + pretty_date($e->{last_check}), + pretty_date($e->{next_check}), + ); + } +} + sub display_service { my ($s) = @_; printf( @@ -225,6 +262,9 @@ elsif ($list_type eq 'h') { display_host($host, 1); } } +elsif ($list_type eq 'q') { + display_queue(); +} else { die("See perldoc -F $0\n"); } @@ -270,11 +310,11 @@ Show details for all hosts in I Only show I's services -=item B<-l>|B<--list> B|B +=item B<-l>|B<--list> B|B|B List either services (the default) or hosts. Note that only the first character of the argument is checked, so C<< icli --lh >> and C<< icli -ls >> are also fine. +-lh >>, C<< icli -ls >> etc. are also fine. =item B<-s>|B<--short> -- cgit v1.2.3