diff --git a/tools/configconvert/Icinga2/Convert.pm b/tools/configconvert/Icinga2/Convert.pm index 2b049ea2a..788e91018 100644 --- a/tools/configconvert/Icinga2/Convert.pm +++ b/tools/configconvert/Icinga2/Convert.pm @@ -1325,6 +1325,10 @@ sub convert_2x { if(defined($obj_1x_service->{'notification_options'})) { $cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = convert_notification_options_to_filter($obj_1x_service->{'notification_options'}); #say Dumper($cfg_obj_2x->{'service'}->{$service_cnt}); + } else { + # fetch them from template tree for later notification object mapping + my $notification_options = obj_1x_get_service_attr($cfg_obj_1x, $obj_1x_service, $service_host_name, 'notification_options'); + $cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = convert_notification_options_to_filter($notification_options); } ########################################## @@ -1586,6 +1590,10 @@ sub convert_2x { if(defined($obj_1x_host->{'notification_options'})) { $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = convert_notification_options_to_filter($obj_1x_host->{'notification_options'}); #say Dumper($cfg_obj_2x->{'host'}->{$host_obj_1x_key}); + } else { + # fetch them from template tree for later notification object mapping + my $notification_options = obj_1x_get_host_attr($cfg_obj_1x, $obj_1x_host, 'notification_options'); + $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = convert_notification_options_to_filter($notification_options); } if(defined($obj_1x_host->{'parents'})) { @@ -2315,10 +2323,23 @@ sub convert_2x { # now loop and fetch objects, and their needed notification values as array # (prepared above - look for $user_notification->{$notification_command_name_2x}...) foreach my $uniq_user (@uniq_users) { + my $obj_2x_user = obj_get_user_obj_by_user_name($cfg_obj_2x, $uniq_user); + + #say Dumper($obj_2x_user); push @{$cfg_obj_2x->{'service'}->{$service_obj_2x_key}->{'__I2CONVERT_NOTIFICATIONS'}}, $obj_2x_user->{'__I2CONVERT_NOTIFICATIONS'}; # we'll add a reference to all notifications here. decide on dump which object type is given, and dump only those notifications! } + + # inherit notification filters from service to all newly created notifications + foreach my $notification (@{$cfg_obj_2x->{'service'}->{$service_obj_2x_key}->{'__I2CONVERT_NOTIFICATIONS'}}) { + foreach my $notification_key (keys %{$notification}) { + next if $notification->{$notification_key}->{'type'} ne 'service'; + + $notification->{$notification_key}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = $cfg_obj_2x->{'service'}->{$service_obj_2x_key}->{'__I2CONVERT_NOTIFICATION_FILTERS'}; + say Dumper($notification); + } + } #say Dumper($obj_2x_service); } diff --git a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm index 6b5209a5f..1e07139f5 100644 --- a/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm +++ b/tools/configconvert/Icinga2/ExportIcinga2Cfg.pm @@ -398,6 +398,20 @@ sub dump_service_2x { dump_config_line($icinga2_cfg, "\t\tusers = [ \"$service_users\" ],"); } + if(defined($service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { + #say Dumper($service_2x); + foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { + next if !@{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; + my $notification_filter; + if (grep /0/, @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\t\tnotification_".$by."_filter = $notification_filter,"); + } + } + # this is set for escalations if(defined($service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}) && $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'} != 0) { dump_config_line($icinga2_cfg, "\t\ttimes = {"); @@ -421,20 +435,6 @@ sub dump_service_2x { dump_config_line($icinga2_cfg, "\tenable_notifications = $service_2x->{'notifications_enabled'},"); } - if(defined($service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { - #say Dumper($service_2x); - foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { - next if !@{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter; - if (grep /0/, @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { - $notification_filter = 0; - } else { - $notification_filter = "(". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - } - dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); - } - } - #################################################### # other service attributes, if set #################################################### @@ -555,19 +555,6 @@ sub dump_host_2x { #################################################### # notifications #################################################### - if(defined($host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { - foreach my $by (keys %{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { - next if !@{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; - my $notification_filter; - if (grep /0/, @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { - $notification_filter = 0; - } else { - $notification_filter = "(". (join ' | ', @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; - } - dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); - } - } - if(defined($host_2x->{'notification_period'})) { dump_config_line($icinga2_cfg, "\tnotification_period = \"$host_2x->{'notification_period'}\","); } @@ -998,6 +985,19 @@ sub dump_notification_2x { dump_config_line($icinga2_cfg, "\tusergroups = [ \"$service_usergroups\" ],"); } + if(defined($notification_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) { + foreach my $by (keys %{$notification_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) { + next if !@{$notification_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}; + my $notification_filter; + if (grep /0/, @{$notification_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) { + $notification_filter = 0; + } else { + $notification_filter = "(". (join ' | ', @{$notification_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")"; + } + dump_config_line($icinga2_cfg, "\tnotification_".$by."_filter = $notification_filter,"); + } + } + # this is set for escalations if(defined($notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'}) && $notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'} != 0) { dump_config_line($icinga2_cfg, "\ttimes = {");