diff --git a/tools/migration/icinga2-migrate-config b/tools/migration/icinga2-migrate-config index 2e720e26c..35958742a 100755 --- a/tools/migration/icinga2-migrate-config +++ b/tools/migration/icinga2-migrate-config @@ -294,18 +294,25 @@ sub parse_icinga1_resource_cfg { sub parse_icinga1_global_macros { my $icinga1_cfg = shift; + my $global_macros; my ($icinga1_resource_file) = get_key_from_icinga1_main_cfg($icinga1_cfg, "resource_file"); # resource.cfg - my $global_macros = parse_icinga1_resource_cfg($icinga1_resource_file); + if(defined($icinga1_resource_file)) { + $global_macros = parse_icinga1_resource_cfg($icinga1_resource_file); + } # special attributes in icinga.cfg (admin_*) my ($admin_pager) = get_key_from_icinga1_main_cfg($icinga1_cfg, "admin_pager"); my ($admin_email) = get_key_from_icinga1_main_cfg($icinga1_cfg, "admin_email"); - $global_macros->{'ADMINPAGER'} = $admin_pager; - $global_macros->{'ADMINEMAIL'} = $admin_email; + if (defined($admin_pager)) { + $global_macros->{'ADMINPAGER'} = $admin_pager; + } + if(defined($admin_email)) { + $global_macros->{'ADMINEMAIL'} = $admin_email; + } return $global_macros; } @@ -1312,7 +1319,7 @@ sub resolve_macro_attribute { # _ == custom var from host/service if ($macro_name =~ /^_HOST(\w+)/) { $attr_name = "_$1"; - debug("MACRO RESOLVER: found Host CV '$macro_name'."); + #debug("MACRO RESOLVER: found Host CV '$macro_name'."); if (defined($obj->{'__I2CONVERT_HOSTNAME'})) { $host_name = $obj->{'__I2CONVERT_HOSTNAME'}; @@ -1325,7 +1332,7 @@ sub resolve_macro_attribute { $macro_value = obj_1x_get_host_attr($cfg_obj, $obj_host, $host_name, $attr_name); - debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj_host)); + #debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj_host)); return $macro_value; } elsif ($macro_name =~ /^_SERVICE(\w+)/) { @@ -1334,17 +1341,17 @@ sub resolve_macro_attribute { # if this is a host object, this macro is invalid! XXX return undef if defined($obj->{'__I2CONVERT_HOSTNAME'}); - debug("MACRO RESOLVER: found Service CV '$macro_name'."); + #debug("MACRO RESOLVER: found Service CV '$macro_name'."); $macro_value = obj_1x_get_service_attr($cfg_obj, $obj, $obj->{'__I2CONVERT_SERVICE_HOSTNAME'}, $attr_name); - debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj)); + #debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj)); return $macro_value; } else { # XXX this is way too modular to actually work with macros not having any underscores and other magic if ($macro_name =~ /^HOST(\w+)/) { $attr_name = lc $1; - debug("MACRO RESOLVER: found Host attribute '$macro_name'."); + #debug("MACRO RESOLVER: found Host attribute '$macro_name'."); if (defined($obj->{'__I2CONVERT_HOSTNAME'})) { $host_name = $obj->{'__I2CONVERT_HOSTNAME'}; @@ -1357,7 +1364,7 @@ sub resolve_macro_attribute { $macro_value = obj_1x_get_host_attr($cfg_obj, $obj_host, $host_name, $attr_name); - debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj_host)); + #debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj_host)); return $macro_value; } elsif ($macro_name =~ /^SERVICE(\w+)/) { @@ -1366,10 +1373,10 @@ sub resolve_macro_attribute { # if this is a host object, this macro is invalid! XXX return undef if defined($obj->{'__I2CONVERT_HOSTNAME'}); - debug("MACRO RESOLVER: found Service attribute '$macro_name'."); + #debug("MACRO RESOLVER: found Service attribute '$macro_name'."); $macro_value = obj_1x_get_service_attr($cfg_obj, $obj, $obj->{'__I2CONVERT_SERVICE_HOSTNAME'}, $attr_name); - debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj)); + #debug("MACRO RESOLVER: found $attr_name with value '$macro_value' on " . Dumper($obj)); return $macro_value; } elsif ($macro_name =~ /^CONTACT(\w+)/) { @@ -1830,7 +1837,8 @@ sub migrate_2x { #say Dumper($service_event_command_2x); # XXX do not add duplicate event commands, they must remain unique by their check_command origin! - if ((obj_2x_command_exists($cfg_obj_2x, $obj_1x_service->{'event_handler'}) != 1)) { + my $command_type = 'Event'; + if (obj_2x_command_exists($cfg_obj_2x, $obj_1x_service->{'event_handler'}, $command_type) != 1) { # create a new EventCommand 2x object with the original name $cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Event'; @@ -1872,7 +1880,8 @@ sub migrate_2x { if (defined($service_check_command_2x->{'check_command_name_1x'})) { # XXX do not add duplicate check commands, they must remain unique by their check_command origin! - if (obj_2x_command_exists($cfg_obj_2x, $service_check_command_2x->{'check_command_name_1x'}) != 1) { + my $command_type = 'Check'; + if (obj_2x_command_exists($cfg_obj_2x, $service_check_command_2x->{'check_command_name_1x'}, $command_type) != 1) { # create a new CheckCommand 2x object with the original name $cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Check';