mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
parent
f30b164692
commit
df42a701d1
@ -29,6 +29,7 @@ icinga2-migrate-config - Migrate Icinga 1.x config to Icinga 2 format
|
|||||||
|
|
||||||
icinga2-migrate-config -c <path to icinga.cfg from Icinga 1.x>
|
icinga2-migrate-config -c <path to icinga.cfg from Icinga 1.x>
|
||||||
-o <output directory for Icinga 2 config>
|
-o <output directory for Icinga 2 config>
|
||||||
|
[-O]
|
||||||
[-v]
|
[-v]
|
||||||
[-h]
|
[-h]
|
||||||
[-V]
|
[-V]
|
||||||
@ -47,6 +48,10 @@ Path to the Icinga 1.x main configuration file "icinga.cfg".
|
|||||||
|
|
||||||
Directory to the Icinga 2 configuration output.
|
Directory to the Icinga 2 configuration output.
|
||||||
|
|
||||||
|
=item -O|--objectscache
|
||||||
|
|
||||||
|
Use objects cache file instead of cfg_dir|file in icinga.cfg.
|
||||||
|
|
||||||
=item --hosttmpl=<template name>
|
=item --hosttmpl=<template name>
|
||||||
|
|
||||||
Custom template name for all host objects.
|
Custom template name for all host objects.
|
||||||
@ -112,6 +117,7 @@ our $opt;
|
|||||||
GetOptions(
|
GetOptions(
|
||||||
"c|icingacfgfile=s" => \$opt->{icinga1xcfg},
|
"c|icingacfgfile=s" => \$opt->{icinga1xcfg},
|
||||||
"o|outputcfgdir=s" => \$opt->{icinga2xoutputprefix},
|
"o|outputcfgdir=s" => \$opt->{icinga2xoutputprefix},
|
||||||
|
"O|objectscache" => \$opt->{icinga1xobjectscache},
|
||||||
"hosttmpl=s" => \$opt->{hosttmpl},
|
"hosttmpl=s" => \$opt->{hosttmpl},
|
||||||
"servicetmpl=s" => \$opt->{servicetmpl},
|
"servicetmpl=s" => \$opt->{servicetmpl},
|
||||||
"usertmpl=s" => \$opt->{usertmpl},
|
"usertmpl=s" => \$opt->{usertmpl},
|
||||||
@ -216,14 +222,23 @@ if ( !-f $icinga1_cfg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# the import
|
# the import
|
||||||
my $icinga1_cfg_obj = parse_icinga1_objects($icinga1_cfg);
|
debug("Start Icinga 1.x config import @".time);
|
||||||
my $icinga1_cfg_obj_cache = parse_icinga1_objects_cache($icinga1_cfg);
|
my $icinga1_cfg_obj;
|
||||||
|
if (!defined($opt->{icinga1xobjectscache})) {
|
||||||
|
$icinga1_cfg_obj = parse_icinga1_objects($icinga1_cfg);
|
||||||
|
} else {
|
||||||
|
$icinga1_cfg_obj = parse_icinga1_objects_cache($icinga1_cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
# global macros
|
||||||
my $icinga1_global_macros = parse_icinga1_global_macros($icinga1_cfg);
|
my $icinga1_global_macros = parse_icinga1_global_macros($icinga1_cfg);
|
||||||
|
|
||||||
# the conversion magic inside
|
# the conversion magic inside
|
||||||
|
debug("Start Icinga 1.x config migration @".time);
|
||||||
my $icinga2_cfg_obj = migrate_2x($icinga2_cfg, $icinga1_cfg_obj, $icinga1_cfg_obj_cache, $icinga1_global_macros);
|
my $icinga2_cfg_obj = migrate_2x($icinga2_cfg, $icinga1_cfg_obj, $icinga1_cfg_obj_cache, $icinga1_global_macros);
|
||||||
|
|
||||||
# the export
|
# the export
|
||||||
|
debug("Dump Icinga 2.x config @".time);
|
||||||
dump_cfg_resource_2x($icinga2_cfg, $icinga1_global_macros);
|
dump_cfg_resource_2x($icinga2_cfg, $icinga1_global_macros);
|
||||||
dump_cfg_obj_2x($icinga2_cfg, $icinga2_cfg_obj);
|
dump_cfg_obj_2x($icinga2_cfg, $icinga2_cfg_obj);
|
||||||
|
|
||||||
@ -234,6 +249,7 @@ print "######################################################################\n"
|
|||||||
|
|
||||||
print_sorted_hash($icinga2_cfg_obj->{'__I2_CONVERT_STATS'});
|
print_sorted_hash($icinga2_cfg_obj->{'__I2_CONVERT_STATS'});
|
||||||
|
|
||||||
|
debug("Icinga 2.x config migratione done @".time);
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
IMPORT OPTIONS
|
IMPORT OPTIONS
|
||||||
@ -448,9 +464,6 @@ sub parse_icinga1_object_cfg {
|
|||||||
sub parse_icinga1_objects_cache {
|
sub parse_icinga1_objects_cache {
|
||||||
my $icinga1_cfg = shift;
|
my $icinga1_cfg = shift;
|
||||||
|
|
||||||
# XXX not needed right now
|
|
||||||
return undef;
|
|
||||||
|
|
||||||
# functions return array in case of multiple occurences, we'll take only the first one
|
# functions return array in case of multiple occurences, we'll take only the first one
|
||||||
my ($object_cache_file) = get_key_from_icinga1_main_cfg($icinga1_cfg, "object_cache_file");
|
my ($object_cache_file) = get_key_from_icinga1_main_cfg($icinga1_cfg, "object_cache_file");
|
||||||
|
|
||||||
@ -466,6 +479,7 @@ sub parse_icinga1_objects_cache {
|
|||||||
|
|
||||||
my $cfg_obj_cache = {};
|
my $cfg_obj_cache = {};
|
||||||
|
|
||||||
|
print "Processing file '$cfg_file'...\n";
|
||||||
$cfg_obj_cache = parse_icinga1_object_cfg($cfg_obj_cache, $object_cache_file);
|
$cfg_obj_cache = parse_icinga1_object_cfg($cfg_obj_cache, $object_cache_file);
|
||||||
|
|
||||||
#say Dumper($cfg_obj_cache);
|
#say Dumper($cfg_obj_cache);
|
||||||
@ -754,15 +768,16 @@ sub obj_get_tmpl_obj_by_tmpl_name {
|
|||||||
my $objs = shift;
|
my $objs = shift;
|
||||||
my $obj_tmpl_type = shift;
|
my $obj_tmpl_type = shift;
|
||||||
my $obj_attr_tmpl_name = shift;
|
my $obj_attr_tmpl_name = shift;
|
||||||
|
my $obj_attr = 'name';
|
||||||
|
|
||||||
#debug("My objects hive: ".Dumper($objs));
|
#debug("My objects hive: ".Dumper($objs));
|
||||||
|
|
||||||
#debug("Checking for template name with $obj_attr_tmpl_name");
|
#debug("Checking for template name with $obj_attr_tmpl_name");
|
||||||
foreach my $obj_key (keys %{@$objs{$obj_tmpl_type}}) {
|
foreach my $obj_key (keys %{@$objs{$obj_tmpl_type}}) {
|
||||||
my $obj = @$objs{$obj_tmpl_type}->{$obj_key};
|
my $obj = @$objs{$obj_tmpl_type}->{$obj_key};
|
||||||
next if !defined($obj->{'name'});
|
next if !defined($obj->{$obj_attr});
|
||||||
# XXX it would be safe, but we cannot garantuee it here, so better check before if we want a template or not
|
# XXX it would be safe, but we cannot garantuee it here, so better check before if we want a template or not
|
||||||
if ($obj->{'name'} eq $obj_attr_tmpl_name) {
|
if ($obj->{$obj_attr} eq $obj_attr_tmpl_name) {
|
||||||
#debug("Found object: ".Dumper($obj));
|
#debug("Found object: ".Dumper($obj));
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
@ -3185,7 +3200,7 @@ sub migrate_2x {
|
|||||||
|
|
||||||
$service_object_cnt++;
|
$service_object_cnt++;
|
||||||
|
|
||||||
say "service object count " . keys %{@$cfg_obj_2x{'service'}};
|
debug("HOST->SERVICE RELATION START: service object count " . keys %{@$cfg_obj_2x{'service'}});
|
||||||
|
|
||||||
# "get all 'host' hashref as array in hashmap, and their keys to access it"
|
# "get all 'host' hashref as array in hashmap, and their keys to access it"
|
||||||
foreach my $host_obj_2x_key (keys %{@$cfg_obj_2x{'host'}}) {
|
foreach my $host_obj_2x_key (keys %{@$cfg_obj_2x{'host'}}) {
|
||||||
@ -3373,7 +3388,7 @@ sub migrate_2x {
|
|||||||
# services assigned
|
# services assigned
|
||||||
######################################
|
######################################
|
||||||
if ($obj_2x_host_service_cnt == 0 && $obj_2x_host->{'__I2CONVERT_IS_TEMPLATE'} == 0) {
|
if ($obj_2x_host_service_cnt == 0 && $obj_2x_host->{'__I2CONVERT_IS_TEMPLATE'} == 0) {
|
||||||
say "Found host '". $obj_2x_host->{'__I2CONVERT_HOSTNAME'} ."' without any services";
|
debug("Found host '". $obj_2x_host->{'__I2CONVERT_HOSTNAME'} ."' without any services");
|
||||||
|
|
||||||
# now, add the hostcheck service
|
# now, add the hostcheck service
|
||||||
my ($host_check_command_2x, @host_command_args_1x) = convert_checkcommand($cfg_obj_1x, @$cfg_obj_1x{'command'}, $obj_2x_host, $obj_2x_host->{'__I2CONVERT_HOSTNAME'} , $global_macros_1x);
|
my ($host_check_command_2x, @host_command_args_1x) = convert_checkcommand($cfg_obj_1x, @$cfg_obj_1x{'command'}, $obj_2x_host, $obj_2x_host->{'__I2CONVERT_HOSTNAME'} , $global_macros_1x);
|
||||||
@ -4596,8 +4611,8 @@ sub errlog {
|
|||||||
sub escape_str {
|
sub escape_str {
|
||||||
my $str = shift;
|
my $str = shift;
|
||||||
|
|
||||||
|
$str =~s/\\/\\\\/g;
|
||||||
$str =~ s/"/\\"/g;
|
$str =~ s/"/\\"/g;
|
||||||
$str =~ s/\\\\"/\\"/g;
|
|
||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user