configconvert: custom attr (CVs, *_url, notes, *image*, 2d_coords)

collect attributes
* notes
* icon_image
* icon_image_alt
* action_url
* notes_url
* statusmap_image
* 2d_coords
* _CVs
* !__I2CONVERT

and stash it onto the custom dictionary.

note: attribute names starting with a number need to be quoted.

fixes #3096
This commit is contained in:
Michael Friedrich 2013-06-26 16:01:22 +02:00
parent 12916ec299
commit f3ccb88bae
2 changed files with 112 additions and 95 deletions

View File

@ -715,6 +715,23 @@ sub obj_2x_get_service_servicegroups {
# Conversion # 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 # convert notification_options to state|type_filter
sub convert_notification_options_to_filter { sub convert_notification_options_to_filter {
my $notification_options = shift; my $notification_options = shift;
@ -978,6 +995,11 @@ sub convert_2x {
} }
} }
####################################################
# migrate custom attributes
####################################################
my $custom = obj_convert_custom_attr_to_custom_hash($obj_1x_service);
#################################################### ####################################################
# get related host_name/service_description # get related host_name/service_description
# used later in host->service resolval # used later in host->service resolval
@ -1025,41 +1047,28 @@ sub convert_2x {
# same: # same:
# - display_name # - display_name
# - max_check_attempts # - max_check_attempts
# - check_period
# - notification_period
# custom:
# - _CV
# - action_url # - action_url
# - notes_url # - notes_url
# - notes # - notes
# - icon_image # - icon_image
# - notes
# change: # change:
# - servicegroups (commaseperated strings to array) # - servicegroups (commaseperated strings to array)
# - check_command # - check_command
# - check_interval (X min -> Xm) + normal_check_interval # - check_interval (X min -> Xm) + normal_check_interval
# - retry_interval (X min -> Xm) + retry_check_interval # - retry_interval (X min -> Xm) + retry_check_interval
# - notification_interval (X min -> Xm) # - 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! # - contacts => users XXX DO NOT DELETE contacts and contactgroups, they will be assembled later for notifications!
# -
#################################################### ####################################################
########################################## ####################################################
# escape strings in attributes # migrate custom attributes
########################################## ####################################################
if(defined($cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'})) { $cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_CUSTOM_ATTR'} = obj_convert_custom_attr_to_custom_hash($cfg_obj_2x->{'service'}->{$service_cnt});
$cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'} = Icinga2::Utils::escape_str($cfg_obj_2x->{'service'}->{$service_cnt}->{'action_url'}); #say Dumper($cfg_obj_2x->{'service'}->{$service_cnt}->{'__I2CONVERT_CUSTOM_ATTR'});
}
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'});
}
########################################## ##########################################
# servicegroups # servicegroups
@ -1276,24 +1285,23 @@ sub convert_2x {
# map existing host attributes # map existing host attributes
# same: # same:
# - max_check_attempts # - max_check_attempts
# - check_period
# - notification_period
# custom:
# - _CVs
# - action_url # - action_url
# - notes_url # - notes_url
# - notes # - notes
# - icon_image # - icon_image
# - statusmap_image # - statusmap_image
# - notes
# change: # change:
# - display_name (if alias is set, overwrites it) # - display_name (if alias is set, overwrites it)
# - hostgroups (commaseperated strings to array) # - hostgroups (commaseperated strings to array)
# - check_interval (X min -> Xm) + normal_check_interval # - check_interval (X min -> Xm) + normal_check_interval
# - retry_interval (X min -> Xm) + retry_check_interval # - retry_interval (X min -> Xm) + retry_check_interval
# - notification_interval (X min -> Xm) # - 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! # - contacts => users XXX DO NOT DELETE contacts and contactgroups - they will be assembled later for notifications!
# - # -
# remove:
# - check_command
#################################################### ####################################################
########################################## ##########################################
@ -1306,24 +1314,10 @@ sub convert_2x {
$cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'address6'} = $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address6'}; $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'__I2CONVERT_MACROS'}->{'address6'} = $cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'address6'};
} }
########################################## ####################################################
# escape strings in attributes # migrate custom attributes
########################################## ####################################################
if(defined($cfg_obj_2x->{'host'}->{$host_obj_1x_key}->{'action_url'})) { $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});
$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'});
}
#################################################### ####################################################
# display_name -> alias mapping # display_name -> alias mapping
@ -1551,6 +1545,11 @@ sub convert_2x {
} }
} }
####################################################
# 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 # check if there are members defined, we must re-link them in their host object again
#################################################### ####################################################
@ -1599,6 +1598,11 @@ sub convert_2x {
} }
} }
####################################################
# 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 # check if there are members defined, we must re-link them in their service object again
#################################################### ####################################################
@ -1656,6 +1660,11 @@ sub convert_2x {
} }
} }
####################################################
# 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 # check if there are members defined, we must re-link them in their host object again
#################################################### ####################################################

View File

@ -419,26 +419,22 @@ sub dump_service_2x {
dump_config_line($icinga2_cfg, "\tcheck_period = \"$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, "\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'})) { if(defined($service_2x->{'volatile'})) {
dump_config_line($icinga2_cfg, "\tvolatile = $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, "}");
dump_config_line($icinga2_cfg, "\n"); dump_config_line($icinga2_cfg, "\n");
@ -586,32 +582,25 @@ sub dump_host_2x {
if(defined($host_2x->{'max_check_attempts'})) { if(defined($host_2x->{'max_check_attempts'})) {
dump_config_line($icinga2_cfg, "\tmax_check_attempts = $host_2x->{'max_check_attempts'},"); dump_config_line($icinga2_cfg, "\tmax_check_attempts = $host_2x->{'max_check_attempts'},");
} }
if(defined($host_2x->{'check_period'})) { if(defined($host_2x->{'check_period'})) {
dump_config_line($icinga2_cfg, "\tcheck_period = \"$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'}\","); # custom attr
} ####################################################
if(defined($host_2x->{'notes_url'})) { if(defined($host_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $host_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
dump_config_line($icinga2_cfg, "\tnotes_url = \"$host_2x->{'notes_url'}\","); 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}\",");
if(defined($host_2x->{'notes'})) { }
dump_config_line($icinga2_cfg, "\tnotes = \"$host_2x->{'notes'}\","); dump_config_line($icinga2_cfg, "\t},");
}
if(defined($host_2x->{'icon_image'})) {
dump_config_line($icinga2_cfg, "\ticon_image = \"$host_2x->{'icon_image'}\",");
}
if(defined($host_2x->{'statusmap_image'})) {
dump_config_line($icinga2_cfg, "\tstatusmap_image = $host_2x->{'statusmap_image'},");
} }
####################################################
# host with no services - valid configuration # host with no services - valid configuration
####################################################
if (!defined($host_2x->{'SERVICE'})) { if (!defined($host_2x->{'SERVICE'})) {
dump_config_line($icinga2_cfg, "}"); dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n"); dump_config_line($icinga2_cfg, "\n");
@ -752,28 +741,22 @@ sub dump_host_2x {
if(defined($service_2x->{'max_check_attempts'})) { if(defined($service_2x->{'max_check_attempts'})) {
dump_config_line($icinga2_cfg, "\t\tmax_check_attempts = $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'})) { if(defined($service_2x->{'check_period'})) {
dump_config_line($icinga2_cfg, "\tcheck_period = \"$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'}\","); # custom attr
} ####################################################
if(defined($service_2x->{'notes_url'})) { if(defined($service_2x->{'__I2CONVERT_CUSTOM_ATTR'}) && $service_2x->{'__I2CONVERT_CUSTOM_ATTR'} != 0) {
dump_config_line($icinga2_cfg, "\t\tnotes_url = \"$service_2x->{'notes_url'}\","); 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},");
if(defined($service_2x->{'notes'})) {
dump_config_line($icinga2_cfg, "\t\tnotes = \"$service_2x->{'notes'}\",");
} }
if(defined($service_2x->{'icon_image'})) {
dump_config_line($icinga2_cfg, "\t\ticon_image = \"$service_2x->{'icon_image'}\",");
}
dump_config_line($icinga2_cfg, "\t},"); dump_config_line($icinga2_cfg, "\t},");
dump_config_line($icinga2_cfg, ""); dump_config_line($icinga2_cfg, "");
} }
@ -855,6 +838,18 @@ sub dump_user_2x {
} }
} }
####################################################
# 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, "}"); dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n"); dump_config_line($icinga2_cfg, "\n");
@ -980,6 +975,19 @@ sub dump_group_2x {
if(defined($group_2x->{'display_name'})) { if(defined($group_2x->{'display_name'})) {
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$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, "}"); dump_config_line($icinga2_cfg, "}");
dump_config_line($icinga2_cfg, "\n"); dump_config_line($icinga2_cfg, "\n");