mirror of https://github.com/Icinga/icinga2.git
Config Conversion: fix missing Command macros, avoid duplicates
This commit is contained in:
parent
7f0a210ff9
commit
14c2e99e4b
|
@ -928,9 +928,12 @@ sub convert_notificationcommand {
|
|||
push @user_macros, @admin_macros;
|
||||
|
||||
foreach my $macro_name (@user_macros) {
|
||||
$notification_commands_2x->{'command_macros'}->{$macro_name} = Icinga2::Utils::escape_str($user_macros_1x->{$macro_name});
|
||||
$notification_commands_2x->{$notification_command_type}->{'command_macros'}->{$macro_name} = Icinga2::Utils::escape_str($user_macros_1x->{$macro_name});
|
||||
}
|
||||
}
|
||||
|
||||
# flag this 1.x command as being used
|
||||
$commands_1x->{$command_1x_key}->{__I2_CONVERT_NOTIFICATION_COMMAND_USED} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1304,6 +1307,7 @@ sub convert_2x {
|
|||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Check';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $service_check_command_2x->{'check_command_name_1x'};
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $service_check_command_2x->{'check_command'};
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $service_check_command_2x->{'command_macros'};
|
||||
|
||||
# use the ITL plugin check command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'checkcommand-template'}) && $icinga2_cfg->{'itl'}->{'checkcommand-template'} ne "") {
|
||||
|
@ -2098,7 +2102,7 @@ sub convert_2x {
|
|||
# get all notification_commands, and create new notification templates
|
||||
####################################################
|
||||
my $notification_commands = $obj_2x_user->{'__I2CONVERT_NOTIFICATION_COMMANDS'};
|
||||
say Dumper($notification_commands);
|
||||
#say Dumper($notification_commands);
|
||||
|
||||
foreach my $notification_command_type (keys %{$notification_commands}) {
|
||||
foreach my $notification_command_name (keys %{$notification_commands->{$notification_command_type}}) {
|
||||
|
@ -2131,10 +2135,11 @@ sub convert_2x {
|
|||
next if (!defined($notification_command_name_2x));
|
||||
|
||||
# create a new NotificationCommand 2x object with the original name
|
||||
if (obj_2x_command_exists($cfg_obj_2x, $notification_command_name) != 1) {
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Notification';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $notification_command_name;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $notification_command_line;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $notification_commands->{'command_macros'};
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $notification_commands->{$notification_command_type}->{'command_macros'};
|
||||
|
||||
# use the ITL plugin notification command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'notificationcommand-template'}) && $icinga2_cfg->{'itl'}->{'notificationcommand-template'} ne "") {
|
||||
|
@ -2147,6 +2152,7 @@ sub convert_2x {
|
|||
|
||||
# our global PK
|
||||
$command_obj_cnt++;
|
||||
}
|
||||
|
||||
# create a new notification template object
|
||||
$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'} = $notification_command_name_2x;
|
||||
|
@ -2340,9 +2346,11 @@ sub convert_2x {
|
|||
next if (!defined($notification_command_name_2x));
|
||||
|
||||
# create a new NotificationCommand 2x object with the original name
|
||||
if (obj_2x_notification_exists($cfg_obj_2x, $notification_command_name) != 1) {
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Notification';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $notification_command_name;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $notification_command_line;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $notification_commands->{$notification_command_type}->{'command_macros'};
|
||||
|
||||
# use the ITL plugin notification command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'notificationcommand-template'}) && $icinga2_cfg->{'itl'}->{'notificationcommand-template'} ne "") {
|
||||
|
@ -2355,6 +2363,7 @@ sub convert_2x {
|
|||
|
||||
# our global PK
|
||||
$command_obj_cnt++;
|
||||
}
|
||||
|
||||
# create a new notification template object
|
||||
$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'} = $notification_command_name_2x;
|
||||
|
@ -2419,9 +2428,11 @@ sub convert_2x {
|
|||
next if (!defined($notification_command_name_2x));
|
||||
|
||||
# create a new NotificationCommand 2x object with the original name
|
||||
if (obj_2x_notification_exists($cfg_obj_2x, $notification_command_name) != 1) {
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Notification';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $notification_command_name;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $notification_command_line;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $notification_commands->{$notification_command_type}->{'command_macros'};
|
||||
|
||||
# use the ITL plugin notification command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'notificationcommand-template'}) && $icinga2_cfg->{'itl'}->{'notificationcommand-template'} ne "") {
|
||||
|
@ -2434,6 +2445,7 @@ sub convert_2x {
|
|||
|
||||
# our global PK
|
||||
$command_obj_cnt++;
|
||||
}
|
||||
|
||||
# create a new notification template object
|
||||
$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'} = $notification_command_name_2x;
|
||||
|
@ -2499,9 +2511,11 @@ sub convert_2x {
|
|||
next if (!defined($notification_command_name_2x));
|
||||
|
||||
# create a new NotificationCommand 2x object with the original name
|
||||
if (obj_2x_notification_exists($cfg_obj_2x, $notification_command_name) != 1) {
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Notification';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $notification_command_name;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $notification_command_line;
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $notification_commands->{$notification_command_type}->{'command_macros'};
|
||||
|
||||
# use the ITL plugin notification command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'notificationcommand-template'}) && $icinga2_cfg->{'itl'}->{'notificationcommand-template'} ne "") {
|
||||
|
@ -2514,6 +2528,7 @@ sub convert_2x {
|
|||
|
||||
# our global PK
|
||||
$command_obj_cnt++;
|
||||
}
|
||||
|
||||
# create a new notification template object
|
||||
$cfg_obj_2x->{'notification'}->{$notification_obj_cnt}->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'} = $notification_command_name_2x;
|
||||
|
@ -2655,6 +2670,7 @@ sub convert_2x {
|
|||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_TYPE'} = 'Check';
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_NAME'} = $host_check_command_2x->{'check_command_name_1x'};
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_LINE'} = $host_check_command_2x->{'check_command'};
|
||||
$cfg_obj_2x->{'command'}->{$command_obj_cnt}->{'__I2CONVERT_COMMAND_MACROS'} = $host_check_command_2x->{'command_macros'};
|
||||
|
||||
# use the ITL plugin check command template
|
||||
if(defined($icinga2_cfg->{'itl'}->{'checkcommand-template'}) && $icinga2_cfg->{'itl'}->{'checkcommand-template'} ne "") {
|
||||
|
|
|
@ -1056,6 +1056,11 @@ sub dump_command_2x {
|
|||
my $object_type = "object";
|
||||
|
||||
#say Dumper($command_2x);
|
||||
# skip used commands
|
||||
if ($command_2x->{'__I2_CONVERT_NOTIFICATION_COMMAND_USED'} == 1) {
|
||||
say "Skipping already processed notification command" . Dumper($command_2x);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($command_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
||||
$object_type = "template";
|
||||
|
|
Loading…
Reference in New Issue