summaryrefslogtreecommitdiff
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
parent39a23d0ef9bea418d7e3b9be625d593b75628fce (diff)
Add icli -lq to list the scheduling queue
-rwxr-xr-xbin/icli44
-rw-r--r--t/50-icli.t7
-rw-r--r--t/out/list_queue31
3 files changed, 79 insertions, 3 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>
diff --git a/t/50-icli.t b/t/50-icli.t
index 53fe15a..d5a4b65 100644
--- a/t/50-icli.t
+++ b/t/50-icli.t
@@ -3,7 +3,7 @@ use strict;
use warnings;
use 5.010;
-use Test::Command tests => (20*3);
+use Test::Command tests => (21*3);
my $icli = 'bin/icli -f t/in/status.dat -c t/in/objects.cache';
@@ -75,6 +75,11 @@ $cmd->exit_is_num(0);
$cmd->stdout_is_file('t/out/list_services_single');
$cmd->stderr_is_eq($EMPTY);
+$cmd = Test::Command->new(cmd => "$icli -lq");
+$cmd->exit_is_num(0);
+$cmd->stdout_is_file('t/out/list_queue');
+$cmd->stderr_is_eq($EMPTY);
+
$cmd = Test::Command->new(cmd => "$icli -g invalid");
$cmd->exit_isnt_num(0);
diff --git a/t/out/list_queue b/t/out/list_queue
new file mode 100644
index 0000000..4d2d651
--- /dev/null
+++ b/t/out/list_queue
@@ -0,0 +1,31 @@
+Host Service Last Check Next Check
+aneurysm SMTP 2010-07-28 10:43:36 2010-07-28 10:48:36
+aneurysm Disk: /data 2010-07-28 10:43:45 2010-07-28 10:48:45
+steel.derf0.net HTTP 2010-07-28 10:43:53 2010-07-28 10:48:53
+aneurysm Disk: /boot 2010-07-28 10:44:01 2010-07-28 10:49:01
+steel.derf0.net Disk: lv-root 2010-07-28 10:44:44 2010-07-28 10:49:44
+aneurysm Disk: /home 2010-07-28 10:44:56 2010-07-28 10:49:56
+steel.derf0.net SMTP 2010-07-28 10:45:21 2010-07-28 10:50:21
+steel.derf0.net SSH password login d 2010-07-28 10:35:27 2010-07-28 10:50:27
+aneurysm Load 2010-07-28 10:45:31 2010-07-28 10:50:31
+steel.derf0.net Disk: lv-home 2010-07-28 10:45:33 2010-07-28 10:50:33
+steel-vpn 2010-07-28 10:45:26 2010-07-28 10:50:36
+steel-vpn SMTP 2010-07-28 10:45:37 2010-07-28 10:50:37
+aneurysm Processes 2010-07-28 10:45:48 2010-07-28 10:50:48
+steel.derf0.net Processes 2010-07-28 10:45:52 2010-07-28 10:50:52
+alpha HTTP 2010-07-28 10:46:02 2010-07-28 10:51:02
+aneurysm HTTPS 2010-07-28 10:46:06 2010-07-28 10:51:06
+aneurysm Disk: / 2010-07-28 10:46:21 2010-07-28 10:51:21
+steel.derf0.net Mail Queue 2010-07-28 10:46:39 2010-07-28 10:51:39
+steel.derf0.net Users 2010-07-28 10:47:09 2010-07-28 10:52:09
+steel.derf0.net SSH 2010-07-28 10:47:17 2010-07-28 10:52:17
+aneurysm 2010-07-28 10:47:26 2010-07-28 10:52:36
+aneurysm HTTP 2010-07-28 10:48:18 2010-07-28 10:53:18
+steel.derf0.net Load 2010-07-28 10:48:19 2010-07-28 10:53:19
+steel.derf0.net Disk: vda1 2010-07-28 10:48:20 2010-07-28 10:53:20
+steel.derf0.net 2010-07-28 10:48:16 2010-07-28 10:53:26
+aneurysm SSH 2010-07-28 10:48:33 2010-07-28 10:53:33
+alpha 2010-07-28 10:48:26 2010-07-28 10:53:36
+aneurysm SSH password login d 2010-07-28 10:47:48 2010-07-28 11:02:48
+steel.derf0.net Not Blacklisted 2010-07-28 10:28:42 2010-07-28 11:28:42
+steel.derf0.net No open relay 2010-07-28 10:47:00 2010-07-28 11:47:00