[icinga-checkins] icinga.org: icinga-web/master: * static content: added inheritance of filters

git at icinga.org git at icinga.org
Fri Jan 29 15:07:28 CET 2010


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

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Wed Jan 27 14:03:49 2010 +0100

* static content: added inheritance of filters
* static content: added another template for tactical views

---

 app/config/cronks.xml                              |   11 ++
 .../models/System/StaticContentModel.class.php     |   38 ++++++-
 .../icinga-tactical-overview-template-custom.xml   |  132 ++++++++++++++++++++
 3 files changed, 180 insertions(+), 1 deletions(-)

diff --git a/app/config/cronks.xml b/app/config/cronks.xml
index bac21c1..a947b3b 100644
--- a/app/config/cronks.xml
+++ b/app/config/cronks.xml
@@ -151,6 +151,17 @@
 			</parameter>
 		</parameter>
 
+		<parameter name="icingaTacticalOverviewCustom">
+			<parameter name="module">Cronks</parameter>
+			<parameter name="action">System.StaticContent</parameter>
+			<parameter name="hide">true</parameter>
+			<parameter name="description">Icinga Tactical Overview</parameter>
+			<parameter name="name">Tactical Overview Custom</parameter>
+			<parameter name="parameter">
+				<parameter name="template">icinga-tactical-overview-template-custom</parameter>
+			</parameter>
+		</parameter>
+
 		<parameter name="portalView1Col">
 			<parameter name="module">Cronks</parameter>
 			<parameter name="action">System.PortalView</parameter>
diff --git a/app/modules/Cronks/models/System/StaticContentModel.class.php b/app/modules/Cronks/models/System/StaticContentModel.class.php
index ed8f691..385ccb8 100644
--- a/app/modules/Cronks/models/System/StaticContentModel.class.php
+++ b/app/modules/Cronks/models/System/StaticContentModel.class.php
@@ -9,6 +9,7 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 	 * API variables
 	 */
 	private $api = false;
+	private $globalFilter = array();
 	private $templateData = array();
 
 	/*
@@ -223,7 +224,12 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 				}
 			}
 
-			// set addiotnal search filter
+			// set additional search filter
+			foreach ($this->globalFilter as $filterData) {
+				$apiSearch->setSearchFilter(array($filterData));
+			}
+
+			// set additional search filter
 			foreach ($additionalFilter as $filterData) {
 				$apiSearch->setSearchFilter(array($filterData));
 			}
@@ -365,9 +371,19 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 		for ($x = 0; $x < $numMatches; $x++) {
 			if (!empty($templateVariables[2][$x])) {
 				$currentFilter = trim($templateVariables[2][$x]);
+				if ($tplId != 'MAIN') {
+					
+				}
 			} else {
 				$currentFilter = false;
 			}
+
+			if ($tplId == 'MAIN') {
+				$this->globalFilter = array();
+			} elseif (!empty($filter)) {
+				$this->addToGlobalFilter($filter);
+			}
+
 			$this->createTemplateContent($templateVariables[1][$x], $currentFilter);
 			$content = $this->substituteTemplateVariablesByProcessedContent(
 				$templateVariables[0][$x],
@@ -380,6 +396,26 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 	}
 
 	/**
+	 * adds filter data to global filter to provide inheritance of filters
+	 * @param	mixed			$filterRaw			filter to add to global filter as string or array
+	 * @return	void
+	 * @author	Christian Doebler <christian.doebler at netways.de>
+	 */
+	private function addToGlobalFilter ($filterRaw) {
+		if (!is_array($filterRaw)) {
+			$filterArr = explode(':', substr($filterRaw, 1));
+			foreach ($filterArr as $currentFilter) {
+				$filterTmp = explode(',', $currentFilter);
+				array_push($this->globalFilter, $filterTmp);
+			}
+		} else {
+			foreach ($filterArr as $currentFilter) {
+				array_push($this->globalFilter, $currentFilter);
+			}
+		}
+	}
+
+	/**
 	 * substitutes template variables by already processed content
 	 * @param	string			$tplVar				variable to replace in content template
 	 * @param	string			$tplId				id of content template
diff --git a/res/xml/icinga-tactical-overview-template-custom.xml b/res/xml/icinga-tactical-overview-template-custom.xml
new file mode 100644
index 0000000..7422493
--- /dev/null
+++ b/res/xml/icinga-tactical-overview-template-custom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<template>
+    
+    <!-- 
+    	Meta description of the templates, that anybody
+    	knows what the template is doing
+    -->
+    <meta>
+        <parameter name="name">Default template for Tactical Overview</parameter>
+        <parameter name="description">Displays a Tactical Overview</parameter>
+        <parameter name="author">icinga-web developers</parameter>
+    </meta>
+
+	<!--
+		data sources 
+	-->
+	<datasources>
+		<datasource id="LOCATIONS">
+			<source_type>IcingaApi</source_type>
+			<target>IcingaApi::TARGET_HOSTGROUP</target>
+			<columns>HOSTGROUP_ALIAS</columns>
+		</datasource>
+
+		<datasource id="HOST_STATUS_UP">
+			<source_type>IcingaApi</source_type>
+			<target>IcingaApi::TARGET_HOST</target>
+			<columns>HOST_STATE</columns>
+			<search_type>IcingaApi::SEARCH_TYPE_COUNT</search_type>
+			<filter>
+				<columns>
+					<column>HOST_STATE</column>
+					<value>0</value>
+				</columns>
+			</filter>
+		</datasource>
+
+		<datasource id="HOST_STATUS_DOWN">
+			<source_type>IcingaApi</source_type>
+			<target>IcingaApi::TARGET_HOST</target>
+			<columns>HOST_STATE</columns>
+			<search_type>IcingaApi::SEARCH_TYPE_COUNT</search_type>
+			<filter>
+				<columns>
+					<column>HOST_STATE</column>
+					<value>1</value>
+				</columns>
+			</filter>
+		</datasource>
+
+		<datasource id="HOST_STATUS_UNREACHABLE">
+			<source_type>IcingaApi</source_type>
+			<target>IcingaApi::TARGET_HOST</target>
+			<columns>HOST_STATE</columns>
+			<search_type>IcingaApi::SEARCH_TYPE_COUNT</search_type>
+			<filter>
+				<columns>
+					<column>HOST_STATE</column>
+					<value>2</value>
+				</columns>
+			</filter>
+		</datasource>
+
+	</datasources>
+
+    <!--
+    	html template
+    -->
+    <template_code>
+    	<host_status>
+    		<![CDATA[
+    			<table border="0" cellpadding="0" cellspacing="0">
+    				<tr><td>${HOST_STATUS_UP:COUNT_HOST_STATE} UP</td></tr>
+    				<tr><td>${HOST_STATUS_DOWN:COUNT_HOST_STATE} DOWN</td></tr>
+    				<tr><td>${HOST_STATUS_UNREACHABLE:COUNT_HOST_STATE} UNREACHABLE</td></tr>
+    			</table>
+    		]]>
+    	</host_status>
+
+    	<service_status>
+    		<![CDATA[
+    			<table border="0" cellpadding="0" cellspacing="0">
+    				<tr><td>OK</td></tr>
+    				<tr><td>WARNING</td></tr>
+    				<tr><td>CRITICAL</td></tr>
+    				<tr><td>UNKNOWN</td></tr>
+    			</table>
+    		]]>
+    	</service_status>
+
+    	<locations>
+    		<![CDATA[
+				<tr>
+					<td>${LOCATIONS:HOSTGROUP_ALIAS}</td>
+					<td>${host_status}</td>
+				</tr>
+			]]>
+    	</locations>
+
+    	<services>
+    		<![CDATA[
+				<tr>
+					<td>Service Check Execution Time:</td>
+					<td>${SERVICE_EXECUTION_TIME:SERVICE_EXECUTION_TIME_MIN} / ${SERVICE_EXECUTION_TIME:SERVICE_EXECUTION_TIME_MAX} / ${SERVICE_EXECUTION_TIME:SERVICE_EXECUTION_TIME_AVG} sec</td>
+				</tr>
+			]]> 
+    	</services>
+
+    	<MAIN>
+	    	<![CDATA[
+				<table border="0" cellpadding="0" cellspacing="4">
+					<tr>
+						<td>Locations</td>
+						<td>Services</td>
+					</tr>
+					<tr>
+						<td>
+							<table border="0" cellpadding="0" cellspacing="0">
+								${locations:HOSTGROUP_NAME,company1}
+								${locations:HOSTGROUP_NAME,company2}
+							</table>
+						</td>
+						<td>
+							<table border="0" cellpadding="0" cellspacing="0">
+								$ {services:SERVICEGROUP_NAME,network}
+							</table>
+						</td>						
+					</tr>
+				</table>
+			]]>
+		</MAIN>
+    </template_code>
+</template>
\ No newline at end of file





More information about the icinga-checkins mailing list