From bf9f682bc5cc6d6133dbe539f81fa7962b7a9857 Mon Sep 17 00:00:00 2001 From: Reik Keutterling Date: Fri, 31 May 2013 23:09:01 +0200 Subject: [PATCH 1/4] Ignore serviceescalation field in the icinga status.dat --- Changelog | 1 + bin/icli | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 99bd586..2a13f96 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ git HEAD * Fix --filter N and --filter !N + * Ignore 'serviceescalation' field in the icinga status file icli 0.44 - Sat Mar 16 2013 diff --git a/bin/icli b/bin/icli index b633141..62fc194 100755 --- a/bin/icli +++ b/bin/icli @@ -369,7 +369,7 @@ sub read_objects_line { [ qw[ timeperiod command contactgroup contact host service - servicedependency module + servicedependency serviceescalation module ] ] ) From 035f6631b0dc3cc4546c6361908ac4964d2ed768 Mon Sep 17 00:00:00 2001 From: Reik Keutterling Date: Sat, 1 Jun 2013 00:27:36 +0200 Subject: [PATCH 2/4] Add -n / --notifications option to enable/disable all notifications --- Changelog | 1 + bin/icli | 62 ++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Changelog b/Changelog index 2a13f96..e7de344 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ git HEAD * Fix --filter N and --filter !N * Ignore 'serviceescalation' field in the icinga status file + * Add -n / --notifications option to enable/disable all notifications icli 0.44 - Sat Mar 16 2013 diff --git a/bin/icli b/bin/icli index 62fc194..8d72dcd 100755 --- a/bin/icli +++ b/bin/icli @@ -27,6 +27,7 @@ my $verbosity = 1; my $overview = 0; my $recheck = 0; my $force_recheck = 0; +my $notifications = undef; my $match_output = undef; my $acknowledge = undef; my $as_contact = undef; @@ -230,8 +231,6 @@ sub filter_generic { or ( $f eq '!D' and not check_is_host_down($x) ) or ( $f eq 'F' and $x->{'is_flapping'} ) or ( $f eq '!F' and not $x->{'is_flapping'} ) - or ( $f eq 'N' and not $x->{'notifications_enabled'} ) - or ( $f eq '!N' and $x->{'notifications_enabled'} ) or ( $f eq 'P' and $x->{'passive_checks_enabled'} and not $x->{'active_checks_enabled'} ) @@ -369,7 +368,7 @@ sub read_objects_line { [ qw[ timeperiod command contactgroup contact host service - servicedependency serviceescalation module + servicedependency module serviceescalation ] ] ) @@ -864,6 +863,16 @@ sub acknowledge_service { say "Acknowledged $host/$service: $acknowledge"; } +sub disable_notifications { + dispatch_command( 'DISABLE_NOTIFICATIONS', time() ); + say "Temporarily disabled all notifications"; +} + +sub enable_notifications { + dispatch_command( 'ENABLE_NOTIFICATIONS', time() ); + say "Temporarily enabled all notifications"; +} + sub action_on_host { my ($h) = @_; @@ -891,24 +900,25 @@ sub action_on_service { } GetOptions( - 'a|acknowledge=s' => sub { $acknowledge = $_[1]; $list_type = q{} }, - 'c|config=s' => \$config_file, - 'C|no-colours' => sub { $colours = 0 }, - 'f|status-file=s' => \$status_file, - 'F|rw-file=s' => \$rw_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 ) }, - 'm|match=s' => sub { $match_output = qr{$_[1]}i }, - 'o|overview' => \$overview, - 'r|recheck' => sub { $recheck = 1; $list_type = q{} }, - 's|service=s' => sub { push( @for_services, split( /,/, $_[1] ) ) }, - 'u|force-recheck' => sub { $force_recheck = 1; $list_type = q{} }, - 'U|as-contact=s' => \$as_contact, - 'v|verbose+' => \$verbosity, - 'V|version' => sub { say "icli version $VERSION"; exit 0 }, - 'x|cut-mode=s' => sub { $cut_mode = substr( $_[1], 0, 1 ) }, - 'z|filter=s' => sub { push( @filters, split( /,/, $_[1] ) ) }, + 'a|acknowledge=s' => sub { $acknowledge = $_[1]; $list_type = q{} }, + 'c|config=s' => \$config_file, + 'C|no-colours' => sub { $colours = 0 }, + 'f|status-file=s' => \$status_file, + 'F|rw-file=s' => \$rw_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 ) }, + 'm|match=s' => sub { $match_output = qr{$_[1]}i }, + 'n|notifications=s' => sub { $notifications = $_[1]; $list_type = q{} }, + 'o|overview' => \$overview, + 'r|recheck' => sub { $recheck = 1; $list_type = q{} }, + 's|service=s' => sub { push( @for_services, split( /,/, $_[1] ) ) }, + 'u|force-recheck' => sub { $force_recheck = 1; $list_type = q{} }, + 'U|as-contact=s' => \$as_contact, + 'v|verbose+' => \$verbosity, + 'V|version' => sub { say "icli version $VERSION"; exit 0 }, + 'x|cut-mode=s' => sub { $cut_mode = substr( $_[1], 0, 1 ) }, + 'z|filter=s' => sub { push( @filters, split( /,/, $_[1] ) ) }, ) or die("Please see perldoc -F $0 for help\n"); read_objects( $status_file, \$data ); @@ -1003,6 +1013,12 @@ elsif ( $recheck or $acknowledge ) { } } } +elsif ( $notifications eq 'off' ) { + disable_notifications(); +} +elsif ( $notifications eq 'on' ) { + enable_notifications(); +} else { die("See perldoc -F $0\n"); } @@ -1091,6 +1107,10 @@ Note that only the first character of the argument is checked, so C<< icli Limit selection to hosts/services whose plugin output matches I (perl regular expression, case insensitive. see L). +=item B<-n>|B<--notifications> I + +Enable or disable all notifications completely + =item B<-o>|B<--overview> Display "tactical overview"-style overview. From dd0adaee429f6d38f435753830b6d7923fc8c62d Mon Sep 17 00:00:00 2001 From: Reik Keutterling Date: Sat, 1 Jun 2013 00:29:23 +0200 Subject: [PATCH 3/4] cosmetic change --- bin/icli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/icli b/bin/icli index 8d72dcd..2886362 100755 --- a/bin/icli +++ b/bin/icli @@ -368,7 +368,7 @@ sub read_objects_line { [ qw[ timeperiod command contactgroup contact host service - servicedependency module serviceescalation + servicedependency serviceescalation module ] ] ) From f286c13c8aa177546c46b63487082f6da4cbcd61 Mon Sep 17 00:00:00 2001 From: Reik Keutterling Date: Sat, 1 Jun 2013 00:51:01 +0200 Subject: [PATCH 4/4] readded Fix -zN and -z!N not working --- bin/icli | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/icli b/bin/icli index 2886362..32734c0 100755 --- a/bin/icli +++ b/bin/icli @@ -231,6 +231,8 @@ sub filter_generic { or ( $f eq '!D' and not check_is_host_down($x) ) or ( $f eq 'F' and $x->{'is_flapping'} ) or ( $f eq '!F' and not $x->{'is_flapping'} ) + or ( $f eq 'N' and not $x->{'notifications_enabled'} ) + or ( $f eq '!N' and $x->{'notifications_enabled'} ) or ( $f eq 'P' and $x->{'passive_checks_enabled'} and not $x->{'active_checks_enabled'} )