diff options
-rwxr-xr-x | bin/icli | 69 |
1 files changed, 28 insertions, 41 deletions
@@ -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); } |