[icinga-checkins] icinga.org: icinga2/master: configconvert: treat address* and other attributes directly as macros

git at icinga.org git at icinga.org
Mon Jun 24 17:04:16 CEST 2013


Module: icinga2
Branch: master
Commit: a5355e63a3f718b4d3cc6fe36ef4d1079be158aa
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a5355e63a3f718b4d3cc6fe36ef4d1079be158aa

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Mon Jun 24 17:03:34 2013 +0200

configconvert: treat address* and other attributes directly as macros

also for user attributes.

fixes #4333

---

 tools/configconvert/Icinga2/Convert.pm          |   29 +++++++++++++++++++-
 tools/configconvert/Icinga2/ExportIcinga2Cfg.pm |   34 +++++++++++++++++-----
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/tools/configconvert/Icinga2/Convert.pm b/tools/configconvert/Icinga2/Convert.pm
index 8c6ddc7..cbfe2b4 100644
--- a/tools/configconvert/Icinga2/Convert.pm
+++ b/tools/configconvert/Icinga2/Convert.pm
@@ -920,7 +920,7 @@ sub convert_2x {
             # XXX make sure to always add the service specific command arguments, since we have a n .. 1 relation here
             # add the command macros to the command 2x object
             if(defined($service_check_command_2x->{'command_macros'})) {
-                @$cfg_obj_2x{'service'}->{$service_cnt}->{command_macros} = dclone($service_check_command_2x->{'command_macros'});
+                @$cfg_obj_2x{'service'}->{$service_cnt}->{'__I2CONVERT_MACROS'} = dclone($service_check_command_2x->{'command_macros'});
             }
 
             # our PK
@@ -1006,6 +1006,16 @@ sub convert_2x {
         ####################################################
 
         ##########################################
+        # macros (address*, etc)  
+        ##########################################
+        if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address'})) {
+            $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'address'} = $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address'};
+        }
+        if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address6'})) {
+            $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'address6'} = $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address6'};
+        }
+
+        ##########################################
         # escape strings in attributes
         ##########################################
         if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'action_url'})) {
@@ -1161,6 +1171,22 @@ sub convert_2x {
         # set our own __I2CONVERT_TYPE
         $cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'__I2CONVERT_TYPE'} = "user";
 
+        ##########################################
+        # macros (email, pager, address1..6)  
+        ##########################################
+        if(defined($obj_1x_contact->{'email'})) {
+            $cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'email'} = $obj_1x_contact->{'email'};
+        }
+        if(defined($obj_1x_contact->{'pager'})) {
+            $cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'pager'} = $obj_1x_contact->{'pager'};
+        }
+        for(my $i=1;$i<=6;$i++) {
+            my $address = "address$i";
+            if(defined($obj_1x_contact->{$address})) {
+                $cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'__I2CONVERT_MACROS'}->{$address} = $obj_1x_contact->{$address};
+            }
+        }
+
         ####################################################
         # migrate renamed attributes
         ####################################################
@@ -1183,6 +1209,7 @@ sub convert_2x {
             #print "DEBUG: usergroups " . join (" ", @{$cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'usergroups'}});
         }
 
+
         # we need to rebuild that notification logic entirely for 2.x
         # do that later when all objects are processed and prepared (all relations?)
         #say Dumper($notification_commands_2x);
diff --git a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm
index 7b671f8..52e8116 100644
--- a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -277,10 +277,10 @@ sub dump_service_2x {
     # macros
     ####################################################
 
-    if(defined($service_2x->{'command_macros'}) && $service_2x->{'command_macros'} != 0) {
+    if(defined($service_2x->{'__I2CONVERT_MACROS'}) && $service_2x->{'__I2CONVERT_MACROS'} != 0) {
         dump_config_line($icinga2_cfg, "\tmacros = {");
-        foreach my $cmd_arg (keys %{$service_2x->{'command_macros'}}) {
-            dump_config_line($icinga2_cfg, "\t\t$cmd_arg = \"$service_2x->{'command_macros'}->{$cmd_arg}\",");
+        foreach my $macro_key (keys %{$service_2x->{'__I2CONVERT_MACROS'}}) {
+            dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$service_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
         }
         dump_config_line($icinga2_cfg, "\t},");
     }
@@ -444,9 +444,13 @@ sub dump_host_2x {
     ####################################################
     # macros 
     ####################################################
-    if(defined($host_2x->{'address'})) {
+    dump_config_line($icinga2_cfg, "");
+
+    if(defined($host_2x->{'__I2CONVERT_MACROS'}) && $host_2x->{'__I2CONVERT_MACROS'} != 0) {
         dump_config_line($icinga2_cfg, "\tmacros = {");
-        dump_config_line($icinga2_cfg, "\t\taddress = \"$host_2x->{'address'}\",");
+        foreach my $macro_key (keys %{$host_2x->{'__I2CONVERT_MACROS'}}) {
+            dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$host_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
+        }
         dump_config_line($icinga2_cfg, "\t},");
     }
     dump_config_line($icinga2_cfg, "");
@@ -594,10 +598,10 @@ sub dump_host_2x {
         ####################################################
         # macros 
         ####################################################
-        if(defined($service_2x->{'command_macros'}) && $service_2x->{'command_macros'} != 0) {
+        if(defined($service_2x->{'__I2CONVERT_MACROS'}) && $service_2x->{'__I2CONVERT_MACROS'} != 0) {
             dump_config_line($icinga2_cfg, "\t\tmacros = {");
-            foreach my $cmd_arg (keys %{$service_2x->{'command_macros'}}) {
-                dump_config_line($icinga2_cfg, "\t\t\t$cmd_arg = \"$service_2x->{'command_macros'}->{$cmd_arg}\",");
+            foreach my $cmd_arg (keys %{$service_2x->{'__I2CONVERT_MACROS'}}) {
+                dump_config_line($icinga2_cfg, "\t\t\t$cmd_arg = \"$service_2x->{'__I2CONVERT_MACROS'}->{$cmd_arg}\",");
             }
             dump_config_line($icinga2_cfg, "\t\t},");
         }
@@ -732,6 +736,20 @@ sub dump_user_2x {
     }
 
     ####################################################
+    # macros
+    ####################################################
+
+    if(defined($user_2x->{'__I2CONVERT_MACROS'}) && $user_2x->{'__I2CONVERT_MACROS'} != 0) {
+        dump_config_line($icinga2_cfg, "\tmacros = {");
+        foreach my $macro_key (keys %{$user_2x->{'__I2CONVERT_MACROS'}}) {
+            dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$user_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
+        }
+        dump_config_line($icinga2_cfg, "\t},");
+    }
+
+    dump_config_line($icinga2_cfg, "");
+
+    ####################################################
     # usergroups 
     ####################################################
     if(defined($user_2x->{'usergroups'})) {





More information about the icinga-checkins mailing list