mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
commit
d27d993395
@ -59,6 +59,13 @@ class DbQuery extends SimpleQuery
|
||||
*/
|
||||
protected $count;
|
||||
|
||||
/**
|
||||
* GROUP BY clauses
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->db = $this->ds->getDbAdapter();
|
||||
@ -100,6 +107,10 @@ class DbQuery extends SimpleQuery
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->group) {
|
||||
$select->group($this->group);
|
||||
}
|
||||
|
||||
$select->columns($this->columns);
|
||||
$this->applyFilterSql($select);
|
||||
|
||||
@ -300,4 +311,17 @@ class DbQuery extends SimpleQuery
|
||||
{
|
||||
return (string) $this->getSelectQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a GROUP BY clause
|
||||
*
|
||||
* @param string|array $group
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function group($group)
|
||||
{
|
||||
$this->group = $group;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
12
library/Icinga/Exception/QueryException.php
Normal file
12
library/Icinga/Exception/QueryException.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if a query contains invalid parameters
|
||||
*/
|
||||
class QueryException extends IcingaException
|
||||
{
|
||||
}
|
@ -44,7 +44,6 @@ class GroupSummaryQuery extends IdoQuery
|
||||
$columns = array(
|
||||
'object_type',
|
||||
'host_state',
|
||||
'host_name'
|
||||
);
|
||||
|
||||
// Prepend group column since we'll use columns index 0 later for grouping
|
||||
@ -61,6 +60,9 @@ class GroupSummaryQuery extends IdoQuery
|
||||
'in_downtime' => 'host_in_downtime'
|
||||
)
|
||||
);
|
||||
if (in_array('servicegroup', $this->desiredColumns)) {
|
||||
$hosts->group(array('sgo.name1', 'ho.object_id', 'state', 'acknowledged', 'in_downtime'));
|
||||
}
|
||||
$services = $this->createSubQuery(
|
||||
'Status',
|
||||
$columns + array(
|
||||
|
@ -6,12 +6,14 @@ namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
use Countable;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filter\FilterMatch;
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Data\Browsable;
|
||||
use Icinga\Data\PivotTable;
|
||||
use Icinga\Data\Sortable;
|
||||
use Icinga\Data\ConnectionInterface;
|
||||
use Icinga\Data\Filterable;
|
||||
use Icinga\Exception\QueryException;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
@ -206,13 +208,13 @@ public function dump()
|
||||
if ($sortRules !== null) {
|
||||
if ($column === null) {
|
||||
$sortColumns = reset($sortRules);
|
||||
if (!isset($sortColumns['columns'])) {
|
||||
if (! isset($sortColumns['columns'])) {
|
||||
$sortColumns['columns'] = array(key($sortRules));
|
||||
}
|
||||
} else {
|
||||
if (isset($sortRules[$column])) {
|
||||
$sortColumns = $sortRules[$column];
|
||||
if (!isset($sortColumns['columns'])) {
|
||||
if (! isset($sortColumns['columns'])) {
|
||||
$sortColumns['columns'] = array($column);
|
||||
}
|
||||
} else {
|
||||
@ -227,6 +229,13 @@ public function dump()
|
||||
$order = (strtoupper($order) === self::SORT_ASC) ? 'ASC' : 'DESC';
|
||||
|
||||
foreach ($sortColumns['columns'] as $column) {
|
||||
if (! $this->isValidFilterTarget($column)) {
|
||||
throw new QueryException(
|
||||
t('The sort column "%s" is not allowed in "%s".'),
|
||||
$column,
|
||||
get_class($this)
|
||||
);
|
||||
}
|
||||
$this->query->order($column, $order);
|
||||
}
|
||||
$this->isSorted = true;
|
||||
@ -289,15 +298,44 @@ public function dump()
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
if (! $this->isSorted) { $this->sort(); }
|
||||
if (! $this->isSorted) {
|
||||
$this->order();
|
||||
}
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function applyFilter(Filter $filter)
|
||||
{
|
||||
$this->validateFilterColumns($filter);
|
||||
|
||||
return $this->addFilter($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates recursive the Filter columns against the isValidFilterTarget() method
|
||||
*
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @throws \Icinga\Data\Filter\FilterException
|
||||
*/
|
||||
public function validateFilterColumns(Filter $filter)
|
||||
{
|
||||
if ($filter instanceof FilterMatch) {
|
||||
if (! $this->isValidFilterTarget($filter->getColumn())) {
|
||||
throw new QueryException(
|
||||
t('The filter column "%s" is not allowed here.'),
|
||||
$filter->getColumn()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (method_exists($filter, 'filters')) {
|
||||
foreach ($filter->filters() as $filter) {
|
||||
$this->validateFilterColumns($filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function clearFilter()
|
||||
{
|
||||
$this->query->clearFilter();
|
||||
|
@ -64,7 +64,8 @@ class HostStatus extends DataView
|
||||
'host_percent_state_change',
|
||||
'host_modified_host_attributes',
|
||||
'host_severity',
|
||||
'host_problem'
|
||||
'host_problem',
|
||||
'host_ipv4'
|
||||
);
|
||||
}
|
||||
|
||||
@ -105,7 +106,7 @@ class HostStatus extends DataView
|
||||
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('hostgroup', 'service_problems');
|
||||
return array('hostgroup', 'service_problems', 'servicegroup');
|
||||
}
|
||||
|
||||
public function isValidFilterTarget($column)
|
||||
|
@ -101,6 +101,7 @@ class ServiceStatus extends DataView
|
||||
'service_flap_detection_enabled',
|
||||
'service_flap_detection_enabled_changed',
|
||||
'service_modified_service_attributes',
|
||||
'service_host_name'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,8 @@ class Service extends MonitoredObject
|
||||
'service_flap_detection_enabled_changed',
|
||||
'service_modified_service_attributes',
|
||||
'service_process_performance_data',
|
||||
'service_percent_state_change'
|
||||
'service_percent_state_change',
|
||||
'service_host_name'
|
||||
))
|
||||
->where('host_name', $this->host->getName())
|
||||
->where('service_description', $this->service);
|
||||
|
Loading…
x
Reference in New Issue
Block a user