summaryrefslogtreecommitdiff
path: root/bin/icli
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-07-26 23:55:05 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-07-26 23:55:05 +0200
commit0d2f6922f95730d6c667f2e95539c2a999b3d7ee (patch)
tree3ed6e989a1b073064a78622dfdc5faf5a9b370cc /bin/icli
parent3ae65767d1fdb5b6d19ef7428ef7b1349791e28a (diff)
Add -h/--host option to only show one host
Diffstat (limited to 'bin/icli')
-rwxr-xr-xbin/icli53
1 files changed, 44 insertions, 9 deletions
diff --git a/bin/icli b/bin/icli
index c124fd8..0489f8c 100755
--- a/bin/icli
+++ b/bin/icli
@@ -4,11 +4,13 @@ use strict;
use warnings;
use 5.010;
+use Getopt::Long;
use Term::ANSIColor;
my ($data, $cache);
my $status_file = '/var/lib/icinga/status.dat';
my $context;
+my ($for_host);
sub read_status_line {
my ($line) = @_;
@@ -61,17 +63,50 @@ sub state_to_string {
}
}
+sub display_service {
+ my ($s) = @_;
+ printf(
+ "%-20.20s %s %s\n",
+ $s->{service_description},
+ state_to_string($s->{current_state}),
+ $s->{plugin_output},
+ );
+}
+
+sub display_host {
+ my ($host, $all) = @_;
+
+ if ($all) {
+ say "\n$host";
+ }
+
+ foreach my $service (@{$data->{services}->{$host}}) {
+
+ if ($all) {
+ print "\t";
+ }
+
+ display_service($service);
+ }
+}
+
+GetOptions(
+ 'h|host=s' => \$for_host,
+);
+
read_status();
-foreach my $host (sort keys %{$data->{services}}) {
- say "\n$host";
- foreach my $s (@{$data->{services}->{$host}}) {
- printf(
- "\t%-20.20s %s %s\n",
- $s->{service_description},
- state_to_string($s->{current_state}),
- $s->{plugin_output},
- );
+if ($for_host) {
+ if (exists $data->{services}->{$for_host}) {
+ display_host($for_host, 0);
+ }
+ else {
+ die("Unknown host: $for_host (You need to use the Alias name)\n");
+ }
+}
+else {
+ foreach my $host (sort keys %{$data->{services}}) {
+ display_host($host, 1);
}
}