Show intersecting ok-states as well in the default servicegrid view
fixes #9360
This commit is contained in:
parent
9595809dfa
commit
98b01207cf
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace Icinga\Data;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
|
@ -45,6 +46,20 @@ class PivotTable
|
|||
*/
|
||||
protected $yAxisColumn;
|
||||
|
||||
/**
|
||||
* The filter being applied on the query for the x axis
|
||||
*
|
||||
* @var Filter
|
||||
*/
|
||||
protected $xAxisFilter;
|
||||
|
||||
/**
|
||||
* The filter being applied on the query for the y axis
|
||||
*
|
||||
* @var Filter
|
||||
*/
|
||||
protected $yAxisFilter;
|
||||
|
||||
/**
|
||||
* Create a new pivot table
|
||||
*
|
||||
|
@ -57,43 +72,31 @@ class PivotTable
|
|||
$this->baseQuery = $query;
|
||||
$this->xAxisColumn = $xAxisColumn;
|
||||
$this->yAxisColumn = $yAxisColumn;
|
||||
$this->prepareQueries()->adjustSorting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the queries used for the pre processing
|
||||
* Set the filter to apply on the query for the x axis
|
||||
*
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function prepareQueries()
|
||||
public function setXAxisFilter(Filter $filter = null)
|
||||
{
|
||||
$this->xAxisQuery = clone $this->baseQuery;
|
||||
$this->xAxisQuery->group($this->xAxisColumn);
|
||||
$this->xAxisQuery->columns(array($this->xAxisColumn));
|
||||
$this->xAxisQuery->setUseSubqueryCount();
|
||||
$this->yAxisQuery = clone $this->baseQuery;
|
||||
$this->yAxisQuery->group($this->yAxisColumn);
|
||||
$this->yAxisQuery->columns(array($this->yAxisColumn));
|
||||
$this->yAxisQuery->setUseSubqueryCount();
|
||||
|
||||
$this->xAxisFilter = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a default sorting for the x- and y-axis without losing any existing rules
|
||||
* Set the filter to apply on the query for the y axis
|
||||
*
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function adjustSorting()
|
||||
public function setYAxisFilter(Filter $filter = null)
|
||||
{
|
||||
if (false === $this->xAxisQuery->hasOrder($this->xAxisColumn)) {
|
||||
$this->xAxisQuery->order($this->xAxisColumn, 'ASC');
|
||||
}
|
||||
|
||||
if (false === $this->yAxisQuery->hasOrder($this->yAxisColumn)) {
|
||||
$this->yAxisQuery->order($this->yAxisColumn, 'ASC');
|
||||
}
|
||||
|
||||
$this->yAxisFilter = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -119,6 +122,56 @@ class PivotTable
|
|||
return $default !== null ? $default : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query horizontal (x) axis
|
||||
*
|
||||
* @return SimpleQuery
|
||||
*/
|
||||
protected function queryXAxis()
|
||||
{
|
||||
if ($this->xAxisQuery === null) {
|
||||
$this->xAxisQuery = clone $this->baseQuery;
|
||||
$this->xAxisQuery->group($this->xAxisColumn);
|
||||
$this->xAxisQuery->columns(array($this->xAxisColumn));
|
||||
$this->xAxisQuery->setUseSubqueryCount();
|
||||
|
||||
if ($this->xAxisFilter !== null) {
|
||||
$this->xAxisQuery->addFilter($this->xAxisFilter);
|
||||
}
|
||||
|
||||
if (! $this->xAxisQuery->hasOrder($this->xAxisColumn)) {
|
||||
$this->xAxisQuery->order($this->xAxisColumn, 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->xAxisQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query vertical (y) axis
|
||||
*
|
||||
* @return SimpleQuery
|
||||
*/
|
||||
protected function queryYAxis()
|
||||
{
|
||||
if ($this->yAxisQuery === null) {
|
||||
$this->yAxisQuery = clone $this->baseQuery;
|
||||
$this->yAxisQuery->group($this->yAxisColumn);
|
||||
$this->yAxisQuery->columns(array($this->yAxisColumn));
|
||||
$this->yAxisQuery->setUseSubqueryCount();
|
||||
|
||||
if ($this->yAxisFilter !== null) {
|
||||
$this->yAxisQuery->addFilter($this->yAxisFilter);
|
||||
}
|
||||
|
||||
if (! $this->yAxisQuery->hasOrder($this->yAxisColumn)) {
|
||||
$this->yAxisQuery->order($this->yAxisColumn, 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->yAxisQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a pagination adapter for the x axis query
|
||||
*
|
||||
|
@ -141,9 +194,10 @@ class PivotTable
|
|||
}
|
||||
}
|
||||
|
||||
$this->xAxisQuery->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
|
||||
$query = $this->queryXAxis();
|
||||
$query->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
|
||||
|
||||
$paginator = new Zend_Paginator(new QueryAdapter($this->xAxisQuery));
|
||||
$paginator = new Zend_Paginator(new QueryAdapter($query));
|
||||
$paginator->setItemCountPerPage($limit);
|
||||
$paginator->setCurrentPageNumber($page);
|
||||
return $paginator;
|
||||
|
@ -171,9 +225,10 @@ class PivotTable
|
|||
}
|
||||
}
|
||||
|
||||
$this->yAxisQuery->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
|
||||
$query = $this->queryYAxis();
|
||||
$query->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
|
||||
|
||||
$paginator = new Zend_Paginator(new QueryAdapter($this->yAxisQuery));
|
||||
$paginator = new Zend_Paginator(new QueryAdapter($query));
|
||||
$paginator->setItemCountPerPage($limit);
|
||||
$paginator->setCurrentPageNumber($page);
|
||||
return $paginator;
|
||||
|
@ -186,10 +241,23 @@ class PivotTable
|
|||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$pivot = array();
|
||||
$xAxis = $this->xAxisQuery->fetchColumn();
|
||||
$yAxis = $this->yAxisQuery->fetchColumn();
|
||||
if (
|
||||
($this->xAxisFilter === null && $this->yAxisFilter === null)
|
||||
|| ($this->xAxisFilter !== null && $this->yAxisFilter !== null)
|
||||
) {
|
||||
$xAxis = $this->queryXAxis()->fetchColumn();
|
||||
$yAxis = $this->queryYAxis()->fetchColumn();
|
||||
} else {
|
||||
if ($this->xAxisFilter !== null) {
|
||||
$xAxis = $this->queryXAxis()->fetchColumn();
|
||||
$yAxis = $this->queryYAxis()->where($this->xAxisColumn, $xAxis)->fetchColumn();
|
||||
} else { // $this->yAxisFilter !== null
|
||||
$yAxis = $this->queryYAxis()->fetchColumn();
|
||||
$xAxis = $this->queryXAxis()->where($this->yAxisColumn, $yAxis)->fetchColumn();
|
||||
}
|
||||
}
|
||||
|
||||
$pivot = array();
|
||||
if (!empty($xAxis) && !empty($yAxis)) {
|
||||
$this->baseQuery->where($this->xAxisColumn, $xAxis)->where($this->yAxisColumn, $yAxis);
|
||||
|
||||
|
@ -199,7 +267,7 @@ class PivotTable
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($this->baseQuery->fetchAll() as $row) {
|
||||
foreach ($this->baseQuery as $row) {
|
||||
$pivot[$row->{$this->yAxisColumn}][$row->{$this->xAxisColumn}] = $row;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -586,6 +586,7 @@ class Monitoring_ListController extends Controller
|
|||
{
|
||||
$this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid'));
|
||||
$this->setAutorefreshInterval(15);
|
||||
$problems = (bool) $this->params->shift('problems', 0);
|
||||
$query = $this->backend->select()->from('servicestatus', array(
|
||||
'host_name',
|
||||
'service_description',
|
||||
|
@ -599,7 +600,12 @@ class Monitoring_ListController extends Controller
|
|||
'host_name' => $this->translate('Hostname'),
|
||||
'service_description' => $this->translate('Service description')
|
||||
), $query);
|
||||
$pivot = $query->pivot('service_description', 'host_name');
|
||||
$pivot = $query->pivot(
|
||||
'service_description',
|
||||
'host_name',
|
||||
$problems ? Filter::where('service_problem', 1) : null,
|
||||
$problems ? Filter::where('service_problem', 1) : null
|
||||
);
|
||||
$this->view->pivot = $pivot;
|
||||
$this->view->horizontalPaginator = $pivot->paginateXAxis();
|
||||
$this->view->verticalPaginator = $pivot->paginateYAxis();
|
||||
|
@ -618,7 +624,7 @@ class Monitoring_ListController extends Controller
|
|||
->setQuery($dataView)
|
||||
->preserveParams(
|
||||
'limit', 'sort', 'dir', 'format', 'view', 'backend',
|
||||
'stateType', 'addColumns', '_dev'
|
||||
'stateType', 'addColumns', '_dev', 'problems'
|
||||
)
|
||||
->ignoreParams('page')
|
||||
->setSearchColumns($dataView->getSearchColumns())
|
||||
|
|
|
@ -112,7 +112,7 @@ $section->add($this->translate('Service Problems'), array(
|
|||
'priority' => 60
|
||||
));
|
||||
$section->add($this->translate('Service Grid'), array(
|
||||
'url' => 'monitoring/list/servicegrid?service_problem=1',
|
||||
'url' => 'monitoring/list/servicegrid?problems',
|
||||
'priority' => 70
|
||||
));
|
||||
$section->add($this->translate('Current Downtimes'), array(
|
||||
|
|
|
@ -201,12 +201,15 @@ abstract class DataView implements QueryInterface, IteratorAggregate
|
|||
*
|
||||
* @param string $xAxisColumn The column to use for the x axis
|
||||
* @param string $yAxisColumn The column to use for the y axis
|
||||
* @param Filter $xAxisFilter The filter to apply on a query for the x axis
|
||||
* @param Filter $yAxisFilter The filter to apply on a query for the y axis
|
||||
*
|
||||
* @return PivotTable
|
||||
*/
|
||||
public function pivot($xAxisColumn, $yAxisColumn)
|
||||
public function pivot($xAxisColumn, $yAxisColumn, Filter $xAxisFilter = null, Filter $yAxisFilter = null)
|
||||
{
|
||||
return new PivotTable($this->query, $xAxisColumn, $yAxisColumn);
|
||||
$pivot = new PivotTable($this->query, $xAxisColumn, $yAxisColumn);
|
||||
return $pivot->setXAxisFilter($xAxisFilter)->setYAxisFilter($yAxisFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue