[icinga-checkins] icinga.org: icinga2-migration/master: Resolve host/ service check_command attributes from template tree

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


Module: icinga2-migration
Branch: master
Commit: 5560cce730e47bc078737dafbae0541e7c34746d
URL:    https://git.icinga.org/?p=icinga2-migration.git;a=commit;h=5560cce730e47bc078737dafbae0541e7c34746d

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

Resolve host/service check_command attributes from template tree

Also add a 'dummy' check_command if the key is missing. Icinga 1.x seems
to ignore that while Icinga 2 makes it a mandatory attribute.

---

 .../library/Conftool/Icinga/IcingaConfig.php       |   37 +++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
index 72d0d32..1faf5b2 100644
--- a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
+++ b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
@@ -370,7 +370,29 @@ class IcingaConfig
         foreach ($this->allDefinitions as $definition) {
             if ($definition instanceof IcingaService) {
                 $this->resolveService($definition);
-                //return;
+            }
+            if ($definition instanceof IcingaHost) {
+                $this->resolveHost($definition);
+            }
+        }
+    }
+
+    protected function resolveHost(IcingaHost $host)
+    {
+        if ($host->isTemplate()) {
+            return;
+        }
+
+        //get the check command from the template tree
+        //otherwise we cannot migrate it later
+        if (! $host->check_command) {
+            $check_command = $this->getObjectAttributeRecursive($host, 'check_command');
+
+            if (! $check_command) {
+                print("//ERROR: Host ".$host." without valid check_command attribute (also not in templates). Assigning 'dummy'.\n");
+                $host->check_command = "dummy";
+            } else {
+                $host->check_command = $check_command;
             }
         }
     }
@@ -385,6 +407,19 @@ class IcingaConfig
             return;
         }
 
+        //get the check command from the template tree
+        //otherwise we cannot migrate it later
+        if (! $service->check_command) {
+            $check_command = $this->getObjectAttributeRecursive($service, 'check_command');
+
+            if (! $check_command) {
+                print("//ERROR: Service ".$service." without valid check_command attribute (also not in templates). Assigning 'dummy'.\n");
+                $service->check_command = "dummy";
+            } else {
+                $service->check_command = $check_command;
+            }
+        }
+
         $hostgroups = $service->hostgroup_name
                     ? $this->splitComma($service->hostgroup_name)
                     : array();



More information about the icinga-checkins mailing list