[FEATURE] Force Server with errors on top of the page 09/14709/1
authorBastian Bringenberg <mail@bastian-bringenberg.de>
Tue, 18 Sep 2012 17:23:38 +0000 (19:23 +0200)
committerBastian Bringenberg <mail@bastian-bringenberg.de>
Tue, 18 Sep 2012 17:23:38 +0000 (19:23 +0200)
All Servers with errors should be listed on the top of the page, not down in the list.

Change-Id: I0b4510e0ca2ba23614bcbd4b877250cd1a8accb8
Fixes: #41025 @1h:00

index.php
static/indexTemplate.html
static/style.css

index f408b87..4ba387a 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,7 +4,16 @@ require_once("ZabbixAPI.class.php");
 require('config.inc.php');
 $temp_ajax = 'temp/ajax.html';
 $temp_all = 'temp/all.html';
-$cachingTime = 60;
+$cachingTime = 120;
+
+/**
+ * @todo generate checkServerErrorAcknowledged - Method
+ * @param int $hostid the 
+ * @return true if server is known.
+**/
+function checkServerErrorAcknowledged($hostid){
+       return true;
+}
 
 if(isset($_GET['ajax']) && $_GET['ajax'] == 1){
     if(file_exists($temp_ajax) && time() - filemtime($temp_ajax) < $cachingTime){
@@ -22,12 +31,12 @@ if(isset($_GET['ajax']) && $_GET['ajax'] == 1){
 ZabbixAPI::debugEnabled(FALSE);
 $zabbix = new ZabbixAPI($apiUrl);
 $zabbix->login($apiUser, $apiPass);
-//$version = $zabbix->fetch_string('apiinfo','version');
-//echo "Server running Zabbix API Version: $version\n<br>";
 
 $hosts = $zabbix->fetch_array('host','get',array('output'=>'extend', 'groupids'=>array(10)));
 $statusDiv = '';
-$statusArray = array();
+$okayArray = array();
+$errorArray = array();
+$acknowledgedArray = array();
 foreach ($hosts as $hostData) {
        /**
         * Zabbix Status 1 is disabled
@@ -36,19 +45,41 @@ foreach ($hosts as $hostData) {
                $hostid = $hostData->hostid;
                $trigger = $zabbix->fetch_array('trigger', 'get', array('output'=>'extend', 'hostids'=>array($hostid)));
                $host = '<a href="http://'.$hostData->host.'">'.str_replace('.typo3.org', '', $hostData->host).'</a>';
-        
+        $error = FALSE;
                $status = array();
+
                foreach ($trigger as $triggerData) {
                        if($triggerData->value == 1 ){
-                               if($triggerData->description == 'Web site failure') $status[] = 'failure';
-                               if($triggerData->description == 'Web site slow') $status[] = 'slow';
-                       }
+               if($triggerData->description == 'Web site failure'){
+                       $status[] = 'failure';
+                       $error = TRUE;
+                }
+            }
+               }
+               if($error === TRUE ){
+                       if(checkServerErrorAcknowledged($hostid)){
+                               $acknowledgedArray[$host] = '<div class="hostEntry slow">'.$host.'</div>';
+                       }else{
+                               $errorArray[$host] = '<div class="hostEntry error">'.$host.'</div>';
+                       }
+               }else{
+                       $okayArray[$host] = '<div class="hostEntry">'.$host.'</div>';
                }
-               $statusArray[$host] = '<div class="hostEntry '. implode(' ', $status) .'">'.$host.'</div>';
        }
 }
-ksort($statusArray);
-$statusDiv = implode('', $statusArray);
+ksort($okayArray);
+ksort($errorArray);
+ksort($acknowledgedArray);
+if(count($errorArray) + count($acknowledgedArray) > 0 ){
+       $statusDiv .= '<h2>Server on Error</h2>';
+       $statusDiv.='<div class="allErrors">';
+       $statusDiv .= implode('', $errorArray);
+       $statusDiv.='</div><div class="allAcknowledged">';
+       $statusDiv .= implode('', $acknowledgedArray);
+       $statusDiv.='</div>';
+       $statusDiv .= '<h2>Server stable running</h2>';
+}
+$statusDiv .= implode('', $okayArray);
 file_put_contents($temp_ajax, $statusDiv);
 if(isset($_GET['ajax']) && $_GET['ajax'] == 1){
      $content = $statusDiv;
index c3c4664..27788af 100644 (file)
             <div id="content">
                 <div id="statusStatistic">
                     <span id="allServer">0</span> Server monitored | 
-                    <span id="slowServer">0</span> Server slow | 
+                    <span id="slowServer">0</span> Server on acknowledged error | 
                     <span id="failureServer">0</span> Server failed
                 </div>
                 <div id="statusLog">{statusDiv}</div>
                 <div id="infoLog">
                     <h2>Server status</h2>
                     <p class="infoDemo">Server is ok</p>
-                    <p class="slowDemo infoDemo">Server is slow</p>
+                    <p class="slowDemo infoDemo">Server error is acknowledged</p>
                     <p class="failureDemo infoDemo">Server is on error</p>
                 </div>
                 <div id="twitter">
index 12a80c7..621f18a 100644 (file)
@@ -14,6 +14,13 @@ h1{
     margin-bottom: 0;
 }
 
+h2{
+       font-family: Share-Regular;
+       margin-top:0px;
+       margin-bottom: 0px;
+       padding-left:10px;      
+}
+
 header div{
     font-family: Share-Regular;
     text-align: right;