[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: code cleanup

git at icinga.org git at icinga.org
Tue Apr 30 19:49:47 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue Apr 30 19:16:15 2013 +0200

configconvert: code cleanup

---

 contrib/configconvert/Icinga2/Convert.pm |   48 ++++-------------------------
 contrib/configconvert/Icinga2/Utils.pm   |   18 -----------
 2 files changed, 7 insertions(+), 59 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index db0be4e..ccaf251 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -96,38 +96,6 @@ sub obj_1x_uses_template {
 ################################################################################
 # Migration 
 #################################################################################
-sub migrate_general_object_2x {
-    my $obj_1x = shift;
-
-    # things we merge or change
-    #
-    # alias / display_name => display_name
-    # prefer the alias (host), and if display_name not set, take the host_name/service_description
-    # service
-    # XXX TODO normal_check_interval => check_interval, retry_check_interval => retry_interval
-    if ($obj_1x->{'__I2CONVERT_TYPE'} == 'service' || $obj_1x->{'__I2CONVERT_TYPE'} == 'servicetemplate') {
-        if (!defined($obj_1x->{'display_name'})) {
-            $obj_1x->{'display_name'} = $obj_1x->{'service_description'};
-        }
-    }
-    # host
-    elsif ($obj_1x->{'__I2CONVERT_TYPE'} == 'host' || $obj_1x->{'__I2CONVERT_TYPE'} == 'hosttemplate') {
-        if (!defined($obj_1x->{'display_name'})) {
-            $obj_1x->{'display_name'} = $obj_1x->{'host_name'};
-            # if alias is set, overwrite it
-            if (defined($obj_1x->{'alias'})) {
-                $obj_1x->{'display_name'} = $obj_1x->{'alias'};
-            }
-        }
-    }
-    # timeperiod, contact
-    else {
-
-    }
-
-    return $obj_1x;
-}
-
 
 #################################################################################
 # Get Object Helpers 
@@ -282,7 +250,7 @@ sub obj_get_hostgroup_obj_by_hostgroup_name {
 
 
 # get host_names by attr 'hostgroup_name'
-sub obj_get_hostnames_obj_by_hostgroup_name {
+sub obj_get_hostnames_arr_by_hostgroup_name {
     my $objs = shift;
     my $obj_type = 'host';
     my $obj_attr = 'hostgroups';
@@ -358,7 +326,7 @@ sub obj_1x_get_host_host_name {
 }
 
 # get host_name(s) from service object
-sub obj_1x_get_service_host_name {
+sub obj_1x_get_service_host_name_arr {
 # service objects may contain comma seperated host lists (ugly as ...)
     my $objs_1x = shift;
     my $obj_1x = shift;
@@ -397,7 +365,7 @@ sub obj_1x_get_service_host_name {
             my $obj_1x_tmpl = obj_get_tmpl_obj_by_tmpl_name($objs_1x, 'service', $obj_1x_template);
 
             # now recurse into ourselves and look for all possible hostnames in array 
-            @host_name = obj_1x_get_service_host_name($objs_1x,$obj_1x_tmpl);
+            @host_name = obj_1x_get_service_host_name_arr($objs_1x,$obj_1x_tmpl);
             #print "DEBUG: from tmpl $obj_1x_template: " . join(" ", @host_name) . "\n";
 
             # bail here if search did not unveil anything
@@ -627,7 +595,7 @@ sub convert_2x {
         # used later in host->service resolval
         ####################################################
         # XXX even if the service object uses templates, we need to figure out its host_name/service_description in order to safely link hosts towards it
-        my @host_names = obj_1x_get_service_host_name($cfg_obj_1x, $obj_1x_service);
+        my @host_names = obj_1x_get_service_host_name_arr($cfg_obj_1x, $obj_1x_service);
        
         #print "DEBUG: service @host_names\n";
 
@@ -635,10 +603,9 @@ sub convert_2x {
         push @{$obj_1x_service->{'__I2CONVERT_HOSTNAME'}}, @host_names;
 
 
-        # skip non-template objects without valid hostnames
+        # skip non-template objects without valid hostnames - we'll deal later with hostgroup magic
         if (!defined($obj_1x_service->{'__I2CONVERT_HOSTNAME'}) && $obj_1x_service->{'__I2CONVERT_IS_TEMPLATE'} == 0) {
             #Icinga2::Utils::debug("Skipping invalid service object without host_name ".Dumper($obj_1x_service));
-            # XXX we may look into objects.cache if there?
             next;
         }
 
@@ -648,10 +615,9 @@ sub convert_2x {
             # we can only look up services with their uniqueness to the host_name
             $obj_1x_service->{'__I2CONVERT_SERVICEDESCRIPTION'} = obj_1x_get_service_service_description($cfg_obj_1x, $obj_1x_service, $service_host_name);
 
-            # skip non-template objects without a valid hostname
+            # skip non-template objects without a valid service description (we cannot tolerate 'name' here!)
             if (!defined($obj_1x_service->{'__I2CONVERT_SERVICEDESCRIPTION'}) && $obj_1x_service->{'__I2CONVERT_IS_TEMPLATE'} == 0) {
                 #Icinga2::Utils::debug("Skipping invalid service object without service_description ".Dumper($obj_1x_service));
-                # XXX we may look into objects.cache if there?
                 next;
             }
 
@@ -1291,7 +1257,7 @@ sub convert_2x {
 
         # we now need all host names for this hostgroup name, as an array
 
-        my @service_hostgroup_hostnames = obj_get_hostnames_obj_by_hostgroup_name($cfg_obj_2x, $hg_name);
+        my @service_hostgroup_hostnames = obj_get_hostnames_arr_by_hostgroup_name($cfg_obj_2x, $hg_name);
 
         if(@service_hostgroup_hostnames == 0) {
             # no members, so service cannot be linked. log a warning XXX
diff --git a/contrib/configconvert/Icinga2/Utils.pm b/contrib/configconvert/Icinga2/Utils.pm
index b8839ae..d40bd42 100644
--- a/contrib/configconvert/Icinga2/Utils.pm
+++ b/contrib/configconvert/Icinga2/Utils.pm
@@ -86,24 +86,6 @@ sub slurp {
     }
 }
 
-# inspired by http://stackoverflow.com/questions/2886872/what-is-the-easiest-way-to-get-a-key-with-the-highest-value-from-a-hash-in-perl
-sub hash_largest_key {
-    my $hash = shift;
-
-    my ($key, @keys) = keys %$hash;
-    my ($big, @vals) = values %$hash;
-
-    for (0 .. $#keys) {
-        if ($vals[$_] > $big) {
-            $big = $vals[$_];
-            $key = $keys[$_];
-        }
-    }
-
-    return $key;
-}
-
-
 1;
 
 __END__





More information about the icinga-checkins mailing list