]> granicus.if.org Git - icinga2/commitdiff
configconvert: treat address* and other attributes directly as macros
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 24 Jun 2013 15:03:34 +0000 (17:03 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 24 Jun 2013 15:03:34 +0000 (17:03 +0200)
also for user attributes.

fixes #4333

tools/configconvert/Icinga2/Convert.pm
tools/configconvert/Icinga2/ExportIcinga2Cfg.pm

index 8c6ddc7ef24baa2c9128a8f879a1a26f46b901b9..cbfe2b4b41602634254aa1260bbae52c25968995 100644 (file)
@@ -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
@@ -1005,6 +1005,16 @@ sub convert_2x {
         # - check_command
         ####################################################
 
+        ##########################################
+        # 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
         ##########################################
@@ -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);
index 7b671f81fa91843892a46a0f4396730c794454b6..52e81168e822a378f3188c41170a3c9a192ca39a 100644 (file)
@@ -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},");
         }
@@ -731,6 +735,20 @@ sub dump_user_2x {
         dump_config_line($icinga2_cfg, "\tdisplay_name = \"$user_2x->{'display_name'}\",");
     }
 
+    ####################################################
+    # 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 
     ####################################################