From 578873f69538b6a1f23bc74dece72f16b18a07e9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 16 Nov 2014 15:48:59 +0100 Subject: [PATCH] Livestatus\Query: start using new filter methods --- library/Icinga/Protocol/Livestatus/Query.php | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/library/Icinga/Protocol/Livestatus/Query.php b/library/Icinga/Protocol/Livestatus/Query.php index 60581d1bf..4e174bf3b 100644 --- a/library/Icinga/Protocol/Livestatus/Query.php +++ b/library/Icinga/Protocol/Livestatus/Query.php @@ -17,6 +17,13 @@ use Exception; 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 */ @@ -130,24 +137,16 @@ class Query extends SimpleQuery $parts = array( sprintf('GET %s', $this->table) ); - if ($this->count === false && $this->columns !== null) { - $parts[] = 'Columns: ' . implode(' ', $this->columns); - } - foreach ($this->filters as $key => $val) { - if ($key === 'search') { - $parts[] = 'Filter: host_name ~~ ' . $val; - $parts[] = 'Filter: description ~~ ' . $val; - $parts[] = 'Or: 2'; - 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)); - } + + // Fetch all required columns + $parts[] = $this->columnsToString(); + + // In case we need to apply a userspace filter as of Livestatus lacking + // support for some of them we also need to fetch all filtered columns + if ($this->filterIsSupported() && $filter = $this->filterToString()) { + $parts[] = $filter; } + if ($this->count === true) { $parts[] = 'Stats: state >= 0'; }