Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
|
|
|
|
=pod
|
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
|
|
|
package Icinga2::ExportIcinga2Cfg;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
use File::Find;
|
|
|
|
use Storable qw(dclone);
|
|
|
|
|
|
|
|
use feature 'say';
|
|
|
|
|
|
|
|
#use Icinga2;
|
|
|
|
use Icinga2::Utils;
|
|
|
|
|
|
|
|
#our $dbg_lvl = 1;
|
|
|
|
|
|
|
|
# XXX figure a better way for \t count printing, making dumps more modular
|
|
|
|
# XXX sort macros and linked hostservices by name
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Helpers
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub open_cfg_file {
|
|
|
|
my $file = shift;
|
|
|
|
my $FH;
|
|
|
|
|
|
|
|
say "opening file '$file'...\n";
|
|
|
|
open($FH, ">".$file);
|
|
|
|
|
|
|
|
return $FH;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub close_cfg_file {
|
|
|
|
my $FH = shift;
|
|
|
|
|
|
|
|
close($FH);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_header {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "/******************************************************************************");
|
|
|
|
dump_config_line($icinga2_cfg, " * GENERATED BY ICINGA2 CONVERSION SCRIPT");
|
|
|
|
dump_config_line($icinga2_cfg, " * (C) 2013 Icinga Development Team");
|
|
|
|
dump_config_line($icinga2_cfg, " * http://www.icinga.org");
|
|
|
|
dump_config_line($icinga2_cfg, " ******************************************************************************/");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_config_line {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $line = shift;
|
|
|
|
my $dbg_lvl = $icinga2_cfg->{'__I2EXPORT_DEBUG'};
|
|
|
|
|
|
|
|
if ($dbg_lvl) {
|
|
|
|
print $line. "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print { $icinga2_cfg->{'__I2EXPORT_FH'} } "$line\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub start_object_type_config_dump {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_type = shift;
|
|
|
|
|
|
|
|
$icinga2_cfg->{'__I2EXPORT_FH'} = open_cfg_file($icinga2_cfg->{$cfg_type});
|
|
|
|
add_header($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub end_object_type_config_dump {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
|
|
|
|
close_cfg_file($icinga2_cfg->{'__I2EXPORT_FH'});
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# DUMP ALL OBJECTS 2.x
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
sub dump_cfg_obj_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
dump_hosts_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_services_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_users_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_notifications_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_timeperiods_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_groups_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
dump_commands_2x($icinga2_cfg, $cfg_obj_2x);
|
|
|
|
|
|
|
|
}
|
|
|
|
sub dump_hosts_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'hosts');
|
|
|
|
#say Dumper($icinga2_cfg);
|
|
|
|
|
|
|
|
foreach my $host_2x_key (keys %{@$cfg_obj_2x{'host'}}) {
|
|
|
|
my $host_2x = @$cfg_obj_2x{'host'}->{$host_2x_key};
|
|
|
|
#say Dumper($host_2x);
|
|
|
|
#say "==============\n";
|
|
|
|
# function decides itsself if object or template
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_host_2x($icinga2_cfg, $host_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_services_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'services');
|
|
|
|
|
|
|
|
foreach my $service_2x_key (keys %{@$cfg_obj_2x{'service'}}) {
|
|
|
|
my $service_2x = @$cfg_obj_2x{'service'}->{$service_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_service_2x($icinga2_cfg, $service_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_users_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'users');
|
|
|
|
|
|
|
|
foreach my $user_2x_key (keys %{@$cfg_obj_2x{'user'}}) {
|
|
|
|
my $user_2x = @$cfg_obj_2x{'user'}->{$user_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_user_2x($icinga2_cfg, $user_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_notifications_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'notifications');
|
|
|
|
|
|
|
|
foreach my $notification_2x_key (keys %{@$cfg_obj_2x{'notification'}}) {
|
|
|
|
my $notification_2x = @$cfg_obj_2x{'notification'}->{$notification_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_notification_2x($icinga2_cfg, $notification_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub dump_timeperiods_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'timeperiods');
|
|
|
|
|
|
|
|
foreach my $timeperiod_2x_key (keys %{@$cfg_obj_2x{'timeperiod'}}) {
|
|
|
|
my $timeperiod_2x = @$cfg_obj_2x{'timeperiod'}->{$timeperiod_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_timeperiod_2x($icinga2_cfg, $timeperiod_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
# XXX maybe split later
|
|
|
|
sub dump_groups_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'groups');
|
|
|
|
|
|
|
|
foreach my $hostgroup_2x_key (keys %{@$cfg_obj_2x{'hostgroup'}}) {
|
|
|
|
my $hostgroup_2x = @$cfg_obj_2x{'hostgroup'}->{$hostgroup_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_group_2x($icinga2_cfg, $hostgroup_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $servicegroup_2x_key (keys %{@$cfg_obj_2x{'servicegroup'}}) {
|
|
|
|
my $servicegroup_2x = @$cfg_obj_2x{'servicegroup'}->{$servicegroup_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_group_2x($icinga2_cfg, $servicegroup_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $usergroup_2x_key (keys %{@$cfg_obj_2x{'usergroup'}}) {
|
|
|
|
my $usergroup_2x = @$cfg_obj_2x{'usergroup'}->{$usergroup_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_group_2x($icinga2_cfg, $usergroup_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_commands_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $cfg_obj_2x = shift;
|
|
|
|
|
|
|
|
start_object_type_config_dump($icinga2_cfg, 'commands');
|
|
|
|
|
|
|
|
foreach my $command_2x_key (keys %{@$cfg_obj_2x{'command'}}) {
|
|
|
|
my $command_2x = @$cfg_obj_2x{'command'}->{$command_2x_key};
|
|
|
|
|
|
|
|
Icinga2::ExportIcinga2Cfg::dump_command_2x($icinga2_cfg, $command_2x);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_object_type_config_dump($icinga2_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# DUMP OBJECT 2.x
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
sub dump_service_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $service_2x = shift;
|
|
|
|
my $object_type = "object"; # object or template
|
|
|
|
my $service_description = $service_2x->{__I2CONVERT_SERVICEDESCRIPTION};
|
|
|
|
|
|
|
|
# only dump templates, the objects will be directly created in host objects
|
|
|
|
if ($service_2x->{__I2CONVERT_IS_TEMPLATE} == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#say Dumper($host_2x);
|
|
|
|
if ($service_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$service_description = $service_2x->{'__I2CONVERT_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($service_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $service_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $service_2x_templates = join '", "', @{$service_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Service \"$service_description\" inherits \"$service_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Service \"$service_description\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# display_name
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$service_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# macros
|
|
|
|
####################################################
|
|
|
|
|
2013-06-24 17:03:34 +02:00
|
|
|
if(defined($service_2x->{'__I2CONVERT_MACROS'}) && $service_2x->{'__I2CONVERT_MACROS'} != 0) {
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "\tmacros = {");
|
2013-06-24 17:03:34 +02:00
|
|
|
foreach my $macro_key (keys %{$service_2x->{'__I2CONVERT_MACROS'}}) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$service_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# check command
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'__I2_CONVERT_CHECKCOMMAND_NAME'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tcheck_command = \"$service_2x->{'__I2_CONVERT_CHECKCOMMAND_NAME'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# event command
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'__I2_CONVERT_EVENTCOMMAND_NAME'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tevent_command = \"$service_2x->{'__I2_CONVERT_EVENTCOMMAND_NAME'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# servicegroups
|
|
|
|
####################################################
|
2013-06-25 13:16:10 +02:00
|
|
|
if(defined($service_2x->{'servicegroups'}) && scalar(@{$service_2x->{'servicegroups'}}) > 0) {
|
|
|
|
#say Dumper($service_2x->{'servicegroups'});
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
my $servicegroups = join '", "', @{$service_2x->{'servicegroups'}};
|
|
|
|
if ($service_2x->{'__I2_CONVERT_SG_ADD'} == 1) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tservicegroups += [ \"$servicegroups\" ],");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "\tservicegroups = [ \"$servicegroups\" ],");
|
|
|
|
}
|
2013-06-25 13:16:10 +02:00
|
|
|
#say Dumper($service_description);
|
|
|
|
#say Dumper($service_2x->{'servicegroups'});
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# servicedependencies (1.x deps)
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'__I2CONVERT_PARENT_SERVICES'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tservicedependencies = [");
|
|
|
|
|
|
|
|
#say Dumper($service_2x);
|
|
|
|
# this is a hash with keys
|
|
|
|
foreach my $servicedep_key (keys %{$service_2x->{'__I2CONVERT_PARENT_SERVICES'}}) {
|
|
|
|
my $servicedep = $service_2x->{'__I2CONVERT_PARENT_SERVICES'}->{$servicedep_key};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t{ host = \"$servicedep->{'host'}\", service = \"$servicedep->{'service'}\" },");
|
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "\t],");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# notifications
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'__I2CONVERT_NOTIFICATIONS'})) {
|
|
|
|
#say Dumper ($service_2x->{'__I2CONVERT_NOTIFICATIONS'});
|
|
|
|
# this is an array of notification objects
|
|
|
|
foreach my $service_notification_hash (@{$service_2x->{'__I2CONVERT_NOTIFICATIONS'}}) {
|
|
|
|
|
|
|
|
#say Dumper($service_notification_hash);
|
|
|
|
|
|
|
|
# this is a hash by unique key of the notification template, but all further attributes are seperatedly available too
|
|
|
|
foreach my $service_notification_key (keys %{$service_notification_hash}) {
|
|
|
|
my $service_notification = $service_notification_hash->{$service_notification_key};
|
|
|
|
#say Dumper($service_notification);
|
|
|
|
|
|
|
|
# skip everything not related to service notifications
|
|
|
|
next if ($service_notification->{'type'} ne 'service');
|
|
|
|
|
2013-06-24 22:15:00 +02:00
|
|
|
dump_config_line($icinga2_cfg, "\tnotifications[\"$service_notification->{'name'}\"] = {");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
|
|
|
|
if (defined ($service_notification->{'templates'}) && @{$service_notification->{'templates'}} > 0) {
|
|
|
|
my $service_notification_templates = join '", "', @{$service_notification->{'templates'}};
|
2013-06-24 22:15:00 +02:00
|
|
|
dump_config_line($icinga2_cfg, "\t\ttemplates = [ \"$service_notification_templates\" ],");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($service_notification->{'users'}) && @{$service_notification->{'users'}} > 0) {
|
|
|
|
my $service_users = join '", "', @{$service_notification->{'users'}};
|
2013-06-24 22:15:00 +02:00
|
|
|
dump_config_line($icinga2_cfg, "\t\tusers = [ \"$service_users\" ],");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
|
2013-06-24 22:15:00 +02:00
|
|
|
# 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 = {");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\tbegin = $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'begin'},");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\tend = $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'end'}");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t},");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($service_2x->{'notification_period'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tnotification_period = \"$service_2x->{'notification_period'}\",");
|
|
|
|
}
|
|
|
|
if(defined($service_2x->{'notification_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tnotification_interval = $service_2x->{'notification_interval'},");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# other service attributes, if set
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'check_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tcheck_interval = $service_2x->{'check_interval'},");
|
|
|
|
}
|
|
|
|
if(defined($service_2x->{'retry_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tretry_interval = $service_2x->{'retry_interval'},");
|
|
|
|
}
|
|
|
|
if(defined($service_2x->{'max_check_attempts'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\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, "\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'},");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_host_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $host_2x = shift;
|
|
|
|
my $object_type = "object"; # object or template
|
|
|
|
my $host_name = $host_2x->{'host_name'}; # default, may be changed for templates
|
|
|
|
|
|
|
|
#say Dumper($host_2x);
|
|
|
|
if ($host_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$host_name = $host_2x->{'__I2CONVERT_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($host_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $host_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $host_2x_templates = join '", "', @{$host_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Host \"$host_name\" inherits \"$host_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Host \"$host_name\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# display_name
|
|
|
|
####################################################
|
|
|
|
if(defined($host_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$host_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# macros
|
|
|
|
####################################################
|
2013-06-24 17:03:34 +02:00
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
|
|
|
|
if(defined($host_2x->{'__I2CONVERT_MACROS'}) && $host_2x->{'__I2CONVERT_MACROS'} != 0) {
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "\tmacros = {");
|
2013-06-24 17:03:34 +02:00
|
|
|
foreach my $macro_key (keys %{$host_2x->{'__I2CONVERT_MACROS'}}) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$host_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
|
|
|
|
}
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# hostcheck
|
|
|
|
####################################################
|
|
|
|
# this is magic, and must be set during conversion
|
|
|
|
if(defined($host_2x->{'__I2CONVERT_HOSTCHECK'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\thostcheck = \"$host_2x->{'__I2CONVERT_HOSTCHECK'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# hostgroups
|
|
|
|
####################################################
|
|
|
|
if(defined($host_2x->{'hostgroups'})) {
|
|
|
|
my $hostgroups = join '", "', @{$host_2x->{'hostgroups'}};
|
|
|
|
if ($host_2x->{'__I2_CONVERT_HG_ADD'} == 1) {
|
|
|
|
dump_config_line($icinga2_cfg, "\thostgroups += [ \"$hostgroups\" ],");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "\thostgroups = [ \"$hostgroups\" ],");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# hostdependencies (1.x deps and parents combined)
|
|
|
|
####################################################
|
|
|
|
if(defined($host_2x->{'__I2CONVERT_PARENT_HOSTNAMES'})) {
|
|
|
|
my $hostdependency_hosts = join '", "', @{$host_2x->{'__I2CONVERT_PARENT_HOSTNAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\thostdependencies = [ \"$hostdependency_hosts\" ],");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# notifications
|
|
|
|
####################################################
|
|
|
|
if(defined($host_2x->{'__I2CONVERT_NOTIFICATIONS'})) {
|
|
|
|
#say Dumper ($host_2x->{'__I2CONVERT_NOTIFICATIONS'});
|
|
|
|
# this is an array of notification objects
|
|
|
|
foreach my $host_notification_hash (@{$host_2x->{'__I2CONVERT_NOTIFICATIONS'}}) {
|
|
|
|
|
|
|
|
#say Dumper($host_notification_hash);
|
|
|
|
|
|
|
|
# this is a hash by unique key of the notification template, but all further attributes are seperatedly available too
|
|
|
|
foreach my $host_notification_key (keys %{$host_notification_hash}) {
|
|
|
|
my $host_notification = $host_notification_hash->{$host_notification_key};
|
|
|
|
#say Dumper($host_notification);
|
|
|
|
|
|
|
|
# skip everything not related to host notifications
|
|
|
|
next if ($host_notification->{'type'} ne 'host');
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tnotifications[\"$host_notification->{'name'}\"] = {");
|
|
|
|
|
|
|
|
if (defined ($host_notification->{'templates'}) && @{$host_notification->{'templates'}} > 0) {
|
|
|
|
my $host_notification_templates = join '", "', @{$host_notification->{'templates'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\ttemplates = [ \"$host_notification_templates\" ],");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($host_notification->{'users'}) && @{$host_notification->{'users'}} > 0) {
|
|
|
|
my $host_users = join '", "', @{$host_notification->{'users'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\tusers = [ \"$host_users\" ],");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t},");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(defined($host_2x->{'notification_period'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tnotification_period = \"$host_2x->{'notification_period'}\",");
|
|
|
|
}
|
|
|
|
if(defined($host_2x->{'notification_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tnotification_interval = $host_2x->{'notification_interval'},");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# other host attributes, if set
|
|
|
|
####################################################
|
|
|
|
if(defined($host_2x->{'check_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tcheck_interval = $host_2x->{'check_interval'},");
|
|
|
|
}
|
|
|
|
if(defined($host_2x->{'retry_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tretry_interval = $host_2x->{'retry_interval'},");
|
|
|
|
}
|
|
|
|
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'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($host_2x->{'statusmap_image'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tstatusmap_image = $host_2x->{'statusmap_image'},");
|
|
|
|
}
|
|
|
|
|
|
|
|
# host with no services - valid configuration
|
|
|
|
if (!defined($host_2x->{'SERVICE'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#say Dumper($host_2x->{'SERVICE'});
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# now all services with templates
|
|
|
|
####################################################
|
|
|
|
foreach my $service_2x_key (keys %{$host_2x->{'SERVICE'}}) {
|
|
|
|
my $service_2x = $host_2x->{'SERVICE'}->{$service_2x_key};
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\tservices[\"$service_2x->{__I2CONVERT_SERVICEDESCRIPTION}\"] = {");
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# templates
|
|
|
|
####################################################
|
|
|
|
if (defined($service_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $service_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $service_2x_templates = join '", "', @{$service_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\ttemplates = [ \"$service_2x_templates\" ],")
|
|
|
|
}
|
|
|
|
####################################################
|
|
|
|
# display_name
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tdisplay_name = \"$service_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
####################################################
|
|
|
|
# macros
|
|
|
|
####################################################
|
2013-06-24 17:03:34 +02:00
|
|
|
if(defined($service_2x->{'__I2CONVERT_MACROS'}) && $service_2x->{'__I2CONVERT_MACROS'} != 0) {
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "\t\tmacros = {");
|
2013-06-24 17:03:34 +02:00
|
|
|
foreach my $cmd_arg (keys %{$service_2x->{'__I2CONVERT_MACROS'}}) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\t$cmd_arg = \"$service_2x->{'__I2CONVERT_MACROS'}->{$cmd_arg}\",");
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t},");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# check_command
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'check_command'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tcheck_command = \"$service_2x->{'check_command'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# servicegroups
|
|
|
|
####################################################
|
2013-06-25 13:16:10 +02:00
|
|
|
if(defined($service_2x->{'servicegroups'}) && scalar(@{$service_2x->{'servicegroups'}}) > 0) {
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
#say Dumper($service_2x->{'servicegroups'});
|
|
|
|
my $servicegroups = join '", "', @{$service_2x->{'servicegroups'}};
|
|
|
|
if ($service_2x->{'__I2_CONVERT_SG_ADD'} == 1) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tservicegroups += [ \"$servicegroups\" ],");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tservicegroups = [ \"$servicegroups\" ],");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# notifications
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'__I2CONVERT_NOTIFICATIONS'})) {
|
|
|
|
#say Dumper ($service_2x->{'__I2CONVERT_NOTIFICATIONS'});
|
|
|
|
# this is an array of notification objects
|
|
|
|
foreach my $service_notification_hash (@{$service_2x->{'__I2CONVERT_NOTIFICATIONS'}}) {
|
|
|
|
|
|
|
|
#say Dumper($service_notification_hash);
|
|
|
|
|
|
|
|
# this is a hash by unique key of the notification template, but all further attributes are seperatedly available too
|
|
|
|
foreach my $service_notification_key (keys %{$service_notification_hash}) {
|
|
|
|
my $service_notification = $service_notification_hash->{$service_notification_key};
|
|
|
|
#say Dumper($service_notification);
|
|
|
|
|
|
|
|
# skip everything not related to service notifications
|
|
|
|
next if ($service_notification->{'type'} ne 'service');
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tnotifications[\"$service_notification->{'name'}\"] = {");
|
|
|
|
|
|
|
|
if (defined ($service_notification->{'templates'}) && @{$service_notification->{'templates'}} > 0) {
|
|
|
|
my $service_notification_templates = join '", "', @{$service_notification->{'templates'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\ttemplates = [ \"$service_notification_templates\" ],");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($service_notification->{'users'}) && @{$service_notification->{'users'}} > 0) {
|
|
|
|
my $service_users = join '", "', @{$service_notification->{'users'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\tusers = [ \"$service_users\" ],");
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:15:00 +02:00
|
|
|
# this is set for escalations
|
|
|
|
if(defined($service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}) && $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'} != 0) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\ttimes = {");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\t\tbegin = $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'begin'},");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\t\tend = $service_notification->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'end'}");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\t},");
|
|
|
|
}
|
|
|
|
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "\t\t},");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($service_2x->{'notification_period'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tnotification_period = \"$service_2x->{'notification_period'}\",");
|
|
|
|
}
|
|
|
|
if(defined($service_2x->{'notification_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tnotification_interval = $service_2x->{'notification_interval'},");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# other service attributes, if set
|
|
|
|
####################################################
|
|
|
|
if(defined($service_2x->{'check_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tcheck_interval = $service_2x->{'check_interval'},");
|
|
|
|
}
|
|
|
|
if(defined($service_2x->{'retry_interval'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tretry_interval = $service_2x->{'retry_interval'},");
|
|
|
|
}
|
|
|
|
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'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
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, "");
|
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_user_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $user_2x = shift;
|
|
|
|
my $object_type = "object"; # object or template
|
|
|
|
my $user_name = $user_2x->{'contact_name'}; # default, may be changed for templates
|
|
|
|
|
|
|
|
#say Dumper($user_2x);
|
|
|
|
if ($user_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$user_name = $user_2x->{'__I2CONVERT_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($user_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $user_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $user_2x_templates = join '", "', @{$user_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type User \"$user_name\" inherits \"$user_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type User \"$user_name\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($user_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$user_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
2013-06-24 17:03:34 +02:00
|
|
|
####################################################
|
|
|
|
# macros
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
if(defined($user_2x->{'__I2CONVERT_MACROS'}) && $user_2x->{'__I2CONVERT_MACROS'} != 0) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tmacros = {");
|
|
|
|
foreach my $macro_key (keys %{$user_2x->{'__I2CONVERT_MACROS'}}) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t$macro_key = \"$user_2x->{'__I2CONVERT_MACROS'}->{$macro_key}\",");
|
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
####################################################
|
|
|
|
# usergroups
|
|
|
|
####################################################
|
|
|
|
if(defined($user_2x->{'usergroups'})) {
|
|
|
|
#say Dumper($user_2x->{'usergroups'});
|
|
|
|
my $usergroups = join '", "', @{$user_2x->{'usergroups'}};
|
|
|
|
if ($user_2x->{'__I2_CONVERT_UG_ADD'} == 1) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tgroups += [ \"$usergroups\" ],");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "\tgroups = [ \"$usergroups\" ],");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_notification_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $notification_2x = shift;
|
|
|
|
my $object_type = "object"; # object or template
|
|
|
|
my $notification_name = $notification_2x->{'__I2CONVERT_NOTIFICATION_NAME'}; # default, may be changed for templates
|
|
|
|
|
|
|
|
#say Dumper($notification_2x);
|
|
|
|
if ($notification_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$notification_name = $notification_2x->{'__I2CONVERT_NOTIFICATION_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:15:00 +02:00
|
|
|
return if (!defined($notification_name));
|
|
|
|
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($notification_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $notification_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $notification_2x_templates = join '", "', @{$notification_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Notification \"$notification_name\" inherits \"$notification_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type Notification \"$notification_name\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($notification_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$notification_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($notification_2x->{'__I2CONVERT_NOTIFICATION_COMMAND'})) {
|
|
|
|
#say Dumper($notifications_2x->{'notification_command'});
|
|
|
|
dump_config_line($icinga2_cfg, "\tnotification_command = \"$notification_2x->{'__I2CONVERT_NOTIFICATION_COMMAND'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($notification_2x->{'export_macros'})) {
|
|
|
|
#say Dumper($notification_2x->{'export_macros'});
|
|
|
|
my $export_macros = join '",\n"', @{$notification_2x->{'export_macros'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\texport_macros = [ \"$export_macros\" ],");
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:15:00 +02:00
|
|
|
if(defined($notification_2x->{'users'}) && @{$notification_2x->{'users'}} > 0) {
|
|
|
|
my $service_users = join '", "', @{$notification_2x->{'users'}};
|
|
|
|
dump_config_line($icinga2_cfg, "\tusers = [ \"$service_users\" ],");
|
|
|
|
}
|
|
|
|
|
|
|
|
# this is set for escalations
|
|
|
|
if(defined($notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'}) && $notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'} != 0) {
|
|
|
|
dump_config_line($icinga2_cfg, "\ttimes = {");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tbegin = $notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'begin'},");
|
|
|
|
dump_config_line($icinga2_cfg, "\t\tend = $notification_2x->{'__I2CONVERT_NOTIFICATION_TIMES'}->{'end'}");
|
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
|
|
|
}
|
|
|
|
|
Config Conversion: add conversion script
Squashed Rebase, commit msg below.
convertv1->v2 initial import
refs #2743
itl: fix inclusion of notification.conf
Config Conversion: command macros, templates
refs #2743
WIP: try resolving the host->svc relation from templates and tricks
not finished yet, there's heavy recursion required
WIP configconversion: rewrite recursive lookup of linked host_name/service_description
this is a mess. configs may just use "name" instead of "host_name" on
type "host", same goes for service and service_descriptions. well, and
if it's a template, "name" is populated too.
the algorithm is not clean enough, and does not scale at all. there are
bugs, and the hostgroup linking is not yet taken into account too.
basics host -> service dumping of v2 config is implemented.
refs #2743
ConfigConvert: split into modules, add objects.cache read, dump cmd line
basically it works with
- dumping a host with all services, using templates
- check_command and all arguments/user macros translation
- reading the objects.cache file location from icinga.cfg
=> this is reserved only for getting dedicated relations
=> we do not want to duplicate the work of xodtemplate.c in perl here
- all important functions have been split up into their respective
modules in order to support better re-usage (i.e. lconfexport)
still missing important bits:
- detect service->group<-host links and build templates
- detect other ugly template methods
- dump templates
- the ugly deprecated normal|retry_check_interval mapping
- timeperiod mapping
- contact => user mapping
- notifications rework (dedicated object)
- dependencies, escalations (to be documented/implemented)
- the infamous rest
ConfigConvert: fix hash keys for convert/dump in perl 5.14
ConfigConvert: improved template handling, host/service dump 2x
refactored code again, removed nested loop bottlenecks. still, the
resolval of host_name/service_description requires more love.
templates are now correctly detected, linked, and printed in 2x syntax.
service templates are _not_ linked against host definitions in 2x as
this is not possible.
commands for hosts do not exist in 2x, therefore the command_name of an
1x host will be taken and guessed against its related services. if
there's a match, the service will be linked as 2x 'hostcheck'.
*_interval still needs proper handling, as the default interval is 1m,
but 2x requires the identifier.
ConfigConvert: refactor host_name/service_description link resolving
previous algorithm was buggy, as well get_host_name always looked up
host template objects, even if the template object was a service. this
is now fixed by re-using the __TYPE attribute (set on Icinga 1x config
read).
the algorithm is now like
|---------------------------------|
\/ |
svc_desc? |
0 / \ 1 |
use tmpl? END -------> [svc_desc] |
0 / \ 1 |
[undef] <- BROKEN getobjbyattr(['use'], __TYPE, svcdesc |
| |
getsvcdesc(obj) |
| |
--------------------------------------
refs #2743
ConvertConfig: add basic support for users, timeperiods, *groups
as well as display_name as attribute to print something.
contact => user mapping is added as well, manipulating the __TYPE var
too. furthermore display_name on the host will be overwritten by the
alias, if set.
the groups don't dump much, only the display_name if set. their dump
function is implemented generic, based on the __TYPE
ConfigConvert: fix 4 little big thinkos on import/convert/dump
1) do not skip lines containing ;.* - there may actually be a comment on
attr->val line. rather clean the line safely, and let the magic happen.
2) the type counter was implemented in order to have unique object ids
by type, since 1x config does not provide us with such. problem - the
function had a local var, saving the counter for each file, overwriting
the hash attributes later on, starting again with 0. nasty bug, hard to
figure out. fixed by feeding the type_cnt into the cfg_obj hive for now.
revamped the state machine logic as well, like so
I: define TYPE { --> __TYPE = TYPE
II: attr val --> {type}->{type_cnt->cnt}->{attr} = val
III: } --> type_cnt->cnt++
IV: <empty/comment>
3) also skip service templates (__IS_TEMPLATE) sooner, and do not try to
calculate some host_name/service_description magic out of them - they
just can't go down one level to the host, but only up with 'use'.
4) host and service templates on 2x config dump must check if
__USES_TEMPLATE is actually set to 1, checking for defined is not
enough.
whatthecommit.com:
A long time ago, in a galaxy far far away...
refs #2743
ConfigConvert: add more host/service attributes, groups
*_interval are automatically mapped, while the *groups attribute it
converted into an array in order to easily stash more groups on it.
still a todo - loop over existing groups and re-link their members into
the respective objects, as 2.x only supports that location.
fix for the host->service relation - use the already processed service
2x hashref in order to do some magic with host->{'SERVICE'} = service
all 2x attributes are now encapsulated with "", to stay safe.
todo - more generic config 2x dump.
furthermore, add some more code comments for the respective sections.
refs #2743
ConfigConvert: fix service linking not unique, add hostgroup->members re-link to host->hostgroups
while working on the missing servicegroups and their facepalm members
syntax (host1,svc1,host2,svc2 - awesome to parse), i figured that the
whole detection of services by their attribute 'service_description' is
not uniquely implemented. now the getter functions are duplicated, and
not modular anymore, for the sake of having a service identified by its
host_name + service_description. since that lookup is recursive, we must
pass the host_name from the very beginning - otherwise we could
accidently overwrite that with a template entry.
the hostgroup re-linking works, also thanks to the fact that the inner
object structure is just an array in the hashref, which allows smart
push.
contact/user groups are tricky again due to the different naming.
further todo: sort all macros and hostservice links. right now this
looks like chaos.
refs #2743
ConfigConvert: basic servicegroup parsing method
ConfigConvert: refactor multiple host_name's on service object detection
this is ugly. a service object may contain 'host_name' with
'host1,host2,host3' and so on. treating this as string won't allow us to
look into the template tree for valid host attributes, so we need to
rewrite the getter function, allowing some special treatment on
host_name arrays.
for the service object preparation this means: while in the service
loop, we need to loop again over all hosts, then dclone the hashref
object for the service, and add the unique host_name attribute again.
we might require some loop unrolling later, but for now this works as
expected.
refs #2743
ConvertConfig: disable debug output, some reformatting of dump
ConfigConvert: refactor host-svc links, add full service/usergroup relinking
due to the relinking afterwards we actually modify the service objects
already prepared for 2x. since the *group magic depends on the
host/services/users already prepared, we get a perpetuum mobile here
with the host loop and resolving service relations.
in order to safely fix the issue, there's a seperate host-service link
loop after resolving all the other needed objects, which may cost a
little bit more performance, but is safe and standalone, getting all
previous modifications, migrations and also hacks.
next to the refactored flow, the issue with resolving the correct
servicegroups and stashing them into an array is solved, as well as
converting the existing contactgroups to usergroups, as well as
re-linking existing contactgroup->members to their new home,
user->usergroups.
note: when parsing the servicegroup members into an array, it must not
be sorted afterwards, because we will shift 2 objects (host, service) in
order to identify the correct service object for adding the servicegroup
item.
some code reorganisation too, plus a minor comma fix for the host
address macro.
the used 1x configuration will be addressed in 2743.cfg on
icinga-core.git, with all future additions.
refs #2743
ConfigConvert: *interval, max_check_attempts dumped as numbers
see
https://git.icinga.org/?p=icinga2.git;a=blob_plain;f=lib/icinga/icinga-type.conf;hb=HEAD
refs #2743
ConfigConvert: fix undocumented contact templates conversion
refs #2743
s/DumpIcinga2Cfg/ExportIcinga2Cfg/g
just for Import/Export clarification.
configconvert: use special prefix for internal attributes
__I2CONVERT_ should do the trick, not to interfere with existing custom
variables.
configconvert: fix leftover from rename
configconvert: properly escape strings with double quotes
* command_line and command_args
* notification commands
* action_url, notes_url
* notes
* icon_image, icon_image_alt
fixes #3931
configconvert: fix multiple templates usage, template object lookup error
multiple host/service templates seperated by commas will cause some
irritation, therefore this is treated as array internally, like group
members. for the config export and "inherits", this is easy to fix. for
the actual host_name lookup for service objects, this unveiled another
bug when looping through all available templates - they are unique by
'name' and not by hostname/servicedesc, and require their very own
getter - obj_get_tmpl_obj_by_tmpl_name() - which makes sure to return
the object which is then looked into recursively if there's a host_name
provided.
possible bug for now - multiple service templates used and the host_name is
defined in one of them. but that's not the usual case, and won't be
supported for now.
refs #2743
fixes #3932
configconvert: dump modular timperiod attr and values
we need to ignore all other attributes which are to be cleaned sooner,
just for safety.
minor flaw: the keys are not sorted by weekdays now, but dumped like the
hash provides them.
fixes #4013
configconvert: support 'name' for groups' if *group_name is not set
this is a fallback for broken configs only, and since i got some, added
a small fix.
refs #2743
configconvert: add service->hostgroup<-hostmembers conversion to template support
WIP: there's multiple service->hostgroup relations - duplicated hosthg
templates. must be fixed.
refs #2743
refs #4016
configconvert: refactor service-hg-hosts for one hosthg template and multiple services
we need to first loop over all services, getting the key ids, collecting
them for each hostgroup_name (this is the unique identifier, because
this is our hosthg template later on).
then we loop over the collected unique hostgroups and build the 2.x
template logic. the difference here is now, that the code is refactored,
and loops over the service keys (getting their objects) only once,
pushing their templates plus a relation to a single (1) hosthg-template.
there's still some space for enhancements - the service template names
as well as hosthg template names as well as service object names are
generated with some hardcoded strings/numbers.
refs #2743
refs #4016
configconversion: remove debug output
configconvert: only dump macros if there are key-val pairs
configconvert: code cleanup
configconversion: explicitely check __I2CONVERT_USES_TEMPLATE == 1 when dumping service templates
refs #4020
configconvert: refactor how services without host_name are handled
this is mainly the cause when using hostgroup relations, or other object
tricks. we still need the single loop run to convert all 2.x object
attributes in one run, and deal with the missing attributes later on.
configconvert: WIP notification conversion
- refactored notification_commands parsing and storage
- do not add duplicated notification_command names to the 2x
notification object hive
- create notifications based on the notification command linked from
users
- move host->service link magic to the end again
refs #4008
configconvert: WIP notifications, how service/hosts relate to users and notifications
there may be more than one notification for the user, and we already had
the type in place. currently, that type is not taken into account (bug
to fix).
the rest with service -> user -> notification linking works in the first
implementation.
refs #4008
configconvert: final stage, rework notification type handling, fix naming amd template output
the config dump must take care of which notification type is dumped,
otherwise there would be yet another look required. Instead we are just
passing a reference from users to hosts/services with all prepared
notification attributes, and check them lazy on dump then.
further fixe on the notification names - they are not unique by their
command (now used on host/service scope, not user/contact) so we'll add
some magic number as suffix.
fixed template name dumping due to changed conversion vars too.
refs #4008
configconvert: write config files, refactor how objects are exported
structure is currently hardcoded, but may be changed to getopts later
on. all files are overridden into conf/ (testing only right on).
refactored export code, removed everything from Convert.pm, and export
is now called from the script directly, wrapped all dump loops and added
more function layers in betweed. open/close file handles take care of
everything, next to a header on top of the files for getting to know
their origin better (our hard work, ey?).
refs #4036
configconvert: fix service description handling, it's now an inner conversion value
previously, i've just re-used 'service_description' which isn't a valid
2.x attribute either. the lookup of service_description attribute in 1.x
templates works already, but populated __I2CONVERT_SERVICEDESCRIPTION
instead. in favor of having a generated value for all our objects, we'll
use that one, also for dumping the configuration.
even further, this is also changed for the service->hostgroup<-hosts
conversion then.
this also avoids writing empty service names into host->service objects.
fixes #4019
configconvert: add small main config file for standalone tests
refs #2743
configconvert: s/usergroups/groups/ for User config dump
configconvert: add README
configconvert: add ITL templates automatically (for services, notifications)
this currently only makes sense for services and notifications.
refs #4037
configconvert: fix timeperiod ranges, add template support for ITL inherits
refs #4037
refs #4013
configconvert: update requirements, perl deps
refs #2743
configconvert: fix import parser - timeperiods require regex (thx LConfImport)
somehow, the Icinga2 import still fails with us holiday definitions. bug
that's not yet determined whose bug that is.
refs #4039
refs #4013
configconvert: add getopts and pod2usage incl help
fixes #4041
configconvert: add notification_interval|period
and refactor check|retry_interval vs normal|retry_check_interval
refs #4008
configconvert: make host->service linked service a template object, referenced by the host
this is not the best solution, as it it creates a service template for
each host-service relation. if you have many host_name entries defined
in your Icinga 1.x config for a service, this will create duplicates
then. requires some more code refactoring, therefore leaving the issue
open.
refs #3933
configconvert: drop config file prefix 'icinga2'
just makes it hard to work with.
refs #4036
configconvert: code cleanup
configconvert: export check_period for hosts/services
refs #2743
configconvert: WIP dependencies - for host based on host_name and parents
refs #4011
configconvert: s/Timeperiod/TimePeriod/g
refs #4013
configconvert: add hostdependency with hostgroup_name hosts unrolling
refs #4011
configconvert: add servicedependency support (host_name)
missing - the loop fun with hostgroups.
special config is here:
https://git.icinga.org/?p=icinga-core.git;a=blob;f=tests/etc/2743.cfg;hb=refs/heads/next#l376
refs #4011
configconvert: add service dependency support for hostgroups
well, a lot of looping required here:
- loop through all child hostgroup hosts and get their hostnames
- get the servive object based on each hostname (loop again) and
the child service description
- loop through all master hostgroup hosts and get their hostnames
- get the master hostname based on each hostname (loop again) and
the master service description, save that as service dependency
given that implementation, dependencies may be converted for now.
once we decide which options we support, we may add them as well.
refs #4011
configconvert: add support for * as service host_name next to comma seperated list
this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.
http://docs.icinga.org/latest/en/objecttricks.html
refs #4010
configconvert: refactor commaseperated list split
... to list of stripped strings into a function.
fixes #4046
configconvert: handle excluded hosts, ignore them on split to array
exclusions/exceptions cannot be treated by icinga2 the same way as in
1.x so it's better to not create unwanted objects.
fixes #4007
configconvert: replace colon in object names with underscore
it's a special delimiter and therefore forbidden.
fixes #4225
configconvert: detect additive inheritance for *groups and use += on export
i guess this can be used for host/service contact(groups) and other foo
as well, so let's see.
refs #4006
configconvert: add wildcard detection for 'members *' in hostgroup
currently adds itself to the host's hostgroups array, but maybe a global
template where all hosts inherit from, plus additive inheritance fit
better here.
refs #4010
configconvert: add a note about servicedeps wildcards todo
refs #4010
configconvert: svg-hg-hst logic may contain multiple hgnames for services
the object tricks section on the 1.x documentation contains everything
which makes the code less readable even here.
luckily the code is rather modular, so the extension for split string to
array, and looping doesn't hurt much.
refs #4010
configconvert: update README with usage and todos
refs #2743
configconvert: fix perl 5.14, skip non-existing objects
configconvert: escape display_name (may contain quotes)
refs #3931
configconvert: refactor using command objects (check/notification)
eventhandlers are missing.
fixes #4305
configconvert: add volatile attribute
fixes #4321
configconvert: eventhandler as EventCommand objects
fixes #4327
update TODOs
configconvert: remove obsolete itl notification template
and check if defined when used.
refs #2743
configconvert: write compat log too in icinga2 conf
Revert "itl: fix inclusion of notification.conf"
This reverts commit 02eb54dc1a818fdcafa6c85817e9f6341cf2831a.
configconvert: fix thinko with check_command|event_command in service
refs #2743
refs #4327
refs #4305
2013-03-12 17:40:53 +01:00
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub dump_timeperiod_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $object_type = "object"; # object or template
|
|
|
|
my $timeperiod_2x = shift;
|
|
|
|
my $timeperiod_name = $timeperiod_2x->{'timeperiod_name'};
|
|
|
|
|
|
|
|
#say Dumper($timeperiod_2x);
|
|
|
|
if ($timeperiod_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$timeperiod_name = $timeperiod_2x->{'__I2CONVERT_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($timeperiod_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $timeperiod_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $timeperiod_2x_templates = join '", "', @{$timeperiod_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type TimePeriod \"$timeperiod_name\" inherits \"$timeperiod_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type TimePeriod \"$timeperiod_name\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
# display_name is seperated at first position
|
|
|
|
if(defined($timeperiod_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$timeperiod_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\tranges = {");
|
|
|
|
|
|
|
|
# dump all possible keys (there's no fixed string attr here)
|
|
|
|
foreach my $key (sort (keys %{$timeperiod_2x})) {
|
|
|
|
if ($key !~ /__I2CONVERT/ &&
|
|
|
|
$key ne 'alias' &&
|
|
|
|
$key ne 'name' &&
|
|
|
|
$key ne 'timeperiod_name' &&
|
|
|
|
$key ne 'display_name' &&
|
|
|
|
$key ne 'use'
|
|
|
|
) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t\"$key\" \t= \"$timeperiod_2x->{$key}\",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "\t},");
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_group_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $group_2x = shift;
|
|
|
|
my $group_name_attr = $group_2x->{__I2CONVERT_TYPE} . "_name";
|
|
|
|
my $group_name = $group_2x->{$group_name_attr};
|
|
|
|
my $group_type = ucfirst("$group_2x->{__I2CONVERT_TYPE}");
|
|
|
|
$group_type =~ s/group/Group/;
|
|
|
|
|
|
|
|
#say Dumper($group_2x);
|
|
|
|
|
|
|
|
dump_config_line($icinga2_cfg, "object $group_type \"$group_name\" {");
|
|
|
|
if(defined($group_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$group_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
dump_config_line($icinga2_cfg, "");
|
|
|
|
dump_config_line($icinga2_cfg, "}");
|
|
|
|
dump_config_line($icinga2_cfg, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub dump_command_2x {
|
|
|
|
my $icinga2_cfg = shift;
|
|
|
|
my $command_2x = shift;
|
|
|
|
my $command_name = $command_2x->{'__I2CONVERT_COMMAND_NAME'};
|
|
|
|
my $command_line = $command_2x->{'__I2CONVERT_COMMAND_LINE'};
|
|
|
|
my $command_type = ucfirst("$command_2x->{__I2CONVERT_COMMAND_TYPE}Command");
|
|
|
|
my $object_type = "object";
|
|
|
|
|
|
|
|
#say Dumper($command_2x);
|
|
|
|
|
|
|
|
if ($command_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
|
|
|
|
$object_type = "template";
|
|
|
|
$command_name = $command_2x->{'__I2CONVERT_TEMPLATE_NAME'};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# start, inherit from template?
|
|
|
|
####################################################
|
|
|
|
if (defined($command_2x->{'__I2CONVERT_USES_TEMPLATE'}) && $command_2x->{'__I2CONVERT_USES_TEMPLATE'} == 1) {
|
|
|
|
my $command_2x_templates = join '", "', @{$command_2x->{'__I2CONVERT_TEMPLATE_NAMES'}};
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type $command_type \"$command_name\" inherits \"$command_2x_templates\" {");
|
|
|
|
} else {
|
|
|
|
dump_config_line($icinga2_cfg, "$object_type $command_type \"$command_name\" {");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# attributes
|
|
|
|
####################################################
|
|
|
|
if(defined($command_2x->{'display_name'})) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tdisplay_name = \"$command_2x->{'display_name'}\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined($command_line)) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tcommand = \"$command_line\",");
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# macros
|
|
|
|
####################################################
|
|
|
|
|
|
|
|
if(defined($command_2x->{'__I2CONVERT_COMMAND_MACROS'}) && $command_2x->{'__I2CONVERT_COMMAND_MACROS'} != 0) {
|
|
|
|
dump_config_line($icinga2_cfg, "\tmacros = {");
|
|
|
|
foreach my $cmd_arg (keys %{$command_2x->{'__I2CONVERT_COMMAND_MACROS'}}) {
|
|
|
|
dump_config_line($icinga2_cfg, "\t\t$cmd_arg = \"$command_2x->{'__I2CONVERT_COMMAND_MACROS'}->{$cmd_arg}\",");
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
# vi: sw=4 ts=4 expandtab :
|