summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-07-26 23:42:53 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-07-26 23:42:53 +0200
commit3ae65767d1fdb5b6d19ef7428ef7b1349791e28a (patch)
tree2adab4d8c398fe89c56a09396faff694e31ee4aa /bin
parent2a8b9578c013a418c9c44234f01b88707e378d08 (diff)
Colors, hierarchical format
Diffstat (limited to 'bin')
-rwxr-xr-xbin/icli34
1 files changed, 19 insertions, 15 deletions
diff --git a/bin/icli b/bin/icli
index caef3c0..c124fd8 100755
--- a/bin/icli
+++ b/bin/icli
@@ -1,8 +1,10 @@
#!/usr/bin/env perl
+use autodie;
use strict;
use warnings;
use 5.010;
-use autodie;
+
+use Term::ANSIColor;
my ($data, $cache);
my $status_file = '/var/lib/icinga/status.dat';
@@ -26,7 +28,7 @@ sub read_status_line {
push(@{$data->{hosts}}, $cache);
}
when('servicestatus') {
- push(@{$data->{services}}, $cache);
+ push(@{$data->{services}->{$cache->{host_name}}}, $cache);
}
when('contactstatus') {
push(@{$data->{contacts}}, $cache);
@@ -51,24 +53,26 @@ sub read_status {
sub state_to_string {
my ($digit) = @_;
given ($digit) {
- when(0) { return 'OK' }
- when(1) { return 'WARNING' }
- when(2) { return 'CRITICAL' }
- when(3) { return 'UNKNOWN' }
- default { return '???' }
+ when(0) { return colored(' OK ', 'black on_green' ) }
+ when(1) { return colored(' WARNING', 'black on_yellow') }
+ when(2) { return colored('CRITICAL', 'white on_red' ) }
+ when(3) { return colored(' UNKNOWN', 'white on_blue' ) }
+ default { return colored(' ??? ', 'white' ) }
}
}
read_status();
-foreach my $s (@{$data->{services}}) {
- printf(
- "%24s/%-20s %s: %s\n",
- $s->{host_name},
- $s->{service_description},
- state_to_string($s->{current_state}),
- $s->{plugin_output},
- );
+foreach my $host (sort keys %{$data->{services}}) {
+ say "\n$host";
+ foreach my $s (@{$data->{services}->{$host}}) {
+ printf(
+ "\t%-20.20s %s %s\n",
+ $s->{service_description},
+ state_to_string($s->{current_state}),
+ $s->{plugin_output},
+ );
+ }
}
__END__