]> granicus.if.org Git - icinga2/commitdiff
Config Conversion: Add ADMINPAGER|EMAIL as macros from icinga.cfg
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 30 Aug 2013 13:58:58 +0000 (15:58 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 30 Aug 2013 13:58:58 +0000 (15:58 +0200)
and fix multiple user macros too. and add NotificationFilterCustom by
default.

fixes #4662

tools/configconvert/Icinga2/Convert.pm
tools/configconvert/Icinga2/ImportIcinga1Cfg.pm

index 199d0b711bad6c7b1a66fe2b9162ac319752362a..835b6225118e6750d17489ad846f06c254cdbb93 100644 (file)
@@ -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)
index d8490bdb842a12bc2b69f9fb19226109cc5a49e1..a1c693c96affc02ea021cfaee411c8714d2028a4 100644 (file)
@@ -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;
 }