summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-07-29 23:41:47 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-07-29 23:41:47 +0200
commite22b73286bbf862090785adf022093dab751f62d (patch)
tree3cef67a9a7c4a824a6f29c2d09aef07ddff319cc /bin
parent39a23d0ef9bea418d7e3b9be625d593b75628fce (diff)
Add icli -lq to list the scheduling queue
Diffstat (limited to 'bin')
-rwxr-xr-xbin/icli44
1 files changed, 42 insertions, 2 deletions
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<hostgroup>
Only show I<host>'s services
-=item B<-l>|B<--list> B<hosts>|B<services>
+=item B<-l>|B<--list> B<hosts>|B<services>|B<queue>
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>