[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-sets-12891: Sync( Rule): Allow to sync services of a ServiceSet

git at icinga.org git at icinga.org
Fri Nov 11 10:44:28 CET 2016


Module: icingaweb2-module-director
Branch: feature/service-sets-12891
Commit: d350623ec2670a0c5e81be8522481142ba09390b
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=d350623ec2670a0c5e81be8522481142ba09390b

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Thu Nov 10 14:05:18 2016 +0100

Sync(Rule): Allow to sync services of a ServiceSet

This extends the destination key pattern for Sync.

refs #12891

---

 library/Director/Import/Sync.php      |    5 ++++-
 library/Director/Objects/SyncRule.php |   13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php
index d7b518a..330dd4c 100644
--- a/library/Director/Import/Sync.php
+++ b/library/Director/Import/Sync.php
@@ -349,7 +349,10 @@ class Sync
             ) as $object) {
 
                 if ($object instanceof IcingaService) {
-                    if (! $object->host_id) {
+                    if (strstr($destinationKeyPattern, '${host}') && $object->host_id === null) {
+                        continue;
+                    }
+                    elseif (strstr($destinationKeyPattern, '${service_set}') && $object->service_set_id === null) {
                         continue;
                     }
                 }
diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php
index a5a0e9a..452a3dd 100644
--- a/library/Director/Objects/SyncRule.php
+++ b/library/Director/Objects/SyncRule.php
@@ -267,6 +267,9 @@ class SyncRule extends DbObject
                     if ($property->destination_field === 'host') {
                         $hasHost = $property->source_expression;
                     }
+                    if ($property->destination_field === 'service_set') {
+                        $hasServiceSet = $property->source_expression;
+                    }
                     if ($property->destination_field === 'object_name') {
                         $hasObjectName = $property->source_expression;
                     }
@@ -282,6 +285,16 @@ class SyncRule extends DbObject
 
                     $this->destinationKeyPattern = '${host}!${object_name}';
                 }
+                elseif ($hasServiceSet !== false && $hasObjectName !== false) {
+                    $this->hasCombinedKey = true;
+                    $this->sourceKeyPattern = sprintf(
+                        '%s!%s',
+                        $hasServiceSet,
+                        $hasObjectName
+                    );
+
+                    $this->destinationKeyPattern = '${service_set}!${object_name}';
+                }
             } elseif ($this->get('object_type') === 'serviceSet') {
                 $hasHost = false;
                 $hasObjectName = false;



More information about the icinga-checkins mailing list