[icinga-checkins] icinga.org: icinga-web/master: * Finished relation provider (refs #1941)

git at icinga.org git at icinga.org
Tue Nov 15 11:47:40 CET 2011


Module: icinga-web
Branch: master
Commit: 83a2d7e3e65d487d910ac84db9a259c5b28ffd15
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=83a2d7e3e65d487d910ac84db9a259c5b28ffd15

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Nov 15 11:46:55 2011 +0100

* Finished relation provider (refs #1941)

---

 .../Api/models/Relation/DataModelModel.class.php   |  125 ++++++++++++++++++--
 .../views/RelationProviderSuccessView.class.php    |   14 ++-
 .../Web/lib/constants/IcingaConstants.class.php    |    6 +-
 3 files changed, 132 insertions(+), 13 deletions(-)

diff --git a/app/modules/Api/models/Relation/DataModelModel.class.php b/app/modules/Api/models/Relation/DataModelModel.class.php
index b7560fb..ea0ba97 100644
--- a/app/modules/Api/models/Relation/DataModelModel.class.php
+++ b/app/modules/Api/models/Relation/DataModelModel.class.php
@@ -9,41 +9,146 @@ class Api_Relation_DataModelModel extends IcingaApiBaseModel {
     public function getRelationDataForObjectId($objectId) {
         $data = array ();
         
-        $data['contactgroup'] = $this->getContactDetails($objectId);
         $data['object'] = $this->getObjectData($objectId);
+        $data['contact'] = $this->getContactDetails($objectId, $data['object']['objecttype_id']);
+        $data['customvariable'] = $this->getCustomVariables($objectId);
+        $data['hostgroup'] = $this->getHostgroups($objectId);
+        $data['servicegroup'] = $this->getServicegroups($objectId);
         
         return $data;
     }
     
-    public function getContactDetails($objectId) {
-        $record = IcingaDoctrine_Query::create()
-        ->select('c.contact_id, c.alias, co.name1, h.display_name')
+    public function getContactDetails($objectId, $objecttypeId) {
+        $type = null;
+        $out = array ();
+        
+        if ($objecttypeId == IcingaConstants::TYPE_HOST) {
+            $type = 'host';
+        } elseif ($objecttypeId == IcingaConstants::TYPE_SERVICE) {
+            $type = 'service';
+        }
+        
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.contact_id, c.alias as contact_alias, co.name1 as contact_name, co.object_id as contact_object_id, NULL as contactgroup, NULL as contactgroup_object_id')
+        ->from('IcingaContacts c')
+        ->innerJoin('c.object co')
+        ->innerJoin('c.'. $type. 's h WITH h.'. $type. '_object_id=?', $objectId)
+        ->execute(null, Doctrine::HYDRATE_ARRAY);
+        
+        if (count($records)) {
+            $out = $records;
+        }
+        
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.contact_id, c.alias as contact_alias, co.name1 as contact_name, co.object_id as contact_object_id,  cg.alias as contactgroup, cg.contactgroup_object_id as contactgroup_object_id')
+        ->from('IcingaContacts c')
+        ->innerJoin('c.object co')
+        ->innerJoin('c.contactgroups cg')
+        ->innerJoin('cg.'. $type. 's h WITH h.'. $type. '_object_id = ?', $objectId)
+        ->execute(null, Doctrine::HYDRATE_ARRAY);
+        
+        if (count($records)) {
+            $out = array_merge($out, $records);
+        }
+        
+        return $out;
+    }
+    
+    public function getHostContactDetails($objectId) {
+        
+        $out = array();
+        
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.alias, co.name1 as name1, co.object_id as contact_object_id, NULL as contactgroup, NULL as contactgroup_id')
         ->from('IcingaContacts c')
         ->innerJoin('c.object co')
         ->innerJoin('c.hosts h WITH h.host_object_id=?', $objectId)
         ->execute();
         
-        $record = IcingaDoctrine_Query::create()
-        ->select('c.contact_id, c.alias, co.name1, h.display_name')
+        foreach ($records as $record) {
+            $out[] = array (
+                'alias' => $record->alias,
+                'email' => $record->email_address,
+                'name'  => $record->name1,
+                'contact_object_id' => $record->contact_object_id,
+                'group' => null,
+                'contactgroup_object_id' => null
+            );
+        }
+        
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.contact_id, c.alias, co.name1 as name1, cg.alias as group, cg.contactgroup_object_id as contactgroup_object_id')
         ->from('IcingaContacts c')
         ->innerJoin('c.object co')
         ->innerJoin('c.contactgroups cg')
-        ->innerJoin('cg.hosts h')
+        ->innerJoin('cg.hosts h WITH h.host_object_id=?', $objectId)
         ->execute();
         
-        die("DY");
+        foreach ($records as $record) {
+            $out[] = array (
+                'alias' => $record->alias,
+                'email' => $record->email_address,
+                'name'  => $record->name1,
+                'contact_object_id' => $record->object->object_id,
+                'group' => $record->group,
+                'contactgroup_object_id' => $record->contactgroup_object_id
+            );
+        }
+        
+        return $out;
+    }
+    
+    public function getServiceContactDetails($objectId) {
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.alias, co.name1 as name1, co.object_id as contact_object_id, NULL as group')
+        ->from('IcingaContacts c')
+        ->innerJoin('c.object co')
+        ->innerJoin('c.services h WITH h.service_object_id=?', $objectId)
+        ->execute(null, Doctrine::HYDRATE_ARRAY);
+        
+        var_dump($records);
+        die;
     }
     
     public function getObjectData($objectId) {
         $record = IcingaDoctrine_Query::create()
         ->from('IcingaObjects o')
-        ->select('o.object_id, o.objecttype_id, o.name1, o.name2, o.is_active')
+        ->select('o.object_id, o.objecttype_id, o.instance_id, o.name1, o.name2, o.is_active')
         ->andWhere('o.object_id=?', $objectId)
-        ->execute(array($objectId))
+        ->execute()
         ->getFirst();
         
         if ($record instanceof IcingaObjects) {
             return $record->toArray();
         }
     }
+    
+    public function getCustomVariables($objectId) {
+        $records = IcingaDoctrine_Query::create()
+        ->select('c.varname, c.varvalue')
+        ->from('IcingaCustomvariables c')
+        ->andWhere('c.object_id=?', array($objectId));
+        
+        return $records->execute(null, Doctrine::HYDRATE_ARRAY);
+    }
+    
+    public function getHostgroups($objectId) {
+        $records = IcingaDoctrine_Query::create()
+        ->select('hg.alias as alias, o.name1 as name, o.object_id as hostgroup_object_id')
+        ->from('IcingaHostgroups hg')
+        ->innerJoin('hg.object o')
+        ->innerJoin('hg.members m with m.host_object_id=?', $objectId);
+        
+        return $records->execute(null, Doctrine::HYDRATE_ARRAY);
+    }
+    
+    public function getServicegroups($objectId) {
+        $records = IcingaDoctrine_Query::create()
+        ->select('sg.alias as alias, o.name1 as name, o.object_id as servicegroup_object_id')
+        ->from('IcingaServicegroups sg')
+        ->innerJoin('sg.object o')
+        ->innerJoin('sg.members m with m.service_object_id = ?', $objectId);
+        
+        return $records->execute(null, Doctrine::HYDRATE_ARRAY);
+    }
 }
\ No newline at end of file
diff --git a/app/modules/Api/views/RelationProviderSuccessView.class.php b/app/modules/Api/views/RelationProviderSuccessView.class.php
index a24dd49..0aa3e67 100644
--- a/app/modules/Api/views/RelationProviderSuccessView.class.php
+++ b/app/modules/Api/views/RelationProviderSuccessView.class.php
@@ -7,8 +7,18 @@ class Api_RelationProviderSuccessView extends IcingaApiBaseView {
 	}
 	
 	public function executeJson(AgaviRequestDataHolder $rd) {
-	    var_dump($this->getAttribute('data', array ()));
-	    return json_encode(array('huhu' => true));
+	    $data = $this->getAttribute('data', array ());
+	    
+	    $out = array (
+	        'result' => $data,
+	        'success' => false
+	    );
+	    
+	    if (isset($data['object']) && is_array($data['object'])) {
+	        $out['success'] = true;
+	    }
+	    
+	    return json_encode($data);
 	}
 }
 
diff --git a/app/modules/Web/lib/constants/IcingaConstants.class.php b/app/modules/Web/lib/constants/IcingaConstants.class.php
index 3e9deee..dea211e 100644
--- a/app/modules/Web/lib/constants/IcingaConstants.class.php
+++ b/app/modules/Web/lib/constants/IcingaConstants.class.php
@@ -1,6 +1,6 @@
 <?php
 
-class IcingaConstants {
+interface IcingaConstants {
 
     // Host states
     const HOST_UP							= 0;
@@ -57,6 +57,10 @@ class IcingaConstants {
     const DOWNTIME_COMMENT					= 2;
     const FLAPPING_COMMENT					= 3;
     const ACKNOWLEDGEMENT_COMMENT			= 4;
+    
+    // Types
+    const TYPE_HOST                         = 1;
+    const TYPE_SERVICE                      = 2;
 }
 
 ?>





More information about the icinga-checkins mailing list