From 9ac89edb86b15c3f6db61f3a0c65d0332a9f8b6d Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 7 Apr 2015 18:00:36 +0200 Subject: [PATCH] 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 --- .../controllers/HostsController.php | 1 + .../controllers/ServicesController.php | 1 + .../list/components/hostssummary.phtml | 80 ++++++++++++------- .../list/components/servicesummary.phtml | 65 +++++++++------ .../partials/host/servicesummary.phtml | 9 +++ .../library/Monitoring/Object/HostList.php | 2 + 6 files changed, 107 insertions(+), 51 deletions(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 070f4f75c..1da2a95e6 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -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(); } /** diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 9ea1ffcb3..789a5fda5 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -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(); } /** diff --git a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml index fc7d30867..418a64906 100644 --- a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml @@ -1,6 +1,17 @@ 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(); stats->hosts_up): ?> 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 + ) + ) ); ?> @@ -29,11 +45,12 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); 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(); 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(); 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(); 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(); 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', diff --git a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml index 0554fcfd4..76a51de92 100644 --- a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml @@ -1,8 +1,19 @@ setQueryString($f->toQueryString()); +} +$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null; + $selfUrl = 'monitoring/list/services'; $currentUrl = Url::fromRequest()->getRelativeUrl(); ?>
compact ? ' data-base-target="col1"' : ''; ?>> @@ -10,19 +21,21 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); stats->services_ok): ?> - 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', + 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 - )) - ); ?> + )) + ); + ?> '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 => $ 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', diff --git a/modules/monitoring/application/views/scripts/partials/host/servicesummary.phtml b/modules/monitoring/application/views/scripts/partials/host/servicesummary.phtml index bdd4d9af7..04408808f 100644 --- a/modules/monitoring/application/views/scripts/partials/host/servicesummary.phtml +++ b/modules/monitoring/application/views/scripts/partials/host/servicesummary.phtml @@ -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(); ?>
compact ? ' data-base-target="col1"' : ''; ?>> diff --git a/modules/monitoring/library/Monitoring/Object/HostList.php b/modules/monitoring/library/Monitoring/Object/HostList.php index 3f3dcee47..40dc002df 100644 --- a/modules/monitoring/library/Monitoring/Object/HostList.php +++ b/modules/monitoring/library/Monitoring/Object/HostList.php @@ -3,6 +3,8 @@ namespace Icinga\Module\Monitoring\Object; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterOr; use Icinga\Util\String; /**