[icinga-checkins] icinga.org: icinga2-migration/fix/ missing-host-hostgroups-for-service-assign: WIP.

git at icinga.org git at icinga.org
Tue Jun 10 23:51:23 CEST 2014


Module: icinga2-migration
Branch: fix/missing-host-hostgroups-for-service-assign
Commit: 1c1dc9c11e6b077b09863eb9f5b2244e6da5e588
URL:    https://git.icinga.org/?p=icinga2-migration.git;a=commit;h=1c1dc9c11e6b077b09863eb9f5b2244e6da5e588

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Tue Jun 10 23:50:41 2014 +0200

WIP.

Find a proper way to link services to all hosts/hostgroups as inherited
from the template tree.

---

 modules/conftool/library/Conftool/Icinga/IcingaConfig.php |    2 --
 .../library/Conftool/Icinga2/Icinga2ObjectDefinition.php  |   13 +++++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
index 2137485..cdda8b0 100644
--- a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
+++ b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
@@ -467,8 +467,6 @@ 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;
                     $this->definitions['host'][$host]->addService($service);
                 }
             } elseif (substr($host, 0, 1) === '!' && isset($this->definitions['host'][substr($host, 1)])) {
diff --git a/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php b/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
index 4d6fa94..a1d4124 100644
--- a/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
+++ b/modules/conftool/library/Conftool/Icinga2/Icinga2ObjectDefinition.php
@@ -63,6 +63,15 @@ class Icinga2ObjectDefinition
         //template, parents and config
         $this->is_template = $object->isTemplate();
         $this->_parents = $object->getParents();
+        $this->_hosts = $object->_hosts;
+        $this->_hostgroups = $object->_hostgroups;
+
+        foreach($object->_hosts as $host) {
+            $this->assignWhere('host.name == "'.$host.'"');
+        }
+        foreach($object->_hostgroups as $hostgroup) {
+            $this->assignWhere('"'.$hostgroup.'" in host.groups');
+        }
 
         foreach ($object->getAttributes() as $key => $value) {
 
@@ -96,7 +105,7 @@ class Icinga2ObjectDefinition
                     $varname = "ARG".$i;
                     $varvalue = addslashes($command_arr[$i]); //escape the string 
                     //check against legacy macros and replace them
-		    $varvalue = $this->migrateLegacyMacros($varvalue);
+                    $varvalue = $this->migrateLegacyMacros($varvalue);
                     $this->vars($varname, $varvalue);
                 }
                 continue;
@@ -265,7 +274,7 @@ class Icinga2ObjectDefinition
                 if (substr($value, 0, 1) === '+') {
                     $value = substr($value, 1);
                 } 
-		        //TODO: strip exclusions, but fix them somewhere later as blacklisted host
+                //TODO: strip exclusions, but fix them somewhere later as blacklisted host
                 if (substr($value, 0, 1) === '!') {
                     //$value = substr($value, 1);
                     return;



More information about the icinga-checkins mailing list