[icinga-checkins] icinga.org: icinga-web/feature/credentials-3715: Migrated LegacyApi to new credential grouping system

git at icinga.org git at icinga.org
Fri Apr 26 11:57:28 CEST 2013


Module: icinga-web
Branch: feature/credentials-3715
Commit: 0a496b0c878d1ce9545052ed821df28d4df7ef92
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=0a496b0c878d1ce9545052ed821df28d4df7ef92

Author: Markus Frosch <markus at lazyfrosch.de>
Date:   Fri Apr 26 11:50:54 2013 +0200

Migrated LegacyApi to new credential grouping system

* grouping the credentials like in the DQLViews:
  ((<hostcredentials> AND <servicecredentials>) OR <othercredentials)
* other credentials is Contactgroup stuff
* the credential targets are grouped by OR instead of AND

refs #3715

---

 .../principal/IcingaPrincipalTargetTool.class.php  |   55 ++++++++++++++++----
 1 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/app/modules/Web/lib/principal/IcingaPrincipalTargetTool.class.php b/app/modules/Web/lib/principal/IcingaPrincipalTargetTool.class.php
index fbc1e88..1c74a14 100644
--- a/app/modules/Web/lib/principal/IcingaPrincipalTargetTool.class.php
+++ b/app/modules/Web/lib/principal/IcingaPrincipalTargetTool.class.php
@@ -30,7 +30,11 @@ class IcingaPrincipalTargetTool {
         $sarr = $user->getTargetValuesArray();
         AppKitLogger::verbose("TargetValuesArray = %s", var_export($sarr, true));
         $models = $user->getTargets(null, true, true);
-        $parts = array();
+        $parts = array(
+            "host"    => array(),
+            "service" => array(),
+            "other"   => array(),
+        );
         foreach($models as $model) {
             if ($model->target_type != 'icinga') {
                 continue;
@@ -49,24 +53,53 @@ class IcingaPrincipalTargetTool {
             }
 
             if (count($sarr[$targetname]) > 0) {
-                $parts[] = $to->getMapArray($sarr[$targetname]);
+                $map = $to->getMapArray($sarr[$targetname]);
+                AppKitLogger::verbose("MapArray: %s, %s", $targetname, $map);
             } else {
                 $map = $to->getCustomMap();
-
-                if ($map) {
-                    $search->setSearchFilterAppendix($map, IcingaApiConstants::SEARCH_AND);
-                }
+                AppKitLogger::verbose("CustomMap: %s %s", $targetname, $map);
             }
+            if(preg_match("#^icingahost#i", $targetname))
+                $parts["host"][] = $map;
+            else if(preg_match("#^icingaservice#i", $targetname))
+                $parts["service"][] = $map;
+            else
+                $parts["other"][] = $map;
         }
 
-        if (count($parts) > 0) {
-            $query = join(' AND ', $parts);
-            $search->setSearchFilterAppendix($query, IcingaApiConstants::SEARCH_AND);
+        $applied = false;
+        $query = "";
 
-            return true;
+        # the following logic is built here:
+        # ( <hostcredentials> AND <servicecredentials> ) OR <othercredentials>
+
+        # host
+        if (count($parts["host"]) > 0) {
+            $hostquery = join(' OR ', $parts["host"]);
+            $query = $hostquery;
+            $applied = true;
+        }
+        # service
+        if (count($parts["service"]) > 0) {
+            $servicequery = join(' OR ', $parts["service"]);
+            if($query) $query = "($query) AND ($servicequery)";
+            else $query = $servicequery;
+            $applied = true;
+        }
+        # other
+        if (count($parts["other"]) > 0) {
+            $otherquery = join(' OR ', $parts["other"]);
+            if($query)
+                $query = "( $query ) OR $otherquery";
+            $applied = true;
         }
 
-        return false;
+        if($query) {
+            AppKitLogger::verbose("Apply credential WHERE to query: %s", $query);
+            $search->setSearchFilterAppendix("( $query )", IcingaApiConstants::SEARCH_AND);
+            return true;
+        }
+        else return false;
     }
 
 





More information about the icinga-checkins mailing list