Fix the duplicate entries in monitoring list shows
refs #7057 refs #7344 fixes #7057
This commit is contained in:
parent
fcc56c9809
commit
afc97b1cac
|
@ -96,14 +96,14 @@ class DbQuery extends SimpleQuery
|
|||
public function getSelectQuery()
|
||||
{
|
||||
$select = $this->dbSelect();
|
||||
|
||||
// Add order fields to select for postgres distinct queries (#6351)
|
||||
if ($this->hasOrder()
|
||||
&& $this->getDatasource()->getDbType() === 'pgsql'
|
||||
&& $select->getPart(Zend_Db_Select::DISTINCT) === true) {
|
||||
foreach ($this->getOrder() as $fieldAndDirection) {
|
||||
list($alias, $field) = explode('.', $fieldAndDirection[0]);
|
||||
$this->columns[$field] = $fieldAndDirection[0];
|
||||
if (array_search($fieldAndDirection[0], $this->columns) === false) {
|
||||
$this->columns[] = $fieldAndDirection[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,6 +264,7 @@ class DbQuery extends SimpleQuery
|
|||
|
||||
$this->applyFilterSql($count);
|
||||
if ($this->useSubqueryCount) {
|
||||
$count->columns($this->columns);
|
||||
$columns = array('cnt' => 'COUNT(*)');
|
||||
return $this->db->select()->from($count, $columns);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class GroupSummaryQuery extends IdoQuery
|
|||
}
|
||||
|
||||
$union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
$this->select->from(array('statussummary' => $union), array($groupColumn))->group(array($groupColumn));
|
||||
$this->select->from(array('statussummary' => $union), array())->group(array($groupColumn));
|
||||
|
||||
$this->joinedVirtualTables = array(
|
||||
'servicestatussummary' => true,
|
||||
|
|
|
@ -8,6 +8,29 @@ use Zend_Db_Expr;
|
|||
|
||||
class StatusQuery extends IdoQuery
|
||||
{
|
||||
/**
|
||||
* This mode represents whether we are in HostStatus or ServiceStatus
|
||||
*
|
||||
* Implemented for `distinct as workaround
|
||||
*
|
||||
* @TODO Subject to change, see #7344
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mode;
|
||||
|
||||
/**
|
||||
* Sets the mode of the current query
|
||||
*
|
||||
* @TODO Subject to change, see #7344
|
||||
*
|
||||
* @param string $mode
|
||||
*/
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
protected $allowCustomVars = true;
|
||||
|
||||
protected $columnMap = array(
|
||||
|
@ -430,6 +453,12 @@ class StatusQuery extends IdoQuery
|
|||
array()
|
||||
);
|
||||
|
||||
// @TODO Subject to change, see #7344
|
||||
if ($this->mode === 'host' || $this->mode === 'service') {
|
||||
$this->useSubqueryCount = true;
|
||||
$this->distinct();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -449,7 +478,11 @@ class StatusQuery extends IdoQuery
|
|||
. ' AND hgo.is_active = 1',
|
||||
array()
|
||||
);
|
||||
|
||||
// @TODO Subject to change, see #7344
|
||||
if ($this->mode === 'service') {
|
||||
$this->distinct();
|
||||
$this->useSubqueryCount = true;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -471,6 +504,14 @@ class StatusQuery extends IdoQuery
|
|||
array()
|
||||
);
|
||||
|
||||
// @TODO Subject to change, see #7344
|
||||
if ($this->mode === 'host' || $this->mode === 'service') {
|
||||
$this->distinct();
|
||||
}
|
||||
if ($this->mode === 'host') {
|
||||
$this->useSubqueryCount = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
|
|||
*
|
||||
* @var \Icinga\Data\SimpleQuery
|
||||
*/
|
||||
private $query;
|
||||
protected $query;
|
||||
|
||||
protected $filter;
|
||||
|
||||
|
@ -47,6 +47,18 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
|
|||
$queryClass = $connection->getQueryClass($this->getQueryName());
|
||||
$this->query = new $queryClass($this->connection->getResource(), $columns);
|
||||
$this->filter = Filter::matchAll();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializer for `distinct purposes
|
||||
*
|
||||
* Implemented for `distinct as workaround
|
||||
*
|
||||
* @TODO Subject to change, see #7344
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,14 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
|
||||
class HostStatus extends DataView
|
||||
{
|
||||
/**
|
||||
* @see DataView::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->query->setMode('host');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
|
|
|
@ -6,6 +6,16 @@ namespace Icinga\Module\Monitoring\DataView;
|
|||
|
||||
class ServiceStatus extends DataView
|
||||
{
|
||||
/**
|
||||
* Sets the mode for `distinct as workaround
|
||||
*
|
||||
* @TODO Subject to change, see #7344
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->query->setMode('service');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue