From 18e3bdc581fafe5b56ad1d5de9faef7c7798d4de Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 26 Jun 2013 14:12:38 +0200 Subject: [PATCH] configconvert: fix 'n' and 'a' notification_options (filter = 0, filter = ...) refs #4060 --- tools/configconvert/Icinga2/Convert.pm | 4 ++- .../configconvert/Icinga2/ExportIcinga2Cfg.pm | 36 ++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/configconvert/Icinga2/Convert.pm b/tools/configconvert/Icinga2/Convert.pm index 040fe1e35..0b81d602c 100644 --- a/tools/configconvert/Icinga2/Convert.pm +++ b/tools/configconvert/Icinga2/Convert.pm @@ -749,11 +749,13 @@ sub convert_notification_options_to_filter { # verify if there's 'n' (none) or 'a' (all) and ignore the rest then if (grep /n/, @options) { + push @{$filter->{'state'}}, 0; + push @{$filter->{'type'}}, 0; return $filter; } if (grep /a/, @options) { foreach my $by (keys %{$filter_by}) { - push @{$filter->{$by}}, $filter_names->{$by}; + push @{$filter->{$filter_by->{$by}}}, $filter_names->{$by}; } return $filter; } diff --git a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm index 6ebe9ad48..c5d7fb0b2 100644 --- a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm +++ b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm @@ -392,8 +392,13 @@ sub dump_service_2x { #say Dumper($service_2x); foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { next if !@{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - dump_config_line($icinga2_cfg, "\t$notification_filter,"); + my $notification_filter; + if (grep /0/, @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); } } @@ -516,8 +521,13 @@ sub dump_host_2x { if(defined($host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { foreach my $by (keys %{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { next if !@{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - dump_config_line($icinga2_cfg, "\t$notification_filter,"); + my $notification_filter; + if (grep /0/, @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); } } @@ -670,8 +680,13 @@ sub dump_host_2x { if(defined($service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { next if !@{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - dump_config_line($icinga2_cfg, "\t$notification_filter,"); + my $notification_filter; + if (grep /0/, @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); } } @@ -817,8 +832,13 @@ sub dump_user_2x { if(defined($user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { foreach my $by (keys %{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { next if !@{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - dump_config_line($icinga2_cfg, "\t$notification_filter,"); + my $notification_filter; + if (grep /0/, @{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); } }