[icinga-checkins] icinga.org: icinga-web/master: * Added simple duration field (fixes #771)

git at icinga.org git at icinga.org
Mon Jan 17 14:00:04 CET 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Wed Jan 12 17:58:11 2011 +0100

* Added simple duration field (fixes #771)

---

 .../Cronks/data/xml/grid/icinga-host-template.xml  |   27 +++++++++++++++++
 .../data/xml/grid/icinga-service-template.xml      |   27 +++++++++++++++++
 .../tdisplay/IcingaTemplateDisplayFormat.class.php |   31 +++++++++++++++++++-
 3 files changed, 84 insertions(+), 1 deletions(-)

diff --git a/app/modules/Cronks/data/xml/grid/icinga-host-template.xml b/app/modules/Cronks/data/xml/grid/icinga-host-template.xml
index 8ccddb1..9fdffb6 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-host-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-host-template.xml
@@ -838,6 +838,33 @@
             </order>
         </field>
         
+        <field name="host_duration">
+        	<datasource>
+        		<parameter name="field">HOST_LAST_STATE_CHANGE</parameter>
+        	</datasource>
+        	
+            <display>
+                <parameter name="visible">true</parameter>
+                <parameter name="label">Duration</parameter>
+                
+                <!-- Let the agavi translation manager transform the date -->
+                <parameter name="userFunc">
+               		<parameter name="class">IcingaTemplateDisplayFormat</parameter>
+               		<parameter name="method">durationString</parameter>
+                </parameter>
+            </display>
+        	
+            <filter>
+                <parameter name="enabled">false</parameter>    
+            </filter>
+            
+            <order>
+                <parameter name="enabled">true</parameter>
+                <parameter name="default">false</parameter>
+                <parameter name="order">DESC</parameter>
+            </order>
+        </field>
+        
         <field name="host_info_icons">
         	
         	<datasource>
diff --git a/app/modules/Cronks/data/xml/grid/icinga-service-template.xml b/app/modules/Cronks/data/xml/grid/icinga-service-template.xml
index 480d847..533d830 100644
--- a/app/modules/Cronks/data/xml/grid/icinga-service-template.xml
+++ b/app/modules/Cronks/data/xml/grid/icinga-service-template.xml
@@ -767,6 +767,33 @@
                 <parameter name="order">DESC</parameter>
             </order>
         </field>
+        
+        <field name="service_duration">
+        	<datasource>
+        		<parameter name="field">SERVICE_LAST_STATE_CHANGE</parameter>
+        	</datasource>
+        	
+            <display>
+                <parameter name="visible">true</parameter>
+                <parameter name="label">Duration</parameter>
+                
+                <!-- Let the agavi translation manager transform the date -->
+                <parameter name="userFunc">
+               		<parameter name="class">IcingaTemplateDisplayFormat</parameter>
+               		<parameter name="method">durationString</parameter>
+                </parameter>
+            </display>
+        	
+            <filter>
+                <parameter name="enabled">false</parameter>    
+            </filter>
+            
+            <order>
+                <parameter name="enabled">true</parameter>
+                <parameter name="default">false</parameter>
+                <parameter name="order">DESC</parameter>
+            </order>
+        </field>
 
         <field name="service_info_icons">
         	
diff --git a/app/modules/Web/lib/tdisplay/IcingaTemplateDisplayFormat.class.php b/app/modules/Web/lib/tdisplay/IcingaTemplateDisplayFormat.class.php
index 8c68714..a4e89b0 100755
--- a/app/modules/Web/lib/tdisplay/IcingaTemplateDisplayFormat.class.php
+++ b/app/modules/Web/lib/tdisplay/IcingaTemplateDisplayFormat.class.php
@@ -1,6 +1,14 @@
 <?php
 class IcingaTemplateDisplayFormat extends IcingaTemplateDisplay {
 
+	private static $duration_map = array (
+		'w'	=> 604800,
+		'd' => 86400,
+		'h'	=> 3600,
+		'm' => 60,
+		's' => 1
+	);
+	
 	public static function getInstance() {
 		return parent::getInstance(__CLASS__);
 	}
@@ -47,7 +55,28 @@ class IcingaTemplateDisplayFormat extends IcingaTemplateDisplay {
 	}
 	
 	public function durationString($val, AgaviParameterHolder $method_params, AgaviParameterHolder $row) {
-		return "LLL";
+		if (($date = strtotime($val)) > 0) {
+			$diff = time()-$date;
+			if ($diff > 0) {
+				$out = array ();
+				foreach (self::$duration_map as $k=>$v) {
+			        $m = $diff%$v;
+			        
+			        if ($diff==$m) {
+			                continue;
+			        }
+			        else {
+			                $out[] = ceil($diff/$v).$k;
+			                $diff = $m;
+			        }
+			
+			        if ($m==0) break;
+					
+				}
+				return implode(' ', $out);
+			}
+		}
+		return '';
 	}
 }
 ?>
\ No newline at end of file





More information about the icinga-checkins mailing list