[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: svg-hg-hst logic may contain multiple hgnames for services

git at icinga.org git at icinga.org
Tue May 28 20:13:19 CEST 2013


Module: icinga2
Branch: feature/configconvert-2743
Commit: f4e82457eb3d3abdcd25ccbc6d34689b6260a1d0
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=f4e82457eb3d3abdcd25ccbc6d34689b6260a1d0

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue May 28 20:11:40 2013 +0200

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

---

 contrib/configconvert/Icinga2/Convert.pm |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 8d8c054..8040aab 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1378,10 +1378,15 @@ sub convert_2x {
         # skip all services without hostgroup_name
         next if(!defined($obj_2x_service->{'hostgroup_name'}));
 
-        # we need to save all services first, but our new key is the hostgroupname
-        # so that we can create multiple services for a single hosthg template later on
-        push @{%$obj_2x_services_hg->{$obj_2x_service->{'hostgroup_name'}}}, $service_obj_2x_key;
+        # XXX object tricks allow to use a comma seperated list of hostgroup_names!
+        # http://docs.icinga.org/latest/en/objecttricks.html
+        my @hostgroup_names = Icinga2::Utils::str2arr_by_delim_without_excludes($obj_2x_service->{'hostgroup_name'}, ',', 1);
 
+        foreach my $hostgroup_name (@hostgroup_names) {
+            # we need to save all services first, but our new key is the hostgroupname
+            # so that we can create multiple services for a single hosthg template later on
+            push @{%$obj_2x_services_hg->{$hostgroup_name}}, $service_obj_2x_key;
+        }
     }
 
     # now loop over all hostgroups with service relations





More information about the icinga-checkins mailing list