From 0d2f6922f95730d6c667f2e95539c2a999b3d7ee Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 26 Jul 2010 23:55:05 +0200 Subject: Add -h/--host option to only show one host --- bin/icli | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file 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); } } -- cgit v1.2.3