[icinga-checkins] icinga.org: icinga-web/cdoebler/default: * prepared static content for handling of sub-templates

git at icinga.org git at icinga.org
Fri Jan 22 16:09:18 CET 2010


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

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Fri Jan 22 16:08:52 2010 +0100

* prepared static content for handling of sub-templates

---

 .../models/System/StaticContentModel.class.php     |   50 ++++++++---
 res/xml/icinga-tactical-overview-template.xml      |   90 ++++++++++----------
 2 files changed, 82 insertions(+), 58 deletions(-)

diff --git a/app/modules/Cronks/models/System/StaticContentModel.class.php b/app/modules/Cronks/models/System/StaticContentModel.class.php
index 26419af..4fcc93a 100644
--- a/app/modules/Cronks/models/System/StaticContentModel.class.php
+++ b/app/modules/Cronks/models/System/StaticContentModel.class.php
@@ -36,7 +36,7 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 	public function getContent ($xmlFile) {
 		$this->getTemplateData($xmlFile);
 		$this->fetchData();
-		$content = $this->processTemplate();
+		$content = $this->processTemplates();
 
 		return $content;
 	}
@@ -260,35 +260,57 @@ class Cronks_System_StaticContentModel extends ICINGACronksBaseModel
 	 */
 
 	/**
-	 * generates content from template and fetched data
+	 * calls the template generator for each template
 	 * @param	void
 	 * @return	string								processed content
 	 * @author	Christian Doebler <christian.doebler at netways.de>
 	 */
-	private function processTemplate () {
+	private function processTemplates () {
 		$content = null;
+		$subContent = array();
 
 		if (array_key_exists('template_code', $this->xmlData)) {
-			$content = $this->xmlData['template_code'];
-
-			// fetch repeating variables from template and call substitution routine
-			$variablePattern = '/\${([A-Za-z0-9_\-]+):repeat}/s';
-			preg_match_all($variablePattern, $content, $templateVariables);
-			$content = $this->substituteRepeatingTemplateVariables($content, $templateVariables);
+			if (is_array($this->xmlData) && array_key_exists('MAIN', $this->xmlData['template_code'])) {
+				$templates = $this->xmlData['template_code'];
 
-			// fetch remaining variables from template and call substitution routine
-			$variablePattern = '/\${([A-Za-z0-9_\-]+):([A-Z_]+)(:.*)?}/s';
-			preg_match_all($variablePattern, $content, $templateVariables);
-			$content = $this->substituteTemplateVariables($content, $templateVariables);
+				foreach ($templates as $tplId => $tpl) {
+					if ($tplId != 'MAIN') {
+						$subContent[$tplId] = $this->createTemplateContent($tpl);
+					}
+				}
 
+				$content = $this->createTemplateContent($templates['MAIN']);
+			} else {
+				throw new Cronks_System_StaticContentModelException('processTemplates(): no template "MAIN" defined!');
+			}
 		} else {
-			throw new Cronks_System_StaticContentModelException('processTemplate(): no template_code defined!');
+			throw new Cronks_System_StaticContentModelException('processTemplates(): no template_code defined!');
 		}
 
 		return $content;
 	}
 
 	/**
+	 * generates content from template and fetched data
+	 * @param	string			$content			content template
+	 * @return	string								processed content
+	 * @author	Christian Doebler <christian.doebler at netways.de>
+	 */
+	private function createTemplateContent ($content) {
+		// fetch repeating variables from template and call substitution routine
+		$variablePattern = '/\${([A-Za-z0-9_\-]+):repeat}/s';
+		preg_match_all($variablePattern, $content, $templateVariables);
+		$content = $this->substituteRepeatingTemplateVariables($content, $templateVariables);
+
+		// fetch remaining variables from template and call substitution routine
+		$variablePattern = '/\${([A-Za-z0-9_\-]+):([A-Z_]+)(:.*)?}/s';
+		preg_match_all($variablePattern, $content, $templateVariables);
+		$content = $this->substituteTemplateVariables($content, $templateVariables);
+
+		return $content;
+	}
+
+	/**
 	 * substitutes repeating template variables by fetched data
 	 * @param	string			$content			template
 	 * @param	array			$templateVariables	template variables extracted via preg_match_all
diff --git a/res/xml/icinga-tactical-overview-template.xml b/res/xml/icinga-tactical-overview-template.xml
index a894043..12e521e 100644
--- a/res/xml/icinga-tactical-overview-template.xml
+++ b/res/xml/icinga-tactical-overview-template.xml
@@ -127,49 +127,51 @@
     	html template
     -->
     <template_code>
-    	<![CDATA[
-			<table border="0" cellpadding="0" cellspacing="4">
-				<tr>
-					<td>Monitoring Performance</td>
-				</tr>
-				<tr>
-					<td>
-						<table border="0" cellpadding="0" cellspacing="0">
-							<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>
-							<tr>
-								<td>Service Check Latency:</td>
-								<td>${SERVICE_LATENCY:SERVICE_LATENCY_MIN} / ${SERVICE_LATENCY:SERVICE_LATENCY_MAX} / ${SERVICE_LATENCY:SERVICE_LATENCY_AVG} sec</td>
-							</tr>
-							<tr>
-								<td>Host Check Execution Time:</td>
-								<td>${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_MIN} / ${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_MAX} / ${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_AVG} sec</td>
-							</tr>
-							<tr>
-								<td>Host Check Latency:</td>
-								<td>${HOST_LATENCY:HOST_LATENCY_MIN} / ${HOST_LATENCY:HOST_LATENCY_MAX} / ${HOST_LATENCY:HOST_LATENCY_AVG} sec</td>
-							</tr>
-							<tr>
-								<td># Active Host / Service Checks:</td>
-								<td>${NUM_ACTIVE_HOST_CHECKS:COUNT_HOST_OBJECT_ID} / ${NUM_ACTIVE_SERVICE_CHECKS:COUNT_SERVICE_OBJECT_ID}</td>
-							</tr>
-							<tr>
-								<td># Passive Host / Service Checks:</td>
-								<td>${NUM_PASSIVE_HOST_CHECKS:COUNT_HOST_OBJECT_ID} / ${NUM_PASSIVE_SERVICE_CHECKS:COUNT_SERVICE_OBJECT_ID}</td>
-							</tr>
-						</table>
-					</td>
-				</tr>
-			</table>
-			<!--
-			${HOST_NAMES:repeat}
-				<br/>
-				${HOST_NAMES:HOST_NAME} | ${HOST_NAMES:HOST_STATE:IcingaTemplateDisplayMonitoring:hostStatus(__VALUE__,new AgaviParameterHolder(),new AgaviParameterHolder())}
-				<br/> 
-			${HOST_NAMES:repeat_end}
-			-->
-		]]>
+    	<MAIN>
+	    	<![CDATA[
+				<table border="0" cellpadding="0" cellspacing="4">
+					<tr>
+						<td>Monitoring Performance</td>
+					</tr>
+					<tr>
+						<td>
+							<table border="0" cellpadding="0" cellspacing="0">
+								<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>
+								<tr>
+									<td>Service Check Latency:</td>
+									<td>${SERVICE_LATENCY:SERVICE_LATENCY_MIN} / ${SERVICE_LATENCY:SERVICE_LATENCY_MAX} / ${SERVICE_LATENCY:SERVICE_LATENCY_AVG} sec</td>
+								</tr>
+								<tr>
+									<td>Host Check Execution Time:</td>
+									<td>${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_MIN} / ${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_MAX} / ${HOST_EXECUTION_TIME:HOST_EXECUTION_TIME_AVG} sec</td>
+								</tr>
+								<tr>
+									<td>Host Check Latency:</td>
+									<td>${HOST_LATENCY:HOST_LATENCY_MIN} / ${HOST_LATENCY:HOST_LATENCY_MAX} / ${HOST_LATENCY:HOST_LATENCY_AVG} sec</td>
+								</tr>
+								<tr>
+									<td># Active Host / Service Checks:</td>
+									<td>${NUM_ACTIVE_HOST_CHECKS:COUNT_HOST_OBJECT_ID} / ${NUM_ACTIVE_SERVICE_CHECKS:COUNT_SERVICE_OBJECT_ID}</td>
+								</tr>
+								<tr>
+									<td># Passive Host / Service Checks:</td>
+									<td>${NUM_PASSIVE_HOST_CHECKS:COUNT_HOST_OBJECT_ID} / ${NUM_PASSIVE_SERVICE_CHECKS:COUNT_SERVICE_OBJECT_ID}</td>
+								</tr>
+							</table>
+						</td>
+					</tr>
+				</table>
+				<!--
+				${HOST_NAMES:repeat}
+					<br/>
+					${HOST_NAMES:HOST_NAME} | ${HOST_NAMES:HOST_STATE:IcingaTemplateDisplayMonitoring:hostStatus(__VALUE__,new AgaviParameterHolder(),new AgaviParameterHolder())}
+					<br/> 
+				${HOST_NAMES:repeat_end}
+				-->
+			]]>
+		</MAIN>
     </template_code>
 </template>
\ No newline at end of file





More information about the icinga-checkins mailing list