[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: fix timeperiod ranges, add template support for ITL inherits

git at icinga.org git at icinga.org
Thu May 2 22:17:33 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu May  2 22:13:11 2013 +0200

configconvert: fix timeperiod ranges, add template support for ITL inherits

refs #4037
refs #4013

---

 contrib/configconvert/Icinga2/Convert.pm          |    4 +++
 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |   22 ++++++++++++++++++--
 contrib/configconvert/icinga2_convert_v1_v2.pl    |    2 +-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 5fd9dc3..d6623fb 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1137,6 +1137,10 @@ sub convert_2x {
         # clone it into our hash
         $cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key} = dclone(@$cfg_obj_1x{'timeperiod'}->{$timeperiod_obj_1x_key});
 
+        # add dependency to ITL template to objects
+        push @{$cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key}->{'__I2CONVERT_TEMPLATE_NAMES'}}, $icinga2_cfg->{'itl'}->{'timeperiod-template'};
+        $cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key}->{'__I2CONVERT_USES_TEMPLATE'} = 1;
+
         ####################################################
         # display_name -> alias mapping
         ####################################################
diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index 7bd38ec..ac5eabb 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -705,18 +705,32 @@ sub dump_notification_2x {
 
 sub dump_timeperiod_2x {
     my $icinga2_cfg = shift;
+    my $object_type = "object"; # object or template
     my $timeperiod_2x = shift;
     my $timeperiod_name = $timeperiod_2x->{'timeperiod_name'};
 
     #say Dumper($timeperiod_2x);
 
-    dump_config_line($icinga2_cfg, "object Timeperiod \"$timeperiod_name\" {");
+    if ($timeperiod_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
+        $object_type = "template";
+        $timeperiod_name = $timeperiod_2x->{'__I2CONVERT_TEMPLATE_NAME'};
+    }
+
+    # if this is a _template_ we need to use 'name' instead of 'host_name'
+    if (defined($timeperiod_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $timeperiod_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
+        my $timeperiod_2x_templates = join '", "', @{$timeperiod_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
+        dump_config_line($icinga2_cfg, "$object_type Timeperiod \"$timeperiod_name\" inherits \"$timeperiod_2x_templates\" {");
+    } else {
+        dump_config_line($icinga2_cfg, "$object_type Timeperiod \"$timeperiod_name\" {");
+    }
 
     # display_name is seperated at first position
     if(defined($timeperiod_2x->{'display_name'})) {
-        dump_config_line($icinga2_cfg, "\tdisplay_name \t= \"$timeperiod_2x->{'display_name'}\",");
+        dump_config_line($icinga2_cfg, "\tdisplay_name = \"$timeperiod_2x->{'display_name'}\",");
     }
 
+    dump_config_line($icinga2_cfg, "\tranges = {");
+
     # dump all possible keys (there's no fixed string attr here)
     foreach my $key (sort (keys %{$timeperiod_2x})) {
         if ($key !~ /__I2CONVERT/ &&
@@ -726,9 +740,11 @@ sub dump_timeperiod_2x {
             $key ne 'display_name' &&
             $key ne 'use'
         ) {
-            dump_config_line($icinga2_cfg, "\t\"$key\" \t= \"$timeperiod_2x->{$key}\",");
+            dump_config_line($icinga2_cfg, "\t\t\"$key\" \t= \"$timeperiod_2x->{$key}\",");
         }
     }
+
+    dump_config_line($icinga2_cfg, "\t},");
     dump_config_line($icinga2_cfg, "");
     dump_config_line($icinga2_cfg, "}");
     dump_config_line($icinga2_cfg, "\n");
diff --git a/contrib/configconvert/icinga2_convert_v1_v2.pl b/contrib/configconvert/icinga2_convert_v1_v2.pl
index a375f9b..3c582bf 100644
--- a/contrib/configconvert/icinga2_convert_v1_v2.pl
+++ b/contrib/configconvert/icinga2_convert_v1_v2.pl
@@ -53,7 +53,7 @@ $icinga2_cfg->{'itl'}->{'host-template'} = "";
 $icinga2_cfg->{'itl'}->{'service-template'} = "plugin-service";
 $icinga2_cfg->{'itl'}->{'user-template'} = "";
 $icinga2_cfg->{'itl'}->{'notification-template'} = "plugin-notification";
-$icinga2_cfg->{'itl'}->{'timeperiod-template'} = "";
+$icinga2_cfg->{'itl'}->{'timeperiod-template'} = "legacy-timeperiod";
 
 
 my $verbose = 1;





More information about the icinga-checkins mailing list