Livestatus\Query: start using new filter methods

This commit is contained in:
Thomas Gelf 2014-11-16 15:48:59 +01:00
parent 3b1b38a353
commit 578873f695

View File

@ -17,6 +17,13 @@ use Exception;
class Query extends SimpleQuery class Query extends SimpleQuery
{ {
/**
* Columns that return arrays. Will be decoded.
*/
protected $arrayColumns = array(
'members' => true,
);
/** /**
* All available columns. To be overridden by specific query implementations * All available columns. To be overridden by specific query implementations
*/ */
@ -130,24 +137,16 @@ class Query extends SimpleQuery
$parts = array( $parts = array(
sprintf('GET %s', $this->table) sprintf('GET %s', $this->table)
); );
if ($this->count === false && $this->columns !== null) {
$parts[] = 'Columns: ' . implode(' ', $this->columns); // Fetch all required columns
} $parts[] = $this->columnsToString();
foreach ($this->filters as $key => $val) {
if ($key === 'search') { // In case we need to apply a userspace filter as of Livestatus lacking
$parts[] = 'Filter: host_name ~~ ' . $val; // support for some of them we also need to fetch all filtered columns
$parts[] = 'Filter: description ~~ ' . $val; if ($this->filterIsSupported() && $filter = $this->filterToString()) {
$parts[] = 'Or: 2'; $parts[] = $filter;
continue;
}
if ($val === null) {
$parts[] = 'Filter: ' . $key;
} elseif (strpos($key, '?') === false) {
$parts[] = sprintf('Filter: %s = %s', $key, $val);
} else {
$parts[] = sprintf('Filter: %s', str_replace('?', $val, $key));
}
} }
if ($this->count === true) { if ($this->count === true) {
$parts[] = 'Stats: state >= 0'; $parts[] = 'Stats: state >= 0';
} }