From 1a3ecb04fb8d98528ec495a60b3e9f222a9c755f Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 30 Aug 2013 15:58:58 +0200 Subject: [PATCH] Config Conversion: Add ADMINPAGER|EMAIL as macros from icinga.cfg and fix multiple user macros too. and add NotificationFilterCustom by default. fixes #4662 --- tools/configconvert/Icinga2/Convert.pm | 15 +++++++++++---- tools/configconvert/Icinga2/ImportIcinga1Cfg.pm | 8 ++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/configconvert/Icinga2/Convert.pm b/tools/configconvert/Icinga2/Convert.pm index 199d0b711..835b62251 100644 --- a/tools/configconvert/Icinga2/Convert.pm +++ b/tools/configconvert/Icinga2/Convert.pm @@ -846,8 +846,9 @@ sub convert_notification_options_to_filter { return $filter; } - # always add NotificationFilterProblem + # always add NotificationFilterProblem|Custom push @{$filter->{'type'}}, 'NotificationFilterProblem'; + push @{$filter->{'type'}}, 'NotificationFilterCustom'; if (grep /a/, @options) { foreach my $by (keys %{$filter_by}) { @@ -997,9 +998,15 @@ sub convert_checkcommand { #Icinga2::Utils::debug("2x Command: $command_2x->{'check_command'}"); # detect $USERn$ macros and replace them too XXX - this should be a global macro? - if ($commands_1x->{$command_1x_key}->{'command_line'} =~ /\$(USER\d+)\$/) { - $command_2x->{'command_macros'}->{$1} = Icinga2::Utils::escape_str($user_macros_1x->{$1}); - #debug("\$$1\$=$command_2x->{'macros'}->{$1}"); + if ($commands_1x->{$command_1x_key}->{'command_line'} =~ /\$(USER\d+)\$/ || + $commands_1x->{$command_1x_key}->{'command_line'} =~ /\$(ADMIN\w+)\$/) { + my @user_macros = ($commands_1x->{$command_1x_key}->{'command_line'} =~ /\$(USER\d+)\$/g); + my @admin_macros = ($commands_1x->{$command_1x_key}->{'command_line'} =~ /\$(ADMIN\w+)\$/g); + push @user_macros, @admin_macros; + + foreach my $macro_name (@user_macros) { + $command_2x->{'command_macros'}->{$macro_name} = Icinga2::Utils::escape_str($user_macros_1x->{$macro_name}); + } } # save all command args as macros (we'll deal later with them in service definitions) diff --git a/tools/configconvert/Icinga2/ImportIcinga1Cfg.pm b/tools/configconvert/Icinga2/ImportIcinga1Cfg.pm index d8490bdb8..a1c693c96 100644 --- a/tools/configconvert/Icinga2/ImportIcinga1Cfg.pm +++ b/tools/configconvert/Icinga2/ImportIcinga1Cfg.pm @@ -94,8 +94,16 @@ sub parse_icinga1_user_macros { my ($icinga1_resource_file) = get_key_from_icinga1_main_cfg($icinga1_cfg, "resource_file"); + # resource.cfg my $user_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"); + + $user_macros->{'ADMINPAGER'} = $admin_pager; + $user_macros->{'ADMINEMAIL'} = $admin_email; + return $user_macros; }