[icinga-checkins] icinga.org: icinga2-migration/master: Allow hostgroup service exclusions

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


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

Author: Michael Friedrich <michael.friedrich at gmail.com>
Date:   Tue Jun 10 21:04:45 2014 +0200

Allow hostgroup service exclusions

---

 modules/conftool/library/Conftool/Icinga/IcingaConfig.php  |    6 ++++++
 .../conftool/library/Conftool/Icinga/IcingaHostgroup.php   |   12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
index dba261a..72d0d32 100644
--- a/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
+++ b/modules/conftool/library/Conftool/Icinga/IcingaConfig.php
@@ -464,6 +464,12 @@ class IcingaConfig
                 } catch (Exception $e) {
                     echo 'Exception: ',  $e->getMessage(), ' for hostgroup ', $hostgroup, '\n';
                 }
+            } elseif (substr($hostgroup, 0, 1) === '!' && isset($this->definitions['hostgroup'][substr($hostgroup, 1)])) {
+                $assigned = true;
+                $hostgroup = substr($hostgroup, 1);
+                if (! $this->definitions['hostgroup'][$hostgroup]->hasBlacklistedService($service)) {
+                    $this->definitions['hostgroup'][$hostgroup]->blacklistService($service);
+                }
             } else {
                 printf('Cannot assign service "%s" to hostgroup "%s"', $service, $hostgroup);
             }
diff --git a/modules/conftool/library/Conftool/Icinga/IcingaHostgroup.php b/modules/conftool/library/Conftool/Icinga/IcingaHostgroup.php
index 133c9a7..50eadd1 100644
--- a/modules/conftool/library/Conftool/Icinga/IcingaHostgroup.php
+++ b/modules/conftool/library/Conftool/Icinga/IcingaHostgroup.php
@@ -6,6 +6,18 @@ class IcingaHostgroup extends IcingaGroupDefinition
 {
     protected $key = 'hostgroup_name';
     protected $_own_services = array();
+    protected $_not_services = array();
+
+    public function blacklistService(IcingaService $service)
+    {
+        $this->_not_services[$service->service_description] = $service;
+        return $this;
+    }
+
+    public function hasBlacklistedService(IcingaService $service)
+    {
+        return isset($this->_not_services[$service->service_description]);
+    }
 
     public function addService(IcingaService $service)
     {



More information about the icinga-checkins mailing list