# Conversion
#################################################################################
+# convert CVs, *_url, etc into custom hash
+sub obj_convert_custom_attr_to_custom_hash {
+ my $obj = shift;
+ my $custom;
+
+ foreach my $key (keys %{$obj}) {
+ if ($key =~ /^_|_url$|notes|image|coords/ && $key !~ /__I2CONVERT/) {
+ my $new_key = ($key =~ /^\d/) ? "\"$key\"" : $key;
+ $custom->{$new_key} = Icinga2::Utils::escape_str($obj->{$key});
+ }
+ }
+
+ $obj->{'__I2CONVERT_CUSTOM_ATTR'} = $custom;
+
+ return $custom;
+}
+
# convert notification_options to state|type_filter
sub convert_notification_options_to_filter {
my $notification_options = shift;
}
}
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ my $custom = obj_convert_custom_attr_to_custom_hash($obj_1x_service);
+
####################################################
# get related host_name/service_description
# used later in host->service resolval
# same:
# - display_name
# - max_check_attempts
+ # - check_period
+ # - notification_period
+ # custom:
+ # - _CV
# - action_url
# - notes_url
# - notes
# - icon_image
- # - notes
# change:
# - servicegroups (commaseperated strings to array)
# - check_command
# - check_interval (X min -> Xm) + normal_check_interval
# - retry_interval (X min -> Xm) + retry_check_interval
# - notification_interval (X min -> Xm)
- # - check_period - XXX TODO
- # - notification_period - XXX TODO
# - contacts => users XXX DO NOT DELETE contacts and contactgroups, they will be assembled later for notifications!
- # -
####################################################
- ##########################################
- # escape strings in attributes
- ##########################################
- if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'})) {
- $cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'});
- }
- if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'notes_url'})) {
- $cfg_obj_2x->{'service'}->{$service_cnt}->{'notes_url'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'notes_url'});
- }
- if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'notes'})) {
- $cfg_obj_2x->{'service'}->{$service_cnt}->{'notes'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'notes'});
- }
- if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image'})) {
- $cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image'});
- }
- if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image_alt'})) {
- $cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image_alt'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'icon_image_alt'});
- }
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ $cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'service'}->{$service_cnt});
+ #say Dumper($cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_CUSTOM_ATTR'});
##########################################
# servicegroups
# map existing host attributes
# same:
# - max_check_attempts
+ # - check_period
+ # - notification_period
+ # custom:
+ # - _CVs
# - action_url
# - notes_url
# - notes
# - icon_image
# - statusmap_image
- # - notes
# change:
# - display_name (if alias is set, overwrites it)
# - hostgroups (commaseperated strings to array)
# - check_interval (X min -> Xm) + normal_check_interval
# - retry_interval (X min -> Xm) + retry_check_interval
# - notification_interval (X min -> Xm)
- # - check_period - XXX TODO
- # - notification_period - XXX TODO
# - contacts => users XXX DO NOT DELETE contacts and contactgroups - they will be assembled later for notifications!
# -
- # remove:
- # - check_command
####################################################
##########################################
$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'address6'} = $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address6'};
}
- ##########################################
- # escape strings in attributes
- ##########################################
- if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'action_url'})) {
- $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'action_url'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'action_url'});
- }
- if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes_url'})) {
- $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes_url'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes_url'});
- }
- if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes'})) {
- $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'notes'});
- }
- if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image'})) {
- $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image'});
- }
- if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image_alt'})) {
- $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image_alt'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'icon_image_alt'});
- }
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'host'}->{$host_obj_1x_key});
####################################################
# display_name -> alias mapping
}
}
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ $cfg_obj_2x->{'hostgroup'}->{$hostgroup_obj_1x_key}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'hostgroup'}->{$hostgroup_obj_1x_key});
+
####################################################
# check if there are members defined, we must re-link them in their host object again
####################################################
}
}
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ $cfg_obj_2x->{'servicegroup'}->{$servicegroup_obj_1x_key}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'servicegroup'}->{$servicegroup_obj_1x_key});
+
####################################################
# check if there are members defined, we must re-link them in their service object again
####################################################
}
}
+ ####################################################
+ # migrate custom attributes
+ ####################################################
+ $cfg_obj_2x->{'usergroup'}->{$contactgroup_obj_1x_key}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'usergroup'}->{$contactgroup_obj_1x_key});
+
####################################################
# check if there are members defined, we must re-link them in their host object again
####################################################
dump_config_line($icinga2_cfg, "\tcheck_period = \"$service_2x->{'check_period'}\",");
}
- if(defined($service_2x->{'action_url'})) {
- dump_config_line($icinga2_cfg, "\taction_url = \"$service_2x->{'action_url'}\",");
- }
-
- if(defined($service_2x->{'notes_url'})) {
- dump_config_line($icinga2_cfg, "\tnotes_url = \"$service_2x->{'notes_url'}\",");
- }
-
- if(defined($service_2x->{'notes'})) {
- dump_config_line($icinga2_cfg, "\tnotes = \"$service_2x->{'notes'}\",");
- }
-
- if(defined($service_2x->{'icon_image'})) {
- dump_config_line($icinga2_cfg, "\ticon_image = \"$service_2x->{'icon_image'}\",");
- }
-
if(defined($service_2x->{'volatile'})) {
dump_config_line($icinga2_cfg, "\tvolatile = $service_2x->{'volatile'},");
}
+ ####################################################
+ # custom attr
+ ####################################################
+ if(defined($service_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $service_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
+ dump_config_line($icinga2_cfg, "\tcustom = {");
+ foreach my $custom_key (keys %{$service_2x->{'__I2CONVERT_CUSTOM_ATTR'}}) {
+ dump_config_line($icinga2_cfg, "\t\t$custom_key = \"$service_2x->{'__I2CONVERT_CUSTOM_ATTR'}->{$custom_key}\",");
+ }
+ dump_config_line($icinga2_cfg, "\t},");
+ }
+
+ dump_config_line($icinga2_cfg, "");
dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n");
if(defined($host_2x->{'max_check_attempts'})) {
dump_config_line($icinga2_cfg, "\tmax_check_attempts = $host_2x->{'max_check_attempts'},");
}
-
if(defined($host_2x->{'check_period'})) {
dump_config_line($icinga2_cfg, "\tcheck_period = \"$host_2x->{'check_period'}\",");
}
- if(defined($host_2x->{'action_url'})) {
- dump_config_line($icinga2_cfg, "\taction_url = \"$host_2x->{'action_url'}\",");
- }
-
- if(defined($host_2x->{'notes_url'})) {
- dump_config_line($icinga2_cfg, "\tnotes_url = \"$host_2x->{'notes_url'}\",");
- }
-
- if(defined($host_2x->{'notes'})) {
- dump_config_line($icinga2_cfg, "\tnotes = \"$host_2x->{'notes'}\",");
- }
-
- if(defined($host_2x->{'icon_image'})) {
- dump_config_line($icinga2_cfg, "\ticon_image = \"$host_2x->{'icon_image'}\",");
- }
+ ####################################################
+ # custom attr
+ ####################################################
- if(defined($host_2x->{'statusmap_image'})) {
- dump_config_line($icinga2_cfg, "\tstatusmap_image = $host_2x->{'statusmap_image'},");
+ if(defined($host_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $host_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
+ dump_config_line($icinga2_cfg, "\tcustom = {");
+ foreach my $custom_key (keys %{$host_2x->{'__I2CONVERT_CUSTOM_ATTR'}}) {
+ dump_config_line($icinga2_cfg, "\t\t$custom_key = \"$host_2x->{'__I2CONVERT_CUSTOM_ATTR'}->{$custom_key}\",");
+ }
+ dump_config_line($icinga2_cfg, "\t},");
}
+ ####################################################
# host with no services - valid configuration
+ ####################################################
if (!defined($host_2x->{'SERVICE'})) {
dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n");
if(defined($service_2x->{'max_check_attempts'})) {
dump_config_line($icinga2_cfg, "\t\tmax_check_attempts = $service_2x->{'max_check_attempts'},");
}
-
if(defined($service_2x->{'check_period'})) {
dump_config_line($icinga2_cfg, "\tcheck_period = \"$service_2x->{'check_period'}\",");
}
- if(defined($service_2x->{'action_url'})) {
- dump_config_line($icinga2_cfg, "\t\taction_url = \"$service_2x->{'action_url'}\",");
- }
-
- if(defined($service_2x->{'notes_url'})) {
- dump_config_line($icinga2_cfg, "\t\tnotes_url = \"$service_2x->{'notes_url'}\",");
- }
-
- if(defined($service_2x->{'notes'})) {
- dump_config_line($icinga2_cfg, "\t\tnotes = \"$service_2x->{'notes'}\",");
- }
+ ####################################################
+ # custom attr
+ ####################################################
- if(defined($service_2x->{'icon_image'})) {
- dump_config_line($icinga2_cfg, "\t\ticon_image = \"$service_2x->{'icon_image'}\",");
+ if(defined($service_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $service_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
+ dump_config_line($icinga2_cfg, "\t\tcustom = {");
+ foreach my $custom_key (keys %{$service_2x->{'__I2CONVERT_CUSTOM_ATTR'}}) {
+ dump_config_line($icinga2_cfg, "\t\t\t$custom_key = \"$service_2x->{'__I2CONVERT_CUSTOM_ATTR'}->{$custom_key}\",");
+ }
+ dump_config_line($icinga2_cfg, "\t\t},");
}
-
dump_config_line($icinga2_cfg, "\t},");
dump_config_line($icinga2_cfg, "");
}
}
}
+ ####################################################
+ # custom attr
+ ####################################################
+
+ if(defined($user_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $user_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
+ dump_config_line($icinga2_cfg, "\tcustom = {");
+ foreach my $custom_key (keys %{$user_2x->{'__I2CONVERT_CUSTOM_ATTR'}}) {
+ dump_config_line($icinga2_cfg, "\t\t$custom_key = \"$user_2x->{'__I2CONVERT_CUSTOM_ATTR'}->{$custom_key}\",");
+ }
+ dump_config_line($icinga2_cfg, "\t},");
+ }
+
dump_config_line($icinga2_cfg, "");
dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n");
if(defined($group_2x->{'display_name'})) {
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$group_2x->{'display_name'}\",");
}
+
+ ####################################################
+ # custom attr
+ ####################################################
+
+ if(defined($group_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $group_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
+ dump_config_line($icinga2_cfg, "\tcustom = {");
+ foreach my $custom_key (keys %{$group_2x->{'__I2CONVERT_CUSTOM_ATTR'}}) {
+ dump_config_line($icinga2_cfg, "\t\t$custom_key = \"$group_2x->{'__I2CONVERT_CUSTOM_ATTR'}->{$custom_key}\",");
+ }
+ dump_config_line($icinga2_cfg, "\t},");
+ }
+
dump_config_line($icinga2_cfg, "");
dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n");