parent
933a851f65
commit
7c599e206e
|
@ -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;
|
||||
|
|
|
@ -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 = '';
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,33 +1,21 @@
|
|||
<?php
|
||||
$logData = $this->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');
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="controls">
|
||||
<?= $this->tabs->render($this); ?>
|
||||
<?= $this->tabs->render($this) ?>
|
||||
<div style="margin-top: 1em"></div>
|
||||
<?= $this->logData ?>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<table class="action">
|
||||
<tbody>
|
||||
<?php foreach ($logData as $value): ?>
|
||||
<?php foreach ($this->logData as $value): ?>
|
||||
<?php $datetime = new Datetime($value->datetime); ?>
|
||||
<tr class="state">
|
||||
<td style="width: 6em; text-align: center">
|
||||
<?= $this->escape($value[0]) ?><br />
|
||||
<?= $this->escape($value[1]) ?>
|
||||
<?= $this->escape($datetime->format('d.m. H:i')) ?><br />
|
||||
<?= $this->escape($value->loglevel) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $this->escape($value[2]) ?>
|
||||
<?= $this->escape($value->message) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
|
Loading…
Reference in New Issue