summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-07-27 00:09:45 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-07-27 00:09:45 +0200
commit0aaa43fc4e1edc46699b8b3820a959a34798cfa6 (patch)
tree5c7ce777dd76eae92500621c5d1fffbd4ce908e5
parent159a8a91af3161e21df247acd724bd5ed1a89a61 (diff)
Add option to disable coloured output
-rwxr-xr-xbin/icli31
1 files changed, 24 insertions, 7 deletions
diff --git a/bin/icli b/bin/icli
index 0d1ea4e..869bc9d 100755
--- a/bin/icli
+++ b/bin/icli
@@ -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