[icinga-checkins] icinga.org: icinga-web/master: * TO colors fix

git at icinga.org git at icinga.org
Fri Jul 23 12:24:15 CEST 2010


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Jul 23 12:23:54 2010 +0200

* TO colors fix

---

 .../icinga-tactical-overview-template-charts.xml   |   20 ++++++++++------
 .../Web/lib/state/IcingaHostStateInfo.class.php    |   10 +++++++-
 .../Web/lib/state/IcingaServiceStateInfo.class.php |    7 +++++
 .../Web/lib/state/IcingaStateInfo.class.php        |   24 +++++++++++++++++++-
 4 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-charts.xml b/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-charts.xml
index 03f3e5a..e0c3a63 100644
--- a/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-charts.xml
+++ b/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-charts.xml
@@ -49,12 +49,20 @@
 					$hosts = $t->ds2Array('HOST_STATUS_SUMMARY');
 					$services = $t->ds2Array('SERVICE_STATUS_SUMMARY');
 
+					$host_color = array();
+					$service_color = array();
+
+					$hs = IcingaHostStateInfo::Create();
+					$ss = IcingaServiceStateInfo::Create();
+
 					foreach ($hosts as $rid=>$r) {
-						$hosts[$rid]['HOST_CURRENT_STATE'] = IcingaHostStateInfo::Create($r['HOST_CURRENT_STATE'])->getCurrentStateAsText();
+						$hosts[$rid]['HOST_CURRENT_STATE'] = $hs->getStateText($r['HOST_CURRENT_STATE']);
+						$host_color[] = $hs->getColorByState($r['HOST_CURRENT_STATE'], true);
 					}
 
 					foreach ($services as $rid=>$r) {
-						$services[$rid]['SERVICE_CURRENT_STATE'] = IcingaServiceStateInfo::Create($r['SERVICE_CURRENT_STATE'])->getCurrentStateAsText();
+						$services[$rid]['SERVICE_CURRENT_STATE'] = $ss->getStateText($r['SERVICE_CURRENT_STATE']);
+						$service_color[] = $ss->getColorByState($r['SERVICE_CURRENT_STATE'], true);
 					}
 
 				?>
@@ -74,9 +82,7 @@
 									'width' =>  250,
 									'height' =>  250,
 
-									'seriesStyles' => array('colors' => array (
-										'#00cc00', '#cc0000', '#ff8000'
-									)),
+									'seriesStyles' => array('colors' => $host_color),
 
 									'extraStyle' => array ('legend' => array (
 										'display' => 'none',
@@ -102,9 +108,7 @@
 									'width' =>  250,
 									'height' =>  250,
 
-									'seriesStyles' => array('colors' => array (
-										'#00cc00', '#ffff00', '#ff0000', '#ff8000'
-									)),
+									'seriesStyles' => array('colors' => $service_color),
 
 									'extraStyle' => array ('legend' => array (
 										'display' => 'none',
diff --git a/app/modules/Web/lib/state/IcingaHostStateInfo.class.php b/app/modules/Web/lib/state/IcingaHostStateInfo.class.php
index c04bb0f..d3f5476 100755
--- a/app/modules/Web/lib/state/IcingaHostStateInfo.class.php
+++ b/app/modules/Web/lib/state/IcingaHostStateInfo.class.php
@@ -13,7 +13,15 @@ class IcingaHostStateInfo extends IcingaStateInfo {
 		IcingaConstants::HOST_DOWN			=> 'DOWN',
 		IcingaConstants::HOST_UNREACHABLE	=> 'UNREACHABLE'
 	);
-	
+
+	protected $colors = array (
+		IcingaConstants::HOST_UP			=> '00cc00',
+		IcingaConstants::HOST_DOWN			=> 'cc0000',
+		IcingaConstants::HOST_UNREACHABLE	=> 'ff8000'
+	);
+
+
+
 	/**
 	 * Shortcut to create an object instance on the fly
 	 * 
diff --git a/app/modules/Web/lib/state/IcingaServiceStateInfo.class.php b/app/modules/Web/lib/state/IcingaServiceStateInfo.class.php
index c57a33c..395bfd6 100755
--- a/app/modules/Web/lib/state/IcingaServiceStateInfo.class.php
+++ b/app/modules/Web/lib/state/IcingaServiceStateInfo.class.php
@@ -14,6 +14,13 @@ class IcingaServiceStateInfo extends IcingaStateInfo {
 		IcingaConstants::STATE_CRITICAL	=> 'CRITICAL',
 		IcingaConstants::STATE_UNKNOWN	=> 'UNKNOWN',
 	);
+
+	protected $colors = array (
+		IcingaConstants::STATE_OK		=> '00cc00',
+		IcingaConstants::STATE_WARNING	=> 'ffff00',
+		IcingaConstants::STATE_CRITICAL	=> 'ff0000',
+		IcingaConstants::STATE_UNKNOWN	=> 'ff8000',
+	);
 	
 	/**
 	 * Shortcut to create an object instance on the fly
diff --git a/app/modules/Web/lib/state/IcingaStateInfo.class.php b/app/modules/Web/lib/state/IcingaStateInfo.class.php
index e56222f..a608f4c 100755
--- a/app/modules/Web/lib/state/IcingaStateInfo.class.php
+++ b/app/modules/Web/lib/state/IcingaStateInfo.class.php
@@ -22,6 +22,14 @@ abstract class IcingaStateInfo {
 	protected $state_list = array (
 	
 	);
+
+	/**
+	 * Colors for states
+	 * @var array
+	 */
+	protected $colors = array (
+		
+	);
 	
 	/**
 	 * Generic constructor to create this object
@@ -92,7 +100,7 @@ abstract class IcingaStateInfo {
 	 * @param integer $state
 	 * @return string
 	 */
-	protected function getStateText($state) {
+	public function getStateText($state) {
 		if (array_key_exists($state, $this->state_list)) {
 			
 			return $this->state_list[$state];
@@ -103,6 +111,20 @@ abstract class IcingaStateInfo {
 	public function getStateList() {
 		return $this->state_list;
 	}
+
+	public function getStateColors() {
+		return $this->colors;
+	}
+
+	public function getColorByState($state, $with_hash=true) {
+		if (array_key_exists($state, $this->colors)) {
+			$out = $this->colors[$state];
+			if ($with_hash==true) {
+				$out = '#'. $out;
+			}
+			return $out;
+		}
+	}
 	
 }
 





More information about the icinga-checkins mailing list