diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2010-07-27 00:09:45 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2010-07-27 00:09:45 +0200 |
commit | 0aaa43fc4e1edc46699b8b3820a959a34798cfa6 (patch) | |
tree | 5c7ce777dd76eae92500621c5d1fffbd4ce908e5 /bin | |
parent | 159a8a91af3161e21df247acd724bd5ed1a89a61 (diff) |
Add option to disable coloured output
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/icli | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -10,8 +10,20 @@ use Term::ANSIColor; my ($data, $cache); my $status_file = '/var/lib/icinga/status.dat'; my $context; +my $colours = 1; my ($for_host); + +sub with_colour { + my ($text, $colour) = @_; + if ($colours) { + return colored($text, $colour); + } + else { + return $text; + } +} + sub read_status_line { my ($line) = @_; @@ -55,11 +67,11 @@ sub read_status { sub state_to_string { my ($digit) = @_; given ($digit) { - 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' ) } + when(0) { return with_colour(' OK ', 'black on_green' ) } + when(1) { return with_colour(' WARNING', 'black on_yellow') } + when(2) { return with_colour('CRITICAL', 'white on_red' ) } + when(3) { return with_colour(' UNKNOWN', 'white on_blue' ) } + default { return with_colour(' ??? ', 'white' ) } } } @@ -91,7 +103,8 @@ sub display_host { } GetOptions( - 'h|host=s' => \$for_host, + 'C|no-colours' => sub { $colours = 0 }, + 'h|host=s' => \$for_host, ); read_status(); @@ -129,7 +142,11 @@ services and their states. =over -=item B<-h> I<host> +=item B<-C>/B<--no-colours> + +Disable colours in output + +=item B<-h>/B<--host> I<host> Only show I<host>'s services |