[icinga-checkins] icinga.org: icinga2-migration/master: Only use apply/ assign for multiple host_name's on service

git at icinga.org git at icinga.org
Thu Jun 12 21:47:05 CEST 2014


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

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Thu Jun 12 21:46:42 2014 +0200

Only use apply/assign for multiple host_name's on service

---

 .../library/Conftool/Icinga2/Icinga2Service.php     |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php b/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
index 2a43ab8..420b24c 100644
--- a/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
+++ b/modules/conftool/library/Conftool/Icinga2/Icinga2Service.php
@@ -76,18 +76,33 @@ class Icinga2Service extends Icinga2ObjectDefinition
     protected function convertHost_name($name)
     {
         $arr = $this->splitComma($name);
-        $this->is_apply = true;
+        $hosts = array();
+        $this->is_apply = false;
 
         foreach ($arr as $hostname) {
             if (substr($hostname, 0, 1) === '!') {
                 $hostname = substr($hostname, 1);
                 $this->ignoreWhere('host.name == ' . $this->migrateLegacyString($hostname));
+                $this->is_apply = true;
             } else if (substr($hostname, 0, 1) === '*') {
                 $this->assignWhere('match("*", host.name)');
+                $this->is_apply = true;
             } else {
-                $this->assignWhere('host.name == ' . $this->migrateLegacyString($hostname));
+                $hosts[] = $hostname;
             }
         }
+
+        if (substr($name, 0, 1) === '*') {
+            return; //no more actions
+        }
+
+        //assign rule applies?
+        if (count($hosts) > 1) {
+            $this->assignWhere('host.name in ' . $this->renderArray($hosts));
+            $this->is_apply = true;
+        } else {
+            $this->host_name = "\"".$name."\"";
+        }
     }
 
     protected function convertHostgroup_name($name)



More information about the icinga-checkins mailing list