[icinga-checkins] icinga.org: icinga2-migration/feature/basic-functionality: fix service-> {host, hostgroup} relation migration

git at icinga.org git at icinga.org
Sat Jun 14 18:43:08 CEST 2014


Module: icinga2-migration
Branch: feature/basic-functionality
Commit: 078a88e9f8f51f265b0e7b3c91abbc91fc0c06be
URL:    https://git.icinga.org/?p=icinga2-migration.git;a=commit;h=078a88e9f8f51f265b0e7b3c91abbc91fc0c06be

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sat Jun 14 18:42:22 2014 +0200

fix service->{host,hostgroup} relation migration

---

 modules/conftool/application/clicommands/MigrateCommand.php |    8 +++++---
 modules/conftool/library/Conftool/Icinga/IcingaConfig.php   |   11 +++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/modules/conftool/application/clicommands/MigrateCommand.php b/modules/conftool/application/clicommands/MigrateCommand.php
index 2f4794a..d3f9652 100644
--- a/modules/conftool/application/clicommands/MigrateCommand.php
+++ b/modules/conftool/application/clicommands/MigrateCommand.php
@@ -10,7 +10,7 @@ class MigrateCommand extends Command
 {
     public function v1Action()
     {
-        $start = time();
+        $start = microtime(true);
 
         printf("//---------------------------------------------------\n");
         printf("//Migrate Icinga 1.x configuration to Icinga 2 format\n");
@@ -39,6 +39,7 @@ class MigrateCommand extends Command
             if (count($object->getServices()) > 0) {
                 printf("//---- MIGRATE HOST SERVICES -- BEGIN\n");
                 foreach($object->getServices() as $service) {
+                    $service->host_name = $object; //force relation
                     Icinga2ObjectDefinition::fromIcingaObjectDefinition($service, $config)->dump();
                 }
                 printf("//---- MIGRATE HOST SERVICES -- END\n");
@@ -67,6 +68,7 @@ class MigrateCommand extends Command
             if (count($object->getServices()) > 0) {
                 printf("//---- MIGRATE HOSTGROUP SERVICES -- BEGIN\n");
                 foreach($object->getServices() as $service) {
+                    $service->hostgroup_name = $object; //force relation
                     Icinga2ObjectDefinition::fromIcingaObjectDefinition($service, $config)->dump();
                 }
                 printf("//---- MIGRATE HOSTGROUP SERVICES -- END\n");
@@ -92,13 +94,13 @@ class MigrateCommand extends Command
         }
         printf("//MIGRATE TIMEPERIODS -- END\n");
 
-        $end = time();
+        $end = microtime(true);
         $runtime = $end - $start;
 
         printf("//---------------------------------------------------\n");
         printf("//FINISHED :-)\n");
         printf("//End time: " . date("Y-m-d H:i:s") . "\n");
-        printf("//Runtime: " . $runtime . "\n");
+        printf("//Runtime: " . (float)$runtime . "\n");
         printf("//---------------------------------------------------\n");
 
     }
diff --git a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
index a214291..d8b8d48 100644
--- a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
+++ b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
@@ -333,7 +333,7 @@ class IcingaConfig
         } catch(Exception $e) {
             echo 'Exception: ',  $e->getMessage(), '\n';
         }
-        
+
         $type = $definition->getDefinitionType();
         if (isset($this->definitions[$type][$id])) {
             throw new IcingaConfigException(sprintf(
@@ -455,7 +455,7 @@ class IcingaConfig
 
         if (empty($hosts) && empty($hostgroups) && !$service->isTemplate()) {
             print("Could not find any host or hostgroup_name attribute. Skipping invalid object.");
-            return;          
+            return;
         }
 
         if (empty($hosts) && empty($hostgroups) && $service->isTemplate()) {
@@ -467,8 +467,8 @@ class IcingaConfig
             if (isset($this->definitions['host'][$host])) {
                 $assigned = true;
                 if (! $this->definitions['host'][$host]->hasService($service)) {
-                    //force relation (could be overridden from template tree)
-                    $service->host_name = (string) $host;
+                    //relation must be force on migration task! see MigrateCommand.php (ugly TODO)
+                    //$service->host_name = (string) $host;
                     $this->definitions['host'][$host]->addService($service);
                 }
             } elseif (substr($host, 0, 1) === '!' && isset($this->definitions['host'][substr($host, 1)])) {
@@ -521,7 +521,7 @@ class IcingaConfig
         if ($object->$attr) {
             return $object->$attr;
         }
-        
+
         $templates = $object->getParents();
 
         foreach ($templates as $template) {
@@ -634,4 +634,3 @@ class IcingaConfig
         $this->definition_files[$file] = $file;
     }
 }
-



More information about the icinga-checkins mailing list