[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: add service dependency support for hostgroups

git at icinga.org git at icinga.org
Fri May 3 18:39:43 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri May  3 18:34:25 2013 +0200

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

---

 contrib/configconvert/Icinga2/Convert.pm |   34 ++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index dacd075..6e78a89 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1237,8 +1237,42 @@ sub convert_2x {
         }
 
         # 2. the infamous group logic - but only for hostgroups here
+        my @master_hostgroup_names = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_servicedependency->{'hostgroup_name'}));
+        my @child_hostgroup_names = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_servicedependency->{'dependent_hostgroup_name'}));
 
+        my @all_master_hostgroup_hostnames = ();
+
+        # get all hosts as array for the master host groups
+        foreach my $master_hostgroup_name (@master_hostgroup_names) {
+            my @host_master_hostgroup_hostnames = obj_get_hostnames_arr_by_hostgroup_name($cfg_obj_2x, $master_hostgroup_name);
+            push @all_master_hostgroup_hostnames, @host_master_hostgroup_hostnames;
+        }
+
+        #say Dumper($obj_1x_servicedependency);
+        #say " DEBUG: all master hg hostnames: ".Dumper(@all_master_hostgroup_hostnames);
+
+        # go through all child hostgroups and fetch their host objects, setting 
+        foreach my $child_hostgroup_name (@child_hostgroup_names) {
+            my @host_child_hostgroup_hostnames = obj_get_hostnames_arr_by_hostgroup_name($cfg_obj_2x, $child_hostgroup_name); # child hostgroup members
+            #say " DEBUG: child hg hostnames: ".Dumper(@host_child_hostgroup_hostnames);
+
+            foreach my $host_child_hostgroup_hostname (@host_child_hostgroup_hostnames) {
+                my $child_service_obj = obj_get_service_obj_by_host_name_service_description($cfg_obj_2x, "__I2CONVERT_SERVICE_HOSTNAME", "__I2CONVERT_SERVICEDESCRIPTION", $host_child_hostgroup_hostname, $child_service_description);
 
+                # now loop through all master hostgroups and get their hosts
+                foreach my $master_hostgroup_name (@master_hostgroup_names) {
+                    my @host_master_hostgroup_names = obj_get_hostnames_arr_by_hostgroup_name($cfg_obj_2x, $master_hostgroup_name); # master hostgroup members
+                    foreach my $host_master_hostgroup_hostname (@host_master_hostgroup_names) {
+
+                        # use some calculated unique key here (no, i will not split the string later! we are perl, we can do hashes)
+                        my $master_key = $host_master_hostgroup_hostname."-".$master_service_description;
+                        $child_service_obj->{'__I2CONVERT_PARENT_SERVICES'}->{$master_key}->{'host'} = $host_master_hostgroup_hostname; # XXX 5th foreach. awesome!
+                        $child_service_obj->{'__I2CONVERT_PARENT_SERVICES'}->{$master_key}->{'service'} = $master_service_description;
+                    }
+                }
+
+            }
+        }
     }
 
     ######################################





More information about the icinga-checkins mailing list