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()); ->setQueryString($this->hostList->getObjectsInDowntime()->filterFromResult());
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments'); $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()); ->setQueryString($this->serviceList->getObjectsInDowntime()->filterFromResult()->toQueryString());
$this->view->commentsLink = Url::fromRequest() $this->view->commentsLink = Url::fromRequest()
->setPath('monitoring/list/comments'); ->setPath('monitoring/list/comments');
$this->view->baseFilter = $this->serviceList->getFilter();
} }
/** /**

View File

@ -1,6 +1,17 @@
<?php <?php
use Icinga\Web\Url; 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'; $selfUrl = 'monitoring/list/hosts';
$currentUrl = Url::fromRequest()->getRelativeUrl(); $currentUrl = Url::fromRequest()->getRelativeUrl();
@ -10,17 +21,22 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
<?php if ($this->stats->hosts_up): ?> <?php if ($this->stats->hosts_up): ?>
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>"> <span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_up, $this->stats->hosts_up,
$selfUrl, urlAddFilterOptional(
array('host_state' => 0), $selfUrl,
array('title' => sprintf( Filter::where('host_state', 0),
$this->translatePlural( $this->baseFilter
'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 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> </span>
<?php endif; ?> <?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' : ''; ?>"> <span class="state critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_down_unhandled, $this->stats->hosts_down_unhandled,
$selfUrl, urlAddFilterOptional(
array( $selfUrl,
'host_state' => 1, Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)),
'host_unhandled' => 1 $this->baseFilter
), ),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural( $this->translatePlural(
'List %u host that is currently in state DOWN', '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' : ''; ?>"> <span class="state handled critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' =>0))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_down_handled, $this->stats->hosts_down_handled,
$selfUrl, urlAddFilterOptional(
array( $selfUrl,
'host_state' => 1, Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)),
'host_unhandled' => 0 $this->baseFilter
), ),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural( $this->translatePlural(
'List %u host that is currently in state DOWN (Acknowledged)', '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' : ''; ?>"> <span class="state unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_unreachable_unhandled, $this->stats->hosts_unreachable_unhandled,
$selfUrl, urlAddFilterOptional(
array( $selfUrl,
'host_state' => 2, Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 1)),
'host_unhandled' => 1 $this->baseFilter
), ),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural( $this->translatePlural(
'List %u host that is currently in state UNREACHABLE', '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' : '' ?>"> <span class="state handled unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 0))->getRelativeUrl() ? ' active' : '' ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_unreachable_handled, $this->stats->hosts_unreachable_handled,
$selfUrl, urlAddFilterOptional(
array( $selfUrl,
'host_state' => 2, Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 0)),
'host_unhandled' => 0 $this->baseFilter
), ),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural( $this->translatePlural(
'List %u host that is currently in state UNREACHABLE (Acknowledged)', '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' : ''; ?>"> <span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink( <?= $this->qlink(
$this->stats->hosts_pending, $this->stats->hosts_pending,
$selfUrl, urlAddFilterOptional(
array('host_state' => 99), $selfUrl,
Filter::where('host_state', 99),
$this->baseFilter
),
null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural( $this->translatePlural(
'List %u host that is currently in state PENDING', 'List %u host that is currently in state PENDING',

View File

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

View File

@ -3,6 +3,15 @@
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Module\Monitoring\Object\Service; 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)); $selfUrl = Url::fromPath('monitoring/show/services', array('host' => $object->host_name));
$currentUrl = Url::fromRequest()->without('limit')->getRelativeUrl(); $currentUrl = Url::fromRequest()->without('limit')->getRelativeUrl();
?><div class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>> ?><div class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>

View File

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