From 416a6fedf5feebc6c8d27f22ef828419fd365609 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 18 Nov 2010 23:02:57 +0100 Subject: Replace $short handling with generic filter (so far only for services) --- bin/icli | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'bin') diff --git a/bin/icli b/bin/icli index 1ca9efb..630c986 100755 --- a/bin/icli +++ b/bin/icli @@ -72,6 +72,21 @@ sub pretty_date { return time2str('%Y-%m-%d %H:%M:%S', $unix); } +sub filter_service { + my ($s) = @_; + + if ($short and not $s->{'current_state'}) { + return 0; + } + + if (@list_services and not ($s->{'service_description'} ~~ + [@list_services])) { + return 0; + } + + return 1; +} + sub read_objects_line { my ($line, $ref) = @_; @@ -282,20 +297,15 @@ sub display_service { sub display_host_services { my ($host, $all) = @_; + my @services; + + @services = grep { filter_service($_) } @{$data->{'services'}->{$host}}; - if ($all and (not $short or $extra->{$host}->{service_problem})) { + if ($all and @services) { say "\n$host"; } - foreach my $service (@{$data->{services}->{$host}}) { - - if ( - ($short and not $service->{current_state}) - or (@list_services and not - ($service->{service_description} ~~ [@list_services]) - )) { - next; - } + foreach my $service (@services) { if ($all) { print "\t"; -- cgit v1.2.3