[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: add servicedependency support (host_name)

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


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri May  3 17:57:07 2013 +0200

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

---

 contrib/configconvert/Icinga2/Convert.pm          |   26 ++++++++++++++++++++-
 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |   15 ++++++++++++
 2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 314074c..dacd075 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -1168,7 +1168,7 @@ sub convert_2x {
     }
 
     ######################################
-    # DEPENDENCIES - XXX handled differently
+    # DEPENDENCIES
     ######################################
 
     foreach my $hostdependency_obj_1x_key (keys %{@$cfg_obj_1x{'hostdependency'}}) {
@@ -1215,6 +1215,30 @@ sub convert_2x {
         my $obj_1x_servicedependency = @$cfg_obj_1x{'servicedependency'}->{$servicedependency_obj_1x_key};
         # clone it into our hash
         $cfg_obj_2x->{'servicedependency'}->{$servicedependency_obj_1x_key} = dclone(@$cfg_obj_1x{'servicedependency'}->{$servicedependency_obj_1x_key});
+
+        # 1. the single host_name / service_description entries
+        # service_description is a string, while the host_name directive is still a comma seperated list
+        my @master_host_names = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_servicedependency->{'host_name'}));
+        my @child_host_names = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x_servicedependency->{'dependent_host_name'}));
+
+        my $master_service_description = $obj_1x_servicedependency->{'service_description'};
+        my $child_service_description = $obj_1x_servicedependency->{'dependent_service_description'};
+
+        # go through all child hosts, and get the service object by host_name and our single service_description
+        foreach my $child_host_name (@child_host_names) {
+            my $child_service_obj = obj_get_service_obj_by_host_name_service_description($cfg_obj_2x, "__I2CONVERT_SERVICE_HOSTNAME", "__I2CONVERT_SERVICEDESCRIPTION", $child_host_name, $child_service_description); 
+            # stash all master dependencies onto the child service
+            foreach my $master_host_name (@master_host_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 = $master_host_name."-".$master_service_description;
+                $child_service_obj->{'__I2CONVERT_PARENT_SERVICES'}->{$master_key}->{'host'} = $master_host_name;
+                $child_service_obj->{'__I2CONVERT_PARENT_SERVICES'}->{$master_key}->{'service'} = $master_service_description;
+            }
+        }
+
+        # 2. the infamous group logic - but only for hostgroups here
+
+
     }
 
     ######################################
diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index f1f9023..c74beb2 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -287,6 +287,21 @@ sub dump_service_2x {
     }
 
     ####################################################
+    # 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'})) {





More information about the icinga-checkins mailing list