summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-07-28 11:21:57 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-07-28 11:21:58 +0200
commit96f5d993d8eff32958e55fe8b3c74cf26e064d2b (patch)
treefed5dbedacc81af0cee092360649469ac2932572 /bin
parent7376360d518a3ef3fd8de16f7598d142b542b218 (diff)
Add -g/--hostgroup option (show all hosts in a group)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/icli25
1 files 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 =~ / ^ (?<context> \w+) \s+ { /x) {
+ if ($line =~ / ^ (?:define \s )? (?<context> \w+) \s+ { /x) {
$context = $+{context};
}
- elsif ($line =~ / ^ \t* (?<key> [^=]+ ) = (?<value> .*) $ /x) {
+ elsif ($line =~ / ^ \t (?<key> [^=\t]+ ) [=\t] (?<value> .*) $ /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<file> instead of the default
F</var/lib/icinga/status.dat>
+=item B<-g>/B<--hostgroup> I<hostgroup>
+
+Show details for all hosts in I<hostgroup>
+
=item B<-h>/B<--host> I<host>
Only show I<host>'s services