[icinga-checkins] icinga.org: icinga-web/mhein/default: * Relation provider [WIP] (refs #1941 )

git at icinga.org git at icinga.org
Mon Nov 14 16:24:50 CET 2011


Module: icinga-web
Branch: mhein/default
Commit: c4990875064d88ad0c8e5ad40a2718730a61bd55
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=c4990875064d88ad0c8e5ad40a2718730a61bd55

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Nov 14 16:24:13 2011 +0100

* Relation provider [WIP] (refs #1941)

---

 app/config/routing.xml                             |    5 ++
 .../Api/actions/ApiCommandInfoAction.class.php     |    7 +++
 .../Api/actions/RelationProviderAction.class.php   |   31 ++++++++++++
 .../models/generated/BaseIcingaContactgroups.php   |    2 +
 .../models/generated/BaseIcingaContacts.php        |    5 ++-
 .../Api/models/Relation/DataModelModel.class.php   |   49 ++++++++++++++++++++
 app/modules/Api/validate/RelationProvider.xml      |   20 ++++++++
 .../views/RelationProviderSuccessView.class.php    |   15 ++++++
 8 files changed, 133 insertions(+), 1 deletions(-)

diff --git a/app/config/routing.xml b/app/config/routing.xml
index 80f6976..f031ed8 100644
--- a/app/config/routing.xml
+++ b/app/config/routing.xml
@@ -44,6 +44,11 @@
                         </ignores>
                     </route>
                 </route>
+                
+                <route name=".relation" pattern="^/relation" stop="false" action="RelationProvider" output_type="json">
+                    <route name=".objectId" stop="true" pattern="^/(objectId:[0-9]+)" />
+                </route>
+                
                 <route name=".sla" pattern="^/sla" output_type="json" action="SLAProvider">
                     <route name=".starttime" stop="false" pattern="start=(starttime:\d*)" />
                     <route name=".endtime" stop="false" pattern="end=(endtime:\d*)" />
diff --git a/app/modules/Api/actions/ApiCommandInfoAction.class.php b/app/modules/Api/actions/ApiCommandInfoAction.class.php
index bea7877..93ae34a 100644
--- a/app/modules/Api/actions/ApiCommandInfoAction.class.php
+++ b/app/modules/Api/actions/ApiCommandInfoAction.class.php
@@ -30,4 +30,11 @@ class Api_ApiCommandInfoAction extends IcingaApiBaseAction implements IAppKitDis
 	    
 	    return $this->getDefaultViewName();
 	}
+	
+	public function isSecure() {
+	    return true;
+	}
+	public function getCredentials() {
+	    return "icinga.user";
+	}
 }
\ No newline at end of file
diff --git a/app/modules/Api/actions/RelationProviderAction.class.php b/app/modules/Api/actions/RelationProviderAction.class.php
new file mode 100644
index 0000000..bef203b
--- /dev/null
+++ b/app/modules/Api/actions/RelationProviderAction.class.php
@@ -0,0 +1,31 @@
+<?php
+
+class Api_RelationProviderAction extends IcingaApiBaseAction {
+	public function getDefaultViewName() {
+		return 'Success';
+	}
+	
+	public function executeRead(AgaviRequestDataHolder $rd) {
+	    return $this->executeWrite($rd);
+	}
+	
+	public function executeWrite(AgaviRequestDataHolder $rd) {
+	    
+	    $model = $this->context->getModel('Relation.DataModel', 'Api');
+	    
+	    try {
+	        $this->setAttribute('data', $model->getRelationDataForObjectId($rd->getParameter('objectId')));
+	    } catch (AppKitModelException $e) {
+	        return "Error";
+	    }
+	    
+	    return $this->getDefaultViewName();
+	}
+	
+	public function isSecure() {
+	    return true;
+	}
+	public function getCredentials() {
+	    return "icinga.user";
+	}
+}
\ No newline at end of file
diff --git a/app/modules/Api/lib/database/models/generated/BaseIcingaContactgroups.php b/app/modules/Api/lib/database/models/generated/BaseIcingaContactgroups.php
index bfec167..08f6a0a 100644
--- a/app/modules/Api/lib/database/models/generated/BaseIcingaContactgroups.php
+++ b/app/modules/Api/lib/database/models/generated/BaseIcingaContactgroups.php
@@ -81,6 +81,7 @@ abstract class BaseIcingaContactgroups extends Doctrine_Record {
         $this->hasMany('IcingaHosts as hosts', array(
                            'local' => 'contactgroup_object_id',
                            'foreign' => 'host_id',
+                           'foreignId' => 'host_id',
                            'refClass' => 'IcingaHostContactgroups',
                            'idField' => 'contactgroup_object_id'
 
@@ -88,6 +89,7 @@ abstract class BaseIcingaContactgroups extends Doctrine_Record {
         $this->hasMany('IcingaServices as services', array(
                            'local' => 'contactgroup_object_id',
                            'foreign' => 'service_id',
+                           'foreignId' => 'service_id',
                            'refClass' => 'IcingaServiceContactgroups',
                            'idField' => 'contactgroup_object_id'
                        ));
diff --git a/app/modules/Api/lib/database/models/generated/BaseIcingaContacts.php b/app/modules/Api/lib/database/models/generated/BaseIcingaContacts.php
index 471e6c0..1e45e5d 100644
--- a/app/modules/Api/lib/database/models/generated/BaseIcingaContacts.php
+++ b/app/modules/Api/lib/database/models/generated/BaseIcingaContacts.php
@@ -272,11 +272,13 @@ abstract class BaseIcingaContacts extends Doctrine_Record {
         $this->hasMany('IcingaHosts as hosts',array(
                            'local' => 'contact_object_id',
                            'foreign' => 'host_id',
-                           'refClass' => 'IcingaHostContacts'
+                           'foreignId' => 'host_id',
+                           'refClass' => 'IcingaHostContacts',
                        ));
         $this->hasMany('IcingaServices as services',array(
                            'local' => 'contact_object_id',
                            'foreign' => 'service_id',
+                           'foreignId' => 'service_id',
                            'refClass' => 'IcingaServiceContacts'
                        ));
         $this->hasOne('IcingaInstances as instance', array(
@@ -302,6 +304,7 @@ abstract class BaseIcingaContacts extends Doctrine_Record {
         $this->hasMany("IcingaContactgroups as contactgroups",array(
                            'local' => 'contact_object_id',
                            'foreign' => 'contactgroup_id',
+                           'foreignId' => 'contactgroup_id',
                            'refClass' => 'IcingaContactgroupMembers'
                        ));
         parent::setUp();
diff --git a/app/modules/Api/models/Relation/DataModelModel.class.php b/app/modules/Api/models/Relation/DataModelModel.class.php
new file mode 100644
index 0000000..b7560fb
--- /dev/null
+++ b/app/modules/Api/models/Relation/DataModelModel.class.php
@@ -0,0 +1,49 @@
+<?php
+
+class Api_Relation_DataModelModel extends IcingaApiBaseModel {
+    
+    public function initialize(AgaviContext $context, array $parameters = array()) {
+        parent::initialize($context, $parameters);
+    }
+    
+    public function getRelationDataForObjectId($objectId) {
+        $data = array ();
+        
+        $data['contactgroup'] = $this->getContactDetails($objectId);
+        $data['object'] = $this->getObjectData($objectId);
+        
+        return $data;
+    }
+    
+    public function getContactDetails($objectId) {
+        $record = IcingaDoctrine_Query::create()
+        ->select('c.contact_id, c.alias, co.name1, h.display_name')
+        ->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')
+        ->from('IcingaContacts c')
+        ->innerJoin('c.object co')
+        ->innerJoin('c.contactgroups cg')
+        ->innerJoin('cg.hosts h')
+        ->execute();
+        
+        die("DY");
+    }
+    
+    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')
+        ->andWhere('o.object_id=?', $objectId)
+        ->execute(array($objectId))
+        ->getFirst();
+        
+        if ($record instanceof IcingaObjects) {
+            return $record->toArray();
+        }
+    }
+}
\ No newline at end of file
diff --git a/app/modules/Api/templates/RelationProviderSuccess.php b/app/modules/Api/templates/RelationProviderSuccess.php
new file mode 100644
index 0000000..e69de29
diff --git a/app/modules/Api/validate/RelationProvider.xml b/app/modules/Api/validate/RelationProvider.xml
new file mode 100644
index 0000000..2a81b4b
--- /dev/null
+++ b/app/modules/Api/validate/RelationProvider.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ae:configurations
+	xmlns="http://agavi.org/agavi/config/parts/validators/1.0"
+	xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
+	parent="%core.module_dir%/Api/config/validators.xml"
+>
+	
+	<ae:configuration>
+        <validators>
+            <validator class="number" name="objectId" required="true">
+                <argument>objectId</argument>
+                
+                <errors>
+                    <error>Could not validate number for objectId</error>
+                </errors>
+            </validator>
+        </validators>
+	</ae:configuration>
+	
+</ae:configurations>
\ No newline at end of file
diff --git a/app/modules/Api/views/RelationProviderSuccessView.class.php b/app/modules/Api/views/RelationProviderSuccessView.class.php
new file mode 100644
index 0000000..a24dd49
--- /dev/null
+++ b/app/modules/Api/views/RelationProviderSuccessView.class.php
@@ -0,0 +1,15 @@
+<?php
+
+class Api_RelationProviderSuccessView extends IcingaApiBaseView {
+	public function executeHtml(AgaviRequestDataHolder $rd) {
+		$this->setupHtml($rd);
+		$this->setAttribute('_title', 'ApiObjectInfo');
+	}
+	
+	public function executeJson(AgaviRequestDataHolder $rd) {
+	    var_dump($this->getAttribute('data', array ()));
+	    return json_encode(array('huhu' => true));
+	}
+}
+
+?>
\ No newline at end of file





More information about the icinga-checkins mailing list