Browse Source

use hostid for quicker filter

pull/5/merge
Kai Kretschmann 2 years ago
parent
commit
f92c1d50f9
4 changed files with 62 additions and 32 deletions
  1. +5
    -1
      do.php
  2. +33
    -15
      inc/lggr_class.php
  3. +16
    -8
      inc/lggrstate_class.php
  4. +8
    -8
      index.php

+ 5
- 1
do.php View File

@@ -37,7 +37,11 @@ switch($_REQUEST['a']) {
break;

case 'host':
$state->setHost($_GET['host']);
$config = new Config();
$l = new Lggr($state, $config);
$id = intval($_GET['hostid']);
$state->setHostName($l->getServersName($id));
$state->setHostId($id);
$state->setPage(0);
$state->setResultSize(0);
break;

+ 33
- 15
inc/lggr_class.php View File

@@ -101,14 +101,8 @@ ORDER BY c DESC
$perf = new LggrPerf();

$sql = "
SELECT DISTINCT host
FROM newlogs";

$a = $this->cache->retrieve("allservers");
if(null != $a) {
return $a;
} // if
$a = array();
SELECT id,name AS host
FROM servers";

$perf->start($sql);

@@ -123,10 +117,34 @@ FROM newlogs";

$perf->stop();
$this->aPerf[] = $perf;
return $a;
} // function

$this->cache->store("allservers", $a);
function getServersName($id) {
$perf = new LggrPerf();
$sql = "
SELECT name
FROM servers
WHERE id=$id";
$perf->start($sql);

return $a;
$a = null;
$res = $this->db->query($sql);
if(false === $res) {
throw new Exception($this->db->error);
} // if
if($row = $res->fetch_object()) {
$a = $row;
} // while
$res->close();
$perf->stop();
$this->aPerf[] = $perf;

return $a->name;
} // function

function getServers() {
@@ -325,19 +343,19 @@ LIMIT $from,$count";
$perfSize = new LggrPerf();
$perfData = new LggrPerf();

$sHost = $this->db->escape_string($this->state->getHost());
$iHost = $this->state->getHostId();
$sFrom = $this->db->escape_string($this->state->getFrom());
$sTo = $this->db->escape_string($this->state->getTo());

$sqlSize = "
SELECT COUNT(*) AS c FROM newlogs
WHERE `date` BETWEEN '$sFrom' AND '$sTo'
AND host='$sHost'";
AND idhost=$iHost";

$sqlData = "
SELECT * FROM newlogs
WHERE `date` BETWEEN '$sFrom' AND '$sTo'
AND host='$sHost'
AND idhost=$iHost
ORDER BY `date` DESC
LIMIT $from,$count";

@@ -375,8 +393,8 @@ LIMIT $from,$count";
} // if

if(count($aWhere) > 0) {
$sqlSize .= " WHERE " . implode(INNERAND, $aWhere);
$sqlData .= " WHERE " . implode(INNERAND, $aWhere);
$sqlSize .= " WHERE " . implode(Lggr::INNERAND, $aWhere);
$sqlData .= " WHERE " . implode(Lggr::INNERAND, $aWhere);
} // if

$sqlData .= " ORDER BY `date` DESC LIMIT $from,$count";

+ 16
- 8
inc/lggrstate_class.php View File

@@ -10,7 +10,8 @@ class LggrState {
private $sSearch=null;
private $sSearchProg=null;
private $iPage=0;
private $sHost=null;
private $sHostName=null;
private $iHost=0;
private $sLevel=null;
private $iRange=24; // default 24h = today, sort of
private $bFromTo=false;
@@ -26,7 +27,8 @@ class LggrState {
$this->sSearch=null;
$this->bSearchProg=false;
$this->sSearchProg=null;
$this->sHost=null;
$this->sHostName=null;
$this->iHost=0;
$this->sLevel=null;
$this->iRange=24;
$this->bFromTo=false;
@@ -66,16 +68,22 @@ class LggrState {
return $this->iPage;
}

public function setHost($s) {
$this->sHost = $s;
public function setHostName($s) {
$this->sHostName = $s;
}
public function getHost() {
return $this->sHost;
public function getHostName() {
return $this->sHostName;
}
public function setHostId($id) {
$this->iHost = $id;
}
public function getHostId() {
return $this->iHost;
}
public function isHost() {
return null != $this->sHost;
return 0 != $this->iHost;
}

public function setLevel($s) {
$this->sLevel = $s;
}

+ 8
- 8
index.php View File

@@ -46,19 +46,19 @@ try {

} elseif($state->isFromTo() && $state->isHost()) {

$host = $state->getHost();
$host = $state->getHostName();

$aEvents = $l->getHostFromTo($page*LggrState::PAGELEN, LggrState::PAGELEN);

$sFilter = _('Filter by time range between') . ' <strong>' . htmlentities($state->getFrom(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong> ' . _('and') . ' <strong>' . htmlentities($state->getTo(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>, ';
$sFilter .= _('Filter by server') . ' <strong>' . htmlentities($state->getHost(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>';
$sFilter .= _('Filter by server') . ' <strong>' . htmlentities($state->getHostName(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>';
$searchvalue='';
$searchvalueprog='';
$isSearch=false;

} elseif($state->isHost() || $state->isLevel()) {

$host = $state->getHost();
$host = $state->getHostName();
$level = $state->getLevel();

$aEvents = $l->getFiltered($host, $level, $page*LggrState::PAGELEN, LggrState::PAGELEN);
@@ -67,7 +67,7 @@ try {
$isSearch=false;
$sFilter='';
if($state->isHost()) {
$sFilter .= _('Filter by server') . ' <strong>' . htmlentities($state->getHost(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>';
$sFilter .= _('Filter by server') . ' <strong>' . htmlentities($state->getHostName(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>';
}
if($state->isLevel()) {
$sFilter .= _('Filter by level') . ' <strong>' . htmlentities($state->getLevel(), ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES) . '</strong>';
@@ -204,11 +204,11 @@ EOL;
<?php
$aServerList = array();
foreach($aAllServers as $server) {
$aServerList[] = $server->host;
$aServerList[$server->host] = $server->id;
} // foreach
sort($aServerList);
foreach($aServerList as $server) {
echo '<li role="presentation"><a role="menuitem" tabindex="-1" href="./do.php?a=host&host=' . urlencode($server) . '">' . $server . '</a></li>';
ksort($aServerList);
foreach($aServerList as $servername => $serverid) {
echo '<li role="presentation"><a role="menuitem" tabindex="-1" href="./do.php?a=host&hostid=' . $serverid . '">' . $servername . '</a></li>';
} // foreach
?>
</ul>

Loading…
Cancel
Save
Social stuff:
Mastodon