From 3ae65767d1fdb5b6d19ef7428ef7b1349791e28a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 26 Jul 2010 23:42:53 +0200 Subject: Colors, hierarchical format --- bin/icli | 34 +++++++++++++++++++--------------- 1 file 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__ -- cgit v1.2.3