[icinga-checkins] icinga.org: icinga-web/master: Fixed log counters (fixes #3289)

git at icinga.org git at icinga.org
Mon Oct 15 13:27:16 CEST 2012


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

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Mon Oct 15 13:26:58 2012 +0200

Fixed log counters (fixes #3289)

---

 app/modules/AppKit/models/LogParserModel.class.php |   46 +++++++++++---------
 .../AppKit/templates/Admin/ViewLogsSuccess.php     |    2 +-
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/app/modules/AppKit/models/LogParserModel.class.php b/app/modules/AppKit/models/LogParserModel.class.php
old mode 100644
new mode 100755
index 0c2f14c..c7d78f6
--- a/app/modules/AppKit/models/LogParserModel.class.php
+++ b/app/modules/AppKit/models/LogParserModel.class.php
@@ -42,7 +42,7 @@ class AppKit_LogParserModel extends AppKitBaseModel {
 
     }
 
-    protected function getEntriesFromFiles(array $files,$start=0,$end=100,$dir = "desc") {
+    protected function getEntriesFromFiles(array $files,$start=0,$end=15,$dir = "desc") {
         if ($dir == "desc") {
             rsort($files);
         } else {
@@ -55,13 +55,16 @@ class AppKit_LogParserModel extends AppKitBaseModel {
 
         foreach($files as $file) {
             $currentLog = $base."/".$file;
-            $string = array_merge($string, $this->readFileDesc($currentLog,$start,$end,$this->entriesRead >= $end));
+            $this->readFileDesc($currentLog,$start,$end,$this->entriesRead >= $end,$string);
+            
 
         }
         return $string;
     }
 
-    private function readFileDesc($log, &$start,$end, $justCount = false) {
+   
+    
+    private function readFileDesc($log, &$start,$end, $justCount = false,array &$string) {
         $handle = fopen($log,"r");
         if(!$handle)
             return array();
@@ -75,26 +78,27 @@ class AppKit_LogParserModel extends AppKitBaseModel {
         }
         if($justCount)
             return array();
-        fseek($handle,$pos,SEEK_END);
-        $string = array();
-        while (false !== ($char = fgetc($handle))) {
-
-            if(($char == "\n" ) && ($start-- <= 0)) {
-                  
-                $line = fgets($handle);
-                if($line !== false) {
-                    if($line[0] == "[") {
-                        $string [] = $line;
-                        $this->entriesRead++;
-                    } else if(count($string) > 0) {
-                        $string[count($string)-1] .= " ".$line;
-                    }
-                    if($this->entriesRead == $end)
-                        break;
+        fseek($handle,0,SEEK_SET);
+        $currentLine = "";
+        
+        while (($line = fgets($handle)) !== false) {
+            
+            if($line[0] == "[") {
+                if($currentLine != "" && $start < 0) {
+                    $string[] = $currentLine;
+                    $this->entriesRead++;
                 }
+                $currentLine = "";
+                if($start >= -1)
+                    $start--; 
             }
-            $start = $start < 0 ? 0 : $start; // prevent underflow
-            fseek($handle,--$pos,SEEK_END);
+            $currentLine .= $line;
+            if(count($string) >= $end-1)
+                break;
+        }
+        if($currentLine != "" && $start < 0) {
+            $string[] = $currentLine;
+            $this->entriesRead++;
         }
         fclose($handle);
         return $string;
diff --git a/app/modules/AppKit/templates/Admin/ViewLogsSuccess.php b/app/modules/AppKit/templates/Admin/ViewLogsSuccess.php
index d6275f7..19d4fdc 100755
--- a/app/modules/AppKit/templates/Admin/ViewLogsSuccess.php
+++ b/app/modules/AppKit/templates/Admin/ViewLogsSuccess.php
@@ -58,7 +58,7 @@ Cronk.util.initEnvironment('viewport-center', function() {
                     return false;
                 var logName = _dview.getRecord(elem).get('Name');
                 logGrid.getStore().setBaseParam("logFile",logName);
-                logGrid.getStore().load({params: {limit: 100}});
+                logGrid.getStore().load({params: {limit: 100,start:0}});
             }
         }
     });





More information about the icinga-checkins mailing list