}
-################################################################################
+#################################################################################
# Migration
#################################################################################
# Conversion
#################################################################################
+# convert notification_options to state|type_filter
+sub convert_notification_options_to_filter {
+ my $notification_options = shift;
+ my $filter = ();
+ @{$filter->{'state'}} = ();
+ @{$filter->{'type'}} = ();
+
+ # define all types
+ my $filter_names = {
+ 'o' => 'StateFilterOK',
+ 'w' => 'StateFilterWarning',
+ 'c' => 'StateFilterCritical',
+ 'u' => 'StateFilterUnknown',
+ 'd' => 'StateFilterCritical', # down, treated as critical
+ 's' => 'NotificationFilterDowntimeStart | NotificationFilterDowntimeEnd | NotificationFilterDowntimeRemoved',
+ 'r' => 'NotificationFilterRecovery',
+ 'f' => 'NotificationFilterFlappingStart | NotificationFilterFlappingEnd'
+ };
+ my $filter_by = {
+ 'o' => 'state',
+ 'w' => 'state',
+ 'c' => 'state',
+ 'u' => 'state',
+ 'd' => 'state',
+ 's' => 'type',
+ 'r' => 'type',
+ 'f' => 'type'
+ };
+
+ # split the string
+ my @options = Icinga2::Utils::str2arr_by_delim_without_excludes($notification_options, ',', 1);
+
+ # verify if there's 'n' (none) or 'a' (all) and ignore the rest then
+ if (grep /n/, @options) {
+ return $filter;
+ }
+ if (grep /a/, @options) {
+ foreach my $by (keys %{$filter_by}) {
+ push @{$filter->{$by}}, $filter_names->{$by};
+ }
+ return $filter;
+ }
+
+ # the selective way
+ foreach my $option (@options) {
+ push @{$filter->{$filter_by->{$option}}}, $filter_names->{$option};
+ }
+
+ return $filter;
+}
+
# host|service_notification_commands are a comma seperated list w/o arguments
sub convert_notificationcommand {
my $objs_1x = shift;
}
##########################################
- # notification_interval
+ # notification_*
##########################################
my $service_notification_interval = undef;
if(defined($obj_1x_service->{'notification_interval'})) {
$cfg_obj_2x->{'service'}->{$service_cnt}->{'notification_interval'} = $service_notification_interval."m";
}
+ 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});
+ }
+
##########################################
# eventhandler
##########################################
$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notification_interval'} = $host_notification_interval."m";
}
+ 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});
+ }
+
if(defined($obj_1x_host->{'parents'})) {
my @host_parents = Icinga2::Utils::str2arr_by_delim_without_excludes($obj_1x_host->{'parents'}, ',', 1);
push @{$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_PARENT_HOSTNAMES'}}, @host_parents;
}
}
+ ##########################################
+ # notification_options (service only XXX)
+ ##########################################
+ if(defined($obj_1x_contact->{'service_notification_options'})) {
+ $cfg_obj_2x->{'user'}->{$contact_obj_1x_key}->{'__I2CONVERT_NOTIFICATION_FILTERS'} = convert_notification_options_to_filter($obj_1x_contact->{'service_notification_options'});
+ }
+
####################################################
# migrate renamed attributes
####################################################
my $file = shift;
my $FH;
- say "opening file '$file'...\n";
+ say "writing file '$file'...\n";
open($FH, ">".$file);
+ if (!-w $FH) {
+ print "ERROR: cannot write file '$file'. Check permissions!\n";
+ }
+
return $FH;
}
if(defined($service_2x->{'notifications_enabled'})) {
dump_config_line($icinga2_cfg, "\tnotifications_enabled = $service_2x->{'notifications_enabled'},");
}
- if(defined($service_2x->{'notification_options'})) {
- dump_config_line($icinga2_cfg, "\tnotification_options = \"$service_2x->{'notification_options'}\",");
+
+ if(defined($service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) {
+ say Dumper($service_2x);
+ foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) {
+ my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")";
+ dump_config_line($icinga2_cfg, "\t$notification_filter,");
+ }
}
####################################################
####################################################
# notifications
####################################################
+ if(defined($host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) {
+ foreach my $by (keys %{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) {
+ my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$host_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")";
+ dump_config_line($icinga2_cfg, "\t$notification_filter,");
+ }
+ }
+
if(defined($host_2x->{'__I2CONVERT_NOTIFICATIONS'})) {
#say Dumper ($host_2x->{'__I2CONVERT_NOTIFICATIONS'});
# this is an array of notification objects
if(defined($host_2x->{'notifications_enabled'})) {
dump_config_line($icinga2_cfg, "\tnotifications_enabled = $host_2x->{'notifications_enabled'},");
}
- if(defined($host_2x->{'notification_options'})) {
- dump_config_line($icinga2_cfg, "\tnotification_options = \"$host_2x->{'notification_options'}\",");
- }
####################################################
# other host attributes, if set
####################################################
# notifications
####################################################
+ if(defined($service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) {
+ foreach my $by (keys %{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) {
+ my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$service_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")";
+ dump_config_line($icinga2_cfg, "\t$notification_filter,");
+ }
+ }
+
if(defined($service_2x->{'__I2CONVERT_NOTIFICATIONS'})) {
#say Dumper ($service_2x->{'__I2CONVERT_NOTIFICATIONS'});
# this is an array of notification objects
if(defined($service_2x->{'notifications_enabled'})) {
dump_config_line($icinga2_cfg, "\tnotifications_enabled = $service_2x->{'notifications_enabled'},");
}
- if(defined($service_2x->{'notification_options'})) {
- dump_config_line($icinga2_cfg, "\tnotification_options = \"$service_2x->{'notification_options'}\",");
- }
####################################################
# other service attributes, if set
# notifications
####################################################
- if(defined($user_2x->{'notification_options'})) {
- dump_config_line($icinga2_cfg, "\tnotification_options = \"$user_2x->{'notification_options'}\",");
- }
if(defined($user_2x->{'notification_period'})) {
dump_config_line($icinga2_cfg, "\tnotification_period = \"$user_2x->{'notification_period'}\",");
}
+ if(defined($user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'})) {
+ foreach my $by (keys %{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}}) {
+ my $notification_filter = "notification_".$by."_filter = (". (join ' | ', @{$user_2x->{'__I2CONVERT_NOTIFICATION_FILTERS'}->{$by}}) .")";
+ dump_config_line($icinga2_cfg, "\t$notification_filter,");
+ }
+ }
+
####################################################
# usergroups
####################################################