[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: dump modular timperiod attr and values

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


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue Apr 30 14:04:49 2013 +0200

configconvert: dump modular timperiod attr and values

we need to ignore all other attributes which are to be cleaned sooner,
just for safety.

minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.

fixes #4013

---

 contrib/configconvert/Icinga2/Convert.pm          |   10 ++++++++++
 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |   17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 2b7b29c..2d671e4 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1039,6 +1039,16 @@ sub convert_2x {
         my $obj_1x_timeperiod = @$cfg_obj_1x{'timeperiod'}->{$timeperiod_obj_1x_key};
         # clone it into our hash
         $cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key} = dclone(@$cfg_obj_1x{'timeperiod'}->{$timeperiod_obj_1x_key});
+
+        ####################################################
+        # display_name -> alias mapping
+        ####################################################
+        # if there was a timeperiod alias defined, make this the primary display_name for 2x
+        if(defined($obj_1x_timeperiod->{'alias'})) {
+            $cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key}->{'display_name'} = $obj_1x_timeperiod->{'alias'};
+            delete($cfg_obj_2x->{'timeperiod'}->{$timeperiod_obj_1x_key}->{'alias'});
+        }
+
     }
 
     ######################################
diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index 58b55b6..17e701e 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -397,8 +397,23 @@ sub dump_timeperiod_2x {
     #say Dumper($timeperiod_2x);
 
     dump_config_line($icinga2_cfg, "object Timeperiod \"$timeperiod_name\" {");
+
+    # display_name is seperated at first position
     if(defined($timeperiod_2x->{'display_name'})) {
-        dump_config_line($icinga2_cfg, "\tdisplay_name = \"$timeperiod_2x->{'display_name'}\",");
+        dump_config_line($icinga2_cfg, "\tdisplay_name \t= \"$timeperiod_2x->{'display_name'}\",");
+    }
+
+    # dump all possible keys (there's no fixed string attr here)
+    foreach my $key (sort (keys %{$timeperiod_2x})) {
+        if ($key !~ /__I2CONVERT/ &&
+            $key ne 'alias' &&
+            $key ne 'name' &&
+            $key ne 'timeperiod_name' &&
+            $key ne 'display_name' &&
+            $key ne 'use'
+        ) {
+            dump_config_line($icinga2_cfg, "\t\"$key\" \t= \"$timeperiod_2x->{$key}\",");
+        }
     }
     dump_config_line($icinga2_cfg, "");
     dump_config_line($icinga2_cfg, "}");





More information about the icinga-checkins mailing list