From f6d467ad0567dd377efd16995294fafd6aef3e71 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 7 Nov 2010 21:53:16 +0100 Subject: Unfuck service/host filtering. Might break rescheduling, though. --- bin/icli | 69 ++++++++++++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 41 deletions(-) (limited to 'bin') diff --git a/bin/icli b/bin/icli index 1151a80..e65e4b9 100755 --- a/bin/icli +++ b/bin/icli @@ -22,7 +22,7 @@ my $short = 0; my $list_type = 's'; my $verbosity = 1; my $recheck = 0; -my (@for_hosts, @for_groups, @for_services); +my (@for_hosts, @for_groups, @for_services, @list_hosts, @list_services); sub have_host { my ($host) = @_; @@ -359,41 +359,37 @@ read_objects($status_file, \$data); read_objects($config_file, \$config); enhance_status(); +foreach my $host (@for_hosts) { + if (not exists $data->{services}->{$host}) { + die("Unknown host: ${host}\n"); + } +} + +@list_hosts = @for_hosts; +@list_services = @for_services; + foreach my $group (@for_groups) { - if (not exists $config->{hostgroups}->{$group}) { - die("Unknown hostgroup: $group\n"); + if (not exists $config->{'hostgroups'}->{$group}) { + die("Unknown hostgroup: ${group}\n"); } - foreach my $host (split(/,/, $config->{hostgroups}->{$group}->{members})) { - if (not grep { $_ eq $host } @for_hosts) { - push(@for_hosts, $host); + foreach my $host (split/,/, $config->{'hostgroups'}->{$group}->{'members'}) { + if (not grep { $_ eq $host } @list_hosts) { + push(@list_hosts, $host); } } } -if (@for_hosts and $list_type ~~ [qw/s h/]) { - foreach my $host (@for_hosts) { - if (have_host($host)) { - display_host( - $host, - ( @for_hosts > 1), - ); - } - else { - die("Unknown host: $host\n"); - } - } +if (@list_hosts == 0) { + @list_hosts = sort keys %{$data->{services}}; } -elsif ($list_type eq 's') { - foreach my $host (sort keys %{$data->{services}}) { - if (not (@for_services and not have_service_multi($host, - @for_services))) { - display_host($host, 1); - } - } + +if (@list_services) { + @list_hosts = grep { have_service_multi($_, @list_services) } @list_hosts; } -elsif ($list_type eq 'h') { - foreach my $host (sort keys %{$data->{hosts}}) { - display_host($host, 1); + +if ($list_type ~~ [qw[s h]]) { + foreach my $host (@list_hosts) { + display_host($host, (@list_hosts > 1)); } } elsif ($list_type eq 'q') { @@ -405,20 +401,11 @@ elsif ($list_type eq 'd') { } } elsif ($recheck) { - if (@for_hosts) { - foreach my $host (@for_hosts) { - if (have_host($host) and not @for_services) { - recheck_host_all($host); - } - elsif (have_host($host)) { - foreach my $service (@for_services) { - recheck_service($host, $service); - } - } + foreach my $host (@list_hosts) { + if (not @list_services) { + recheck_host_all($host); } - } - else { - foreach my $host (sort keys %{$data->{services}}) { + else { foreach my $service (@for_services) { recheck_service($host, $service); } -- cgit v1.2.3