[icinga-checkins] icinga.org: icinga-web/mhein/default: * Added logic for status icons

git at icinga.org git at icinga.org
Wed Jan 13 11:59:11 CET 2010


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Wed Jan 13 11:57:53 2010 +0100

* Added logic for status icons
* Removed some antiquated files
* Fixed a bug for zero replacements in format parser

---

 ...ingaDataCustomVariablePrincipalTarget.class.php |   26 -----
 .../IcingaTemplateDisplayServiceIcons.class.php    |  107 ++++++++++----------
 lib/appkit/util/AppKitFormatParserUtil.class.php   |    2 +-
 res/xml/icinga-service-template.xml                |    8 ++
 4 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/app/lib/icinga/principal/IcingaDataCustomVariablePrincipalTarget.class.php b/app/lib/icinga/principal/IcingaDataCustomVariablePrincipalTarget.class.php
deleted file mode 100644
index 393696e..0000000
--- a/app/lib/icinga/principal/IcingaDataCustomVariablePrincipalTarget.class.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-class IcingaDataCustomVariablePrincipalTarget extends IcingaDataPrincipalTarget {
-	
-	public function __construct() {
-		
-		parent::__construct();
-		
-		$this->setFields(array(
-			'cv_name'	=> 'Name of the custom variable',
-			'cv_value'	=> 'Value contained ba the variable'
-		));
-		
-		$this->setApiMappingFields(array(
-			'cv_name'	=> 'CUSTOMVARIABLE_NAME',
-			'cv_value'	=> 'CUSTOMVARIABLE_VALUE'
-		));
-		
-		$this->setType('IcingaDataTarget');
-		
-		$this->setDescription('Limit data access to customvariables');
-	}
-	
-}
-
-?>
\ No newline at end of file
diff --git a/app/lib/icinga/tdisplay/IcingaTemplateDisplayServiceIcons.class.php b/app/lib/icinga/tdisplay/IcingaTemplateDisplayServiceIcons.class.php
index 5558228..16f8ecb 100644
--- a/app/lib/icinga/tdisplay/IcingaTemplateDisplayServiceIcons.class.php
+++ b/app/lib/icinga/tdisplay/IcingaTemplateDisplayServiceIcons.class.php
@@ -2,40 +2,54 @@
 
 class IcingaTemplateDisplayServiceIcons extends IcingaTemplateDisplay {
 	
+	const COND_ERROR = 0xffff;
+	
 	private $image_path = '/images/status';
 	
-	private $service_fields = array (
-		'SERVICE_NOTIFICATIONS_ENABLED' => array (
+	private static $service_fields = array (
+		'SERVICE_NOTIFICATIONS_ENABLED', 'SERVICE_ACTIVE_CHECKS_ENABLED',
+		'SERVICE_PASSIVE_CHECKS_ENABLED', 'SERVICE_CURRENT_STATE',
+		'SERVICE_PROBLEM_HAS_BEEN_ACKNOWLEDGED'
+	);
+	
+	private static $service_conditions = array (
+		'${field.SERVICE_NOTIFICATIONS_ENABLED}' => array (
 			false	=> array ('ndisabled.png', 'Notifications disabled')
 		),
 		
-		'SERVICE_ACTIVE_CHECKS_ENABLED,SERVICE_PASSIVE_CHECKS_ENABLED' => array (
-			false	=> array ('off.png', 'Service disabled')
+		'!${field.SERVICE_ACTIVE_CHECKS_ENABLED} && !${field.SERVICE_PASSIVE_CHECKS_ENABLED}' => array (
+			true	=> array ('off.png', 'Service disabled')
 		),
 		
-		'SERVICE_ACTIVE_CHECKS_ENABLED' => array (
-			false	=> array ('passive.png', 'Passive only')
+		'!${field.SERVICE_ACTIVE_CHECKS_ENABLED} && ${field.SERVICE_PASSIVE_CHECKS_ENABLED}' => array (
+			true	=> array ('passive.png', 'Passive only')
 		),
 		
-		'SERVICE_CURRENT_STATE,SERVICE_PROBLEM_HAS_BEEN_ACKNOWLEDGED' => array (
+		'${field.SERVICE_CURRENT_STATE} && ${field.SERVICE_PROBLEM_HAS_BEEN_ACKNOWLEDGED}' => array (
 			true	=> array ('acknowledged.png', 'Problem has been acknowledged')
 		)
 	);
 	
-	private $host_fields = array (
-		'HOST_NOTIFICATIONS_ENABLED' => array (
+	private static $host_fields = array (
+		'HOST_NOTIFICATIONS_ENABLED', 'HOST_ACTIVE_CHECKS_ENABLED',
+		'HOST_PASSIVE_CHECKS_ENABLED', 'HOST_CURRENT_STATE',
+		'HOST_PROBLEM_HAS_BEEN_ACKNOWLEDGED'
+	);
+	
+	private static $host_conditions = array (
+		'${field.HOST_NOTIFICATIONS_ENABLED}' => array (
 			false	=> array ('ndisabled.png', 'Notifications disabled')
 		),
 		
-		'HOST_ACTIVE_CHECKS_ENABLED,HOST_PASSIVE_CHECKS_ENABLED' => array (
+		'${field.HOST_ACTIVE_CHECKS_ENABLED} && ${field.HOST_PASSIVE_CHECKS_ENABLED}' => array (
 			false	=> array ('off.png', 'Service disabled')
 		),
 		
-		'HOST_ACTIVE_CHECKS_ENABLED' => array (
-			false	=> array ('passive.png', 'Passive only')
+		'!${field.HOST_ACTIVE_CHECKS_ENABLED} && ${field.HOST_PASSIVE_CHECKS_ENABLED}' => array (
+			true	=> array ('passive.png', 'Passive only')
 		),
 		
-		'HOST_CURRENT_STATE,HOST_PROBLEM_HAS_BEEN_ACKNOWLEDGED' => array (
+		'${field.HOST_CURRENT_STATE} && ${field.HOST_PROBLEM_HAS_BEEN_ACKNOWLEDGED}' => array (
 			true	=> array ('acknowledged.png', 'Problem has been acknowledged')
 		)
 	);
@@ -50,10 +64,10 @@ class IcingaTemplateDisplayServiceIcons extends IcingaTemplateDisplay {
 		
 		$dh = $this->getIcingaApi()->createSearch()
 		->setSearchTarget(IcingaApi::TARGET_SERVICE)
-		->setResultColumns($this->getFields($this->service_fields))
+		->setResultColumns(self::$service_fields)
 		->setSearchFilter('SERVICE_OBJECT_ID', $id);
 		
-		return $this->buildIcons($dh, $this->service_fields);
+		return $this->buildIcons($dh, self::$service_conditions);
 	}
 	
 	public function hostIcons($val, AgaviParameterHolder $method_params, AgaviParameterHolder $row) {
@@ -62,56 +76,30 @@ class IcingaTemplateDisplayServiceIcons extends IcingaTemplateDisplay {
 		
 		$dh = $this->getIcingaApi()->createSearch()
 		->setSearchTarget(IcingaApi::TARGET_HOST)
-		->setResultColumns($this->getFields($this->host_fields))
+		->setResultColumns(self::$host_fields)
 		->setSearchFilter('HOST_OBJECT_ID', $id);
 		
-		return $this->buildIcons($dh, $this->host_fields);
-	}
-	
-	private function getFields(array $a) {
-		$out = array ();
-		foreach ($a as $k=>$garbage) {
-			$values = split(',', $k);
-			$out = array_merge($out, $values);
-		}
-		
-		return array_unique($out);
-	}
-	
-	private function getBooleanVal($key, array $row) {
-		$keys = split(',', $key);
-		$val = false;
-		
-		foreach ($keys as $sk) {
-			if (array_key_exists($sk, $row)) {
-				$val |= (bool)$row[$sk];
-			}
-		}
-		return (bool)$val;
-	}
-	
-	private function keyExists($key, array $row) {
-		$keys = split(',', $key);
-		$out = array_intersect($keys, array_keys($row));
-		if (count($out)) {
-			return true;
-		}
-		
-		return false;
+		return $this->buildIcons($dh, self::$host_conditions);
 	}
 	
 	private function buildIcons(IcingaApiSearch &$dh, array $mapping) {
 		$out = null;
 		
+		$parser = new AppKitFormatParserUtil();
+		$parser->registerNamespace('field', AppKitFormatParserUtil::TYPE_ARRAY);
+		
 		foreach ($dh->fetch() as $res) {
 			$row = (array)$res->getRow();
+			$parser->registerData('field', $row);
 			
 			foreach ($mapping as $fkey=>$fm) {
-				if ($this->keyExists($fkey, $row)) {
-					$val = $this->getBooleanVal($fkey, $row);
-					
-					if (isset($fm[$val])) {
-						$i = $fm[$val];
+				$cond = 'return (int)('. $parser->parseData($fkey). ');';
+				
+				if (($test = $this->evalCode($cond)) !== self::COND_ERROR) {
+					// var_dump(array($fkey, $cond, $test));
+					if (isset($fm[$test])) {
+						// var_dump(" --> OK");
+						$i = $fm[$test];
 						$tag = AppKitXmlTag::create('img');
 						
 						if (isset($i[0])) {
@@ -126,6 +114,8 @@ class IcingaTemplateDisplayServiceIcons extends IcingaTemplateDisplay {
 						$out .= (string)$tag;
 					}
 				}
+				
+				
 			}
 			
 		}
@@ -133,6 +123,15 @@ class IcingaTemplateDisplayServiceIcons extends IcingaTemplateDisplay {
 		return $out;
 	}
 	
+	private function evalCode($code) {
+		$re = @eval($code);
+		if ($re === false) {
+			return self::COND_ERROR;
+		}
+		
+		return (bool)$re;
+	}
+	
 	private function getObjectId($field_name, AgaviParameterHolder $row) {
 
 		if ($row->hasParameter($field_name)) {
diff --git a/lib/appkit/util/AppKitFormatParserUtil.class.php b/lib/appkit/util/AppKitFormatParserUtil.class.php
index 3106e8a..5c70391 100644
--- a/lib/appkit/util/AppKitFormatParserUtil.class.php
+++ b/lib/appkit/util/AppKitFormatParserUtil.class.php
@@ -151,7 +151,7 @@ class AppKitFormatParserUtil {
 					
 				}
 				
-				if ($replace) {
+				if (isset($replace)) {
 					$format = preg_replace('@'. preg_quote($match[0]). '@', $replace, $format);
 				}
 				
diff --git a/res/xml/icinga-service-template.xml b/res/xml/icinga-service-template.xml
index 1c54124..054ab63 100644
--- a/res/xml/icinga-service-template.xml
+++ b/res/xml/icinga-service-template.xml
@@ -525,6 +525,14 @@
         	<display>
                 <parameter name="visible">true</parameter>
                 <parameter name="label">Info</parameter>
+                
+                <parameter name="width">50</parameter>
+                
+                <!-- Config for the AJAX grid (see http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.Column) -->
+                <parameter name="Ext.grid.Column">
+                	<parameter name="menuDisabled">true</parameter>
+                </parameter>
+                
                 <parameter name="userFunc">
                 	<parameter name="class">IcingaTemplateDisplayServiceIcons</parameter>
                 	<parameter name="method">serviceIcons</parameter>





More information about the icinga-checkins mailing list