[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: fix 'n' and 'a' notification_options (filter = 0, filter = ...)

git at icinga.org git at icinga.org
Wed Jun 26 14:31:09 CEST 2013


Module: icinga2
Branch: feature/configconvert-2743
Commit: 18e3bdc581fafe5b56ad1d5de9faef7c7798d4de
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=18e3bdc581fafe5b56ad1d5de9faef7c7798d4de

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed Jun 26 14:12:38 2013 +0200

configconvert: fix 'n' and 'a' notification_options (filter = 0, filter = ...)

refs #4060

---

 tools/configconvert/Icinga2/Convert.pm          |    4 ++-
 tools/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 040fe1e..0b81d60 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 6ebe9ad..c5d7fb0 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,");
         }
     }
 





More information about the icinga-checkins mailing list