diff --git a/library/Icinga/Protocol/File/Query.php b/library/Icinga/Protocol/File/Query.php index d51461891..e6fd40f48 100644 --- a/library/Icinga/Protocol/File/Query.php +++ b/library/Icinga/Protocol/File/Query.php @@ -13,11 +13,6 @@ class Query extends BaseQuery public function applyFilter() {}// ? - public function count() - { - return $this->ds->count(); - } - public function order($dir) { $this->sortDir = ($dir === null || strtoupper(trim($dir)) === 'DESC') ? self::SORT_DESC : self::SORT_ASC; diff --git a/library/Icinga/Protocol/File/Reader.php b/library/Icinga/Protocol/File/Reader.php index e889f1109..b00269079 100644 --- a/library/Icinga/Protocol/File/Reader.php +++ b/library/Icinga/Protocol/File/Reader.php @@ -10,15 +10,10 @@ class Reader implements DatasourceInterface private $config; - private $queryCache = null; - public function __construct($config) { $this->config = $config; $this->filename = $config->filename; - var_dump($this->readFromStart());//NO! - //var_dump($this->fetchOne(new Query($this))); - die;//NO! } public function select() @@ -75,14 +70,14 @@ class Reader implements DatasourceInterface return $this->read($query); } - public function validateLine($line) + public function validateLine($line, Query $query) { $data = array(); $PCRE_result = @preg_match($this->config->fields, $line, $data); if ($PCRE_result === false) { throw new \Exception('Failed parsing regular expression!'); } else if ($PCRE_result === 1) { - foreach ($this->queryCache->getFilters() as $filter) { + foreach ($query->getFilters() as $filter) { if (strpos($line, $filter) === false) { return false; } @@ -104,17 +99,13 @@ class Reader implements DatasourceInterface if ($skip_lines === null) { $skip_lines = 0; } - $this->queryCache = $query; if ($query->sortDesc()) { - $data = $this->readFromEnd($skip_lines, $read_lines); - } else { - $data = $this->readFromStart($skip_lines, $read_lines); + return $this->readFromEnd($skip_lines, $read_lines, $query); } - $this->queryCache = null; - return $data; + return $this->readFromStart($skip_lines, $read_lines, $query); } - public function readFromEnd($skip_lines = null, $read_lines = null) + public function readFromEnd($skip_lines = null, $read_lines = null, Query $query) { $PHP_EOL_len = strlen(PHP_EOL); $lines = array(); @@ -126,7 +117,7 @@ class Reader implements DatasourceInterface fseek($f, --$pos); $c = fgetc($f); if ($c === false || $pos < 0) { - $l = $this->validateLine($s); + $l = $this->validateLine($s, $query); if (!($l === false || $skip_lines)) { $lines[] = $l; } @@ -134,7 +125,7 @@ class Reader implements DatasourceInterface } $s = $c . $s; if (strpos($s, PHP_EOL) === 0) { - $l = $this->validateLine((string)substr($s, $PHP_EOL_len)); + $l = $this->validateLine((string)substr($s, $PHP_EOL_len), $query); if ($l !== false) { if ($skip_lines) { $skip_lines--; @@ -148,7 +139,7 @@ class Reader implements DatasourceInterface return $lines; } - public function readFromStart($skip_lines = null, $read_lines = null) + public function readFromStart($skip_lines = null, $read_lines = null, Query $query) { $PHP_EOL_len = strlen(PHP_EOL); $lines = array(); @@ -157,7 +148,7 @@ class Reader implements DatasourceInterface while ($read_lines === null || count($lines) < $read_lines) { $c = fgetc($f); if ($c === false) { - $l = $this->validateLine($s); + $l = $this->validateLine($s, $query); if (!($l === false || $skip_lines)) { $lines[] = $l; } @@ -165,7 +156,7 @@ class Reader implements DatasourceInterface } $s .= $c; if (strpos($s, PHP_EOL) !== false) { - $l = $this->validateLine((string)substr($s, 0, strlen($s) - $PHP_EOL_len)); + $l = $this->validateLine((string)substr($s, 0, strlen($s) - $PHP_EOL_len), $query); if ($l !== false) { if ($skip_lines) { $skip_lines--; @@ -179,7 +170,7 @@ class Reader implements DatasourceInterface return $lines; } - public function count() { + public function count(Query $query) { $PHP_EOL_len = strlen(PHP_EOL); $lines = 0; $s = ''; @@ -190,14 +181,14 @@ class Reader implements DatasourceInterface fseek($f, --$pos); $c = fgetc($f); if ($c === false || $pos < 0) { - if ($this->validateLine($s) !== false) { + if ($this->validateLine($s, $query) !== false) { $lines++; } break; } $s = $c . $s; if (strpos($s, PHP_EOL) === 0) { - if ($this->validateLine((string)substr($s, $PHP_EOL_len)) !== false) { + if ($this->validateLine((string)substr($s, $PHP_EOL_len), $query) !== false) { $lines++; } $s = ''; diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 459891391..c875ed69e 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -642,45 +642,12 @@ class Monitoring_ListController extends Controller ) { $config = ResourceFactory::getResourceConfig('logfile'); $resource = ResourceFactory::createResource($config); + $this->view->logData = $resource->select()->paginate(); - $resource->select()->andWhere('error')->order('desc')->limit(200, 50)->fetchAll(); - - var_dump($config, $resource); - die; - $log = new LogFile($config_ini['logging']['target']); - $this->view->logLines = $log->count(); - $this->view->logData = $log->readFromEnd(1, 38); + //$resource->select()->andWhere('error')->order('desc')->limit(200, 50)->fetchAll(); } else { $this->view->logData = null; } - /*$dataview = EventHistoryView::fromRequest( - $this->getRequest(), - array( - 'host_name', - 'service_description', - 'object_type', - 'timestamp', - 'raw_timestamp', - 'state', - 'attempt', - 'max_attempts', - 'output', - 'type', - 'host', - 'service' - ) - ); - - $this->setupFilterControl($dataview, 'eventhistory'); - $this->setupSortControl( - array( - 'raw_timestamp' => 'Occurence' - ) - ); - - $query = $dataview->getQuery(); - $this->handleFormatRequest($query); - $this->view->history = $query->paginate();*/ } } // @codingStandardsIgnoreEnd diff --git a/modules/monitoring/application/views/scripts/list/applicationlog.phtml b/modules/monitoring/application/views/scripts/list/applicationlog.phtml index 87aa65049..68b115152 100644 --- a/modules/monitoring/application/views/scripts/list/applicationlog.phtml +++ b/modules/monitoring/application/views/scripts/list/applicationlog.phtml @@ -1,33 +1,21 @@ -logData; -foreach ($logData as $key => $value) { - list($datetime, $remaining) = explode(' ', $value, 2); - list($loglevel, $msg) = explode(': ', $remaining, 2); - $loglevel = explode(' ', $loglevel, 2); - $logData[$key] = array( - new DateTime($datetime), - $loglevel[0], - $msg - ); - $logData[$key][0] = $logData[$key][0]->format('d.m. H:i'); -} -?> -
- tabs->render($this); ?> + tabs->render($this) ?> +
+ logData ?>
- + logData as $value): ?> + datetime); ?>
- escape($value[0]) ?>
- escape($value[1]) ?> + escape($datetime->format('d.m. H:i')) ?>
+ escape($value->loglevel) ?>
- escape($value[2]) ?> + escape($value->message) ?>