From: Michael Friedrich Date: Mon, 24 Jun 2013 15:03:34 +0000 (+0200) Subject: configconvert: treat address* and other attributes directly as macros X-Git-Tag: v0.0.2~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5355e63a3f718b4d3cc6fe36ef4d1079be158aa;p=icinga2 configconvert: treat address* and other attributes directly as macros also for user attributes. fixes #4333 --- diff --git a/tools/configconvert/Icinga2/Convert.pm b/tools/configconvert/Icinga2/Convert.pm index 8c6ddc7ef..cbfe2b4b4 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 @@ -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); diff --git a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm index 7b671f81f..52e81168e 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},"); } @@ -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 ####################################################