summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-11-07 21:53:16 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-11-07 21:53:16 +0100
commitf6d467ad0567dd377efd16995294fafd6aef3e71 (patch)
tree5702982ddb07ef9931291c3778883d5b075255c4 /bin
parentaf8ce156b29fbcdfa2c5e80395661d227897f962 (diff)
Unfuck service/host filtering. Might break rescheduling, though.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/icli69
1 files changed, 28 insertions, 41 deletions
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);
}