Add filter to summary links

Add the multiselection filter as a base filter to the state summary, to ensure that the summary links only selected services.

refs #8565
This commit is contained in:
Matthias Jentsch 2015-04-07 18:00:36 +02:00
parent 028c3ba08c
commit 9ac89edb86
6 changed files with 107 additions and 51 deletions

View File

@ -165,6 +165,7 @@ class Monitoring_HostsController extends Controller
->setQueryString($this->hostList->getObjectsInDowntime()->filterFromResult());
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
$this->view->baseFilter = $this->hostList->getFilter();
}
/**

View File

@ -202,6 +202,7 @@ class Monitoring_ServicesController extends Controller
->setQueryString($this->serviceList->getObjectsInDowntime()->filterFromResult()->toQueryString());
$this->view->commentsLink = Url::fromRequest()
->setPath('monitoring/list/comments');
$this->view->baseFilter = $this->serviceList->getFilter();
}
/**

View File

@ -1,6 +1,17 @@
<?php
use Icinga\Web\Url;
use Icinga\Data\Filter\Filter;
function urlAddFilterOptional($url, $filter, $optional) {
$url = Url::fromPath($url);
$f = $filter;
if (isset($optional)) {
$f = Filter::matchAll($filter, $optional);
}
return $url->setQueryString($f->toQueryString());
}
$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null;
$selfUrl = 'monitoring/list/hosts';
$currentUrl = Url::fromRequest()->getRelativeUrl();
@ -10,17 +21,22 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<?php if ($this->stats->hosts_up): ?>
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->hosts_up,
$selfUrl,
array('host_state' => 0),
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state UP',
'List %u hosts which are currently in state UP',
$this->stats->hosts_up
$this->stats->hosts_up,
urlAddFilterOptional(
$selfUrl,
Filter::where('host_state', 0),
$this->baseFilter
),
$this->stats->hosts_up
))
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state UP',
'List %u hosts which are currently in state UP',
$this->stats->hosts_up
),
$this->stats->hosts_up
)
)
); ?>
</span>
<?php endif; ?>
@ -29,11 +45,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="state critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->hosts_down_unhandled,
$selfUrl,
array(
'host_state' => 1,
'host_unhandled' => 1
urlAddFilterOptional(
$selfUrl,
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)),
$this->baseFilter
),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state DOWN',
@ -49,11 +66,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="state handled critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' =>0))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->hosts_down_handled,
$selfUrl,
array(
'host_state' => 1,
'host_unhandled' => 0
urlAddFilterOptional(
$selfUrl,
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)),
$this->baseFilter
),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state DOWN (Acknowledged)',
@ -74,11 +92,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="state unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->hosts_unreachable_unhandled,
$selfUrl,
array(
'host_state' => 2,
'host_unhandled' => 1
urlAddFilterOptional(
$selfUrl,
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 1)),
$this->baseFilter
),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state UNREACHABLE',
@ -94,11 +113,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="state handled unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 0))->getRelativeUrl() ? ' active' : '' ?>">
<?= $this->qlink(
$this->stats->hosts_unreachable_handled,
$selfUrl,
array(
'host_state' => 2,
'host_unhandled' => 0
urlAddFilterOptional(
$selfUrl,
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 0)),
$this->baseFilter
),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state UNREACHABLE (Acknowledged)',
@ -119,8 +139,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->hosts_pending,
$selfUrl,
array('host_state' => 99),
urlAddFilterOptional(
$selfUrl,
Filter::where('host_state', 99),
$this->baseFilter
),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u host that is currently in state PENDING',

View File

@ -1,8 +1,19 @@
<?php
use Icinga\Data\Filter\Filter;
use Icinga\Web\Url;
use Icinga\Module\Monitoring\Object\Service;
function urlAddFilterOptional($url, $filter, $optional) {
$url = Url::fromPath($url);
$f = $filter;
if (isset($optional)) {
$f = Filter::matchAll($filter, $optional);
}
return $url->setQueryString($f->toQueryString());
}
$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null;
$selfUrl = 'monitoring/list/services';
$currentUrl = Url::fromRequest()->getRelativeUrl();
?><div class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
@ -10,19 +21,21 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<span class="badges">
<?php if ($this->stats->services_ok): ?>
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->services_ok,
$selfUrl,
array('service_state' => 0),
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state OK',
'List %u services which are currently in state OK',
<?=
$this->qlink(
$this->stats->services_ok,
urlAddFilterOptional($selfUrl, Filter::where('service_state', 0), $this->baseFilter),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state OK',
'List %u services which are currently in state OK',
$this->stats->services_ok
),
$this->stats->services_ok
),
$this->stats->services_ok
))
); ?>
))
);
?>
</span>
<?php endif ?>
<?php
@ -31,12 +44,18 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
if ($this->stats->$pre) {
$handled = $pre . '_handled';
$unhandled = $pre . '_unhandled';
$paramsHandled = array('service_state' => $stateId, 'service_handled' => 1);
$paramsUnhandled = array('service_state' => $stateId, 'service_handled' => 0);
$paramsHandled = Filter::matchAll(
Filter::where('service_state', $stateId),
Filter::where('service_handled', 1)
);
$paramsUnhandled = Filter::matchAll(
Filter::where('service_state', $stateId),
Filter::where('service_handled', 0)
);
if ($this->stats->$unhandled) {
$compareUrl = Url::fromPath($selfUrl, $paramsUnhandled)->getRelativeUrl();
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl();
} else {
$compareUrl = Url::fromPath($selfUrl, $paramsHandled)->getRelativeUrl();
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl();
}
if ($compareUrl === $currentUrl) {
@ -50,8 +69,8 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
echo $this->qlink(
$this->stats->$unhandled,
$selfUrl,
$paramsUnhandled,
urlAddFilterOptional($selfUrl, $paramsUnhandled, $this->baseFilter),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state %s',
@ -65,7 +84,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
}
if ($this->stats->$handled) {
if (Url::fromPath($selfUrl, $paramsHandled)->getRelativeUrl() === $currentUrl) {
if (Url::fromPath($selfUrl)->setQueryString($paramsHandled->toQueryString())->getRelativeUrl() === $currentUrl) {
$active = ' active';
} else {
$active = '';
@ -75,8 +94,8 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
}
echo $this->qlink(
$this->stats->$handled,
$selfUrl,
$paramsHandled,
urlAddFilterOptional($selfUrl, $paramsHandled, $this->baseFilter),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state %s (Acknowledged)',
@ -99,8 +118,8 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$this->stats->services_pending,
$selfUrl,
array('service_state' => 99),
urlAddFilterOptional($selfUrl, Filter::where('service_state', 99), $this->baseFilter),
null,
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state PENDING',

View File

@ -3,6 +3,15 @@
use Icinga\Web\Url;
use Icinga\Module\Monitoring\Object\Service;
function urlAddFilterOptional($url, $filter, $optional) {
$url = Url::fromPath($url);
$f = $filter;
if (isset($optional)) {
$f = Filter::matchAll($filter, $optional);
}
return $url->setQueryString($f->toQueryString());
}
$selfUrl = Url::fromPath('monitoring/show/services', array('host' => $object->host_name));
$currentUrl = Url::fromRequest()->without('limit')->getRelativeUrl();
?><div class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>

View File

@ -3,6 +3,8 @@
namespace Icinga\Module\Monitoring\Object;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterOr;
use Icinga\Util\String;
/**