Code

Updated rSyslog view
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 18 Dec 2009 15:17:28 +0000 (15:17 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 18 Dec 2009 15:17:28 +0000 (15:17 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14910 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/rsyslog/addons/rsyslog/class_rsyslog.inc
gosa-plugins/rsyslog/addons/rsyslog/rSyslog.tpl

index 49a7d14ea782d4042f08433afe5042c6b9f62d91..fe25e7b9c2375b0b8691347374830f22d92e5bdb 100644 (file)
@@ -9,11 +9,23 @@ class rsyslog extends plugin
   var $selected_server = "";
   var $selected_host = "";
 
+  var $startTime = "";
+  var $stopTime  = "";
+
+  var $sort_value  = "FromHost";
+  var $sort_type  = "DESC";
+  var $limit  = 20;
+  var $limits = array(20,50,100,200,500,1000,'-');
+  var $page   = 0;
+
   function rsyslog (&$config, $dn= NULL)
   {
     $this->config= &$config;
     $this->ui = get_userinfo();
 
+    $this->startTime = date("d.m.Y", (time() - 7*24*60*60));
+    $this->stopTime  = date("d.m.Y", time());
+
     // Get list of rsyslog servers 
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
@@ -75,6 +87,7 @@ class rsyslog extends plugin
   function execute()
   {
     $smarty = get_smarty();
+    $smarty->assign("usePrototype", "true");
     $ui = get_userinfo();
     
     if(!isset($this->servers[$this->selected_server]) || !count($this->servers[$this->selected_server]['Hosts'])){
@@ -84,11 +97,29 @@ class rsyslog extends plugin
       $hosts = array_merge($hosts,$this->servers[$this->selected_server]['Hosts']);
     }
 
+    $result =$this->get_result();
+
     $smarty->assign("servers",$this->servers);
     $smarty->assign("hosts",$hosts);
     $smarty->assign("selected_server",$this->selected_server);
     $smarty->assign("selected_host",$this->selected_host);
-    $smarty->assign("result", $this->get_result());
+    $smarty->assign("startTime",  $this->startTime);
+    $smarty->assign("stopTime",    $this->stopTime);
+    $smarty->assign("sort_type",    $this->sort_type);
+    $smarty->assign("sort_value",   $this->sort_value);
+    $smarty->assign("limits",   $this->limits);
+    $smarty->assign("limit",    $this->limit);
+    $smarty->assign("page",    $this->page);
+    $smarty->assign("plug_id", $_GET['plug']);
+    $smarty->assign("downimg", "<img src='images/lists/sort-down.png' class='center' alt='\\/' border='0'>");
+    $smarty->assign("upimg", "<img src='images/lists/sort-up.png' class='center' alt='\\/' border='0'>");
+    $smarty->assign("result", $result);
+    if($this->limit != '-'){
+      $smarty->assign("page_sel", range_selector($result['count'],$this->page,$this->limits[$this->limit]));
+    }else{
+      $smarty->assign("page_sel", "");
+    }
+
     return($smarty->fetch(get_template_path("rSyslog.tpl", TRUE)));
   }
 
@@ -130,9 +161,10 @@ class rsyslog extends plugin
       $host = "%%";
       if($this->selected_host != "all") $host = $this->selected_host;
 
-    
-      $filter = "FROM SystemEvents WHERE FromHost like '{$host}' LIMIT 20;";
-      
+      $filter = "FROM SystemEvents WHERE FromHost like '{$host}' ";
+      $filter.= "AND DeviceReportedTime >= '".(date("Y.m.d 00:00:00", strtotime($this->startTime)))."' ";     
+      $filter.= "AND DeviceReportedTime <= '".(date("Y.m.d 23:59:59", strtotime($this->stopTime)))."' ";     
+
       // Detect amount of matching entries 
       $query = "SELECT count(ID) as `amount` ".$filter;
       $res = @mysql_query($query, $link);
@@ -144,9 +176,14 @@ class rsyslog extends plugin
       }
 
       if($result['count']){
-
+        $filter.= "ORDER BY ".$this->sort_value." ".$this->sort_type." ";
+        if($this->limit != "-"){
+          $filter.= "LIMIT ".$this->page.", ".$this->limits[$this->limit];
+        }else{
+          $this->page = 0;
+        }
         $query = "SELECT * ".$filter;
-        $res = @mysql_query($query, $link);
+        $res = mysql_query($query, $link);
         if($res){
           while($attrs = @mysql_fetch_assoc($res)){
             $result['entries'][] = $attrs;
@@ -167,9 +204,27 @@ class rsyslog extends plugin
 
   function save_object()
   {
-    foreach(array("selected_host","selected_server") as $attr){
+    foreach(array("selected_host","selected_server","stopTime","startTime") as $attr){
       if(isset($_POST[$attr])) $this->$attr = get_post($attr);
     }
+
+    if(isset($_GET['start'])) $this->page = $_GET['start'];
+    if(isset($_POST['limit']) && isset($this->limits[$_POST['limit']])){
+      $this->limit = $_POST['limit'];
+    }
+
+    if(isset($_GET['sort_value']) && in_array($_GET['sort_value'], 
+          array("DeviceReportedTime","FromHost","Facility","Priority","Message"))){
+      $sort_value = $_GET['sort_value'];
+      if($this->sort_value == $sort_value){
+        if($this->sort_type == "ASC"){
+          $this->sort_type="DESC"; 
+        }else{
+          $this->sort_type="ASC"; 
+        }
+      } 
+      $this->sort_value=$sort_value; 
+    } 
   }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index ba5573445f10a21701949b8f2de66072f6510934..4c0df584dbbe7b37dc607c5af7712fe5cc1053fc 100644 (file)
 
-<select name='selected_server' onChange='document.mainform.submit();'>
-  {foreach from=$servers item=item key=key}
-    <option value='{$key}' {if $key == $selected_server} selected {/if}>{$item.cn}</option>
-  {/foreach}
-</select>
-
-<select name='selected_host' onChange='document.mainform.submit();'>
-  {foreach from=$hosts item=item key=key}
-    <option value='{$key}' {if $key == $selected_host} selected {/if}>{$item}</option>
-  {/foreach}
-</select>
+<table width="100%">
+  <tr>
+    <td>{t}Server{/t}:</td>
+    <td>   
+      <select name='selected_server' onChange='document.mainform.submit();'>
+        {foreach from=$servers item=item key=key}
+          <option value='{$key}' {if $key == $selected_server} selected {/if}>{$item.cn}</option>
+        {/foreach}
+      </select>
+    </td>
+    <td>{t}Host{/t}:</td>
+    <td>   
+      <select name='selected_host' onChange='document.mainform.submit();'>
+        {foreach from=$hosts item=item key=key}
+          <option value='{$key}' {if $key == $selected_host} selected {/if}>{$item}</option>
+        {/foreach}
+      </select>
+    </td>
+    <td>{t}From{/t}:</td>
+    <td>
+      <input type="text" id="startTime" name="startTime" class="date" style='width:100px' value="{$startTime}">
+      <script type="text/javascript">
+        {literal}
+        var datepicker  = new DatePicker({ relative : 'startTime', language : '{/literal}{$lang}{literal}', keepFieldEmpty : true,
+           enableCloseEffect : false, enableShowEffect : false });
+        {/literal}
+      </script> 
+    </td>
+    <td>{t}to{/t}:</td>
+    <td>
+      <input type="text" id="stopTime" name="stopTime" class="date" style='width:100px' value="{$stopTime}">
+      <script type="text/javascript">
+        {literal}
+        var datepicker  = new DatePicker({ relative : 'stopTime', language : '{/literal}{$lang}{literal}', keepFieldEmpty : true,
+           enableCloseEffect : false, enableShowEffect : false });
+        {/literal}
+      </script> 
+    </td>
+    <td><input type='submit' name='search' value="{t}Search{/t}">
+  </tr>
+</table>
 
 <p class="separator">&nbsp;</p>
 {if $result.status != 'ok'}
   <b>{t}Error{/t}: &nbsp;{$result.status}</b><br>
   {$result.error}<br>
 {else}
-  <b>{t}Results{/t}:</b>
-  <table>
+
+  <br>
+  <table width="100%">
+    <tr>
+      <td>
+        <b>
+          <a href='?plug={$plug_id}&amp;sort_value=DeviceReportedTime'>{t}Received{/t}
+            {if $sort_value=="DeviceReportedTime"}{if $sort_type=="DESC"}{$downimg}{else}{$upimg}{/if}{/if}
+          </a>
+        </b>
+      </td>
+      <td>
+        <b>
+          <a href='?plug={$plug_id}&amp;sort_value=FromHost'>{t}Host{/t}
+            {if $sort_value=="FromHost"}{if $sort_type=="DESC"}{$downimg}{else}{$upimg}{/if}{/if}
+          </a>
+        </b>
+      </td>
+      <td>
+        <b>
+          <a href='?plug={$plug_id}&amp;sort_value=Facility'>{t}Facility{/t}
+            {if $sort_value=="Facility"}{if $sort_type=="DESC"}{$downimg}{else}{$upimg}{/if}{/if}
+          </a>
+        </b>
+      </td>
+      <td>
+        <b>
+          <a href='?plug={$plug_id}&amp;sort_value=Priority'>{t}Priority{/t}
+            {if $sort_value=="Priority"}{if $sort_type=="DESC"}{$downimg}{else}{$upimg}{/if}{/if}
+          </a>
+        </b>
+      </td>
+      <td>
+        <b>
+          <a href='?plug={$plug_id}&amp;sort_value=Message'>{t}Message{/t}
+            {if $sort_value=="Message"}{if $sort_type=="DESC"}{$downimg}{else}{$upimg}{/if}{/if}
+          </a>
+        </b>
+      </td>
+    </tr>
+    <tr><td colspan="5"><p class="separator">&nbsp;</p></td></tr>
     {foreach from=$result.entries item=item key=key}
     <tr>
-      <td>{$item.DeviceReportedTime}</td>
-      <td>{$item.FromHost}</td>
-      <td>{$item.Facility}</td>
-      <td>{$item.Priority}</td>
-      <td>{$item.Message}</td>
+      <td title='{$item.DeviceReportedTime}' style='width:120px'>
+        {$item.DeviceReportedTime}
+      </td>
+      <td title='{$item.FromHost}'>
+        {$item.FromHost}
+      </td>
+      <td title='{$item.Facility}'>
+        {$item.Facility}
+      </td>
+      <td title='{$item.Priority}'>
+        {$item.Priority}
+      </td>
+      <td title='{$item.Message}' style="width:600px">
+        <div style='overflow:hidden; width:600px'><nobr>{$item.Message}</nobr></div>
+      </td>
     </tr>
     {/foreach}
   </table>
-  {$result.count} {t}entries matching filter{/t}
+  {if !$result.count == 0}
+  <p class="separator">&nbsp;</p>
+  {/if}
+  <div style='width:40%;float:left;'>{$result.count} {t}entries matching filter{/t}</div>
+  <div style='width:80px;float:right;'>
+    <select name='limit' onChange='document.mainform.submit();'>
+      {html_options options=$limits selected=$limit}
+    </select>
+  </div>
+  <div style='width:200px;float:left;'>{$page_sel}</div>
 {/if}