From 96f5d993d8eff32958e55fe8b3c74cf26e064d2b Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 28 Jul 2010 11:21:57 +0200 Subject: Add -g/--hostgroup option (show all hosts in a group) --- bin/icli | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/icli b/bin/icli index 24c755b..0248e47 100755 --- a/bin/icli +++ b/bin/icli @@ -14,7 +14,7 @@ my $context; my $colours = 1; my $short = 0; my $list_type = 's'; -my (@for_hosts); +my (@for_hosts, @for_groups); sub have_host { my ($host) = @_; @@ -39,13 +39,13 @@ sub with_colour { sub read_objects_line { my ($line, $ref) = @_; - if ($line =~ / ^ (? \w+) \s+ { /x) { + if ($line =~ / ^ (?:define \s )? (? \w+) \s+ { /x) { $context = $+{context}; } - elsif ($line =~ / ^ \t* (? [^=]+ ) = (? .*) $ /x) { + elsif ($line =~ / ^ \t (? [^=\t]+ ) [=\t] (? .*) $ /x) { $cache->{$+{key}} = $+{value}; } - elsif ($line =~ / ^ \t* } \s* $ /x) { + elsif ($line =~ / ^ \t } $ /x) { given($context) { when(['info', 'programstatus']) { ${$ref}->{$context} = $cache; @@ -177,14 +177,27 @@ sub display_host { GetOptions( 'C|no-colours' => sub { $colours = 0 }, 'f|status-file=s' => \$status_file, + 'g|hostgroup=s' => sub { push(@for_groups, split(/,/, $_[1])) }, 'h|host=s' => sub { push(@for_hosts, split(/,/, $_[1])) }, 'l|list=s' => sub { $list_type = substr($_[1], 0, 1) }, 's|short' => \$short, ); read_objects($status_file, \$data); +read_objects($config_file, \$config); enhance_status(); +foreach my $group (@for_groups) { + 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); + } + } +} + if (@for_hosts) { foreach my $host (@for_hosts) { if (have_host($host)) { @@ -237,6 +250,10 @@ Disable colours in output Read the status from I instead of the default F +=item B<-g>/B<--hostgroup> I + +Show details for all hosts in I + =item B<-h>/B<--host> I Only show I's services -- cgit v1.2.3