From 29cc92a3f3417f639deab9eb7c78df3cec24632b Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 1 Jun 2015 12:22:53 +0200 Subject: [PATCH] Display acknowledgement action for all unacknowledged objects Instead of displaying the ack for all unhandled problem host, make acknowledgement possible for all monitored objects in multi views. fixes #7931 --- .../controllers/HostsController.php | 5 +-- .../controllers/ServicesController.php | 5 +-- .../views/scripts/hosts/show.phtml | 36 ++++++++++--------- .../views/scripts/services/show.phtml | 36 +++++++++++-------- .../library/Monitoring/Object/HostList.php | 15 ++++++++ .../library/Monitoring/Object/ObjectList.php | 5 +++ .../library/Monitoring/Object/ServiceList.php | 15 ++++++++ 7 files changed, 82 insertions(+), 35 deletions(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 2a40efc5b..487955da4 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -133,13 +133,14 @@ class Monitoring_HostsController extends Controller $this->view->objects = $this->hostList; $this->view->unhandledObjects = $this->hostList->getUnhandledObjects(); $this->view->problemObjects = $this->hostList->getProblemObjects(); - $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem') - ->setQueryString($this->hostList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime') ->setQueryString($this->hostList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeLink = Url::fromPath('monitoring/hosts/schedule-downtime') ->setQueryString($this->hostList->getProblemObjects()->objectsFilter()->toQueryString()); $this->view->acknowledgedObjects = $this->hostList->getAcknowledgedObjects(); + $this->view->acknowledgeLink = Url::fromPath('monitoring/hosts/acknowledge-problem') + ->setQueryString($this->hostList->getUnacknowledgedObjects()->objectsFilter()->toQueryString()); + $this->view->unacknowledgedObjects = $this->hostList->getUnacknowledgedObjects(); $this->view->objectsInDowntime = $this->hostList->getObjectsInDowntime(); $this->view->inDowntimeLink = Url::fromPath('monitoring/list/hosts') ->setQueryString( diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 097ee607b..a05a10e4d 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -149,13 +149,14 @@ class Monitoring_ServicesController extends Controller $this->view->objects = $this->serviceList; $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects(); $this->view->problemObjects = $this->serviceList->getProblemObjects(); - $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem') - ->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime') ->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString()); $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime') ->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString()); $this->view->acknowledgedObjects = $acknowledgedObjects; + $this->view->acknowledgeLink = Url::fromPath('monitoring/services/acknowledge-problem') + ->setQueryString($this->serviceList->getUnacknowledgedObjects()->objectsFilter()->toQueryString()); + $this->view->unacknowledgedObjects = $this->serviceList->getUnacknowledgedObjects(); $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime(); $this->view->inDowntimeLink = Url::fromPath('monitoring/list/services') ->setQueryString($this->serviceList->getObjectsInDowntime() diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index 6bbb3c80d..1abc2d21d 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -72,9 +72,10 @@ - +

icon('attention-alt') ?> translatePlural( @@ -110,6 +111,24 @@ ); ?> + 0): ?> +
+ qlink( + sprintf( + $this->translatePlural( + 'Acknowledge %u unacknowledged problem hosts', + 'Acknowledge %u unacknowledged problem hosts', + $unackCount + ), + $unackCount + ), + $acknowledgeLink, + null, + array('icon' => 'ok') + ); ?> + +

'plug') ); ?> -
- qlink( - sprintf( - $this->translatePlural( - 'Acknowledge %u unhandled problem host', - 'Acknowledge %u unhandled problem hosts', - $unhandledCount - ), - $unhandledCount - ), - $acknowledgeUnhandledLink, - null, - array('icon' => 'ok') - ); ?> - diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 746e24871..f4469fe2d 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -70,9 +70,10 @@ - +

icon('attention-alt') ?> @@ -105,6 +106,25 @@ ); ?> + + 0): ?> +
+ qlink( + sprintf( + $this->translatePlural( + 'Acknowledge %u unacknowledged problem service', + 'Acknowledge %u unacknowledged problem services', + $unackCount + ), + $unackCount + ), + $acknowledgeLink, + null, + array('icon' => 'ok') + ); ?> + +

translate('There are %s unhandled problem services. ' . @@ -126,20 +146,6 @@ array('icon' => 'plug') ); ?> -
- qlink( - sprintf( - $this->translatePlural( - 'Acknowledge %u unhandled problem service', - 'Acknowledge %u unhandled problem services', - $unhandledCount - ), - $unhandledCount - ), - $acknowledgeUnhandledLink, - null, - array('icon' => 'ok') - ); ?>

diff --git a/modules/monitoring/library/Monitoring/Object/HostList.php b/modules/monitoring/library/Monitoring/Object/HostList.php index 2aa5bb04f..51b58776b 100644 --- a/modules/monitoring/library/Monitoring/Object/HostList.php +++ b/modules/monitoring/library/Monitoring/Object/HostList.php @@ -99,4 +99,19 @@ class HostList extends ObjectList ->applyFilter(clone $this->filter) ->where('downtime_objecttype', 'host'); } + + /** + * @return ObjectList + */ + public function getUnacknowledgedObjects() + { + $unhandledObjects = array(); + foreach ($this as $object) { + if (! in_array((int) $object->state, array(0, 99)) && + (bool) $object->host_acknowledged === false) { + $unhandledObjects[] = $object; + } + } + return $this->newFromArray($unhandledObjects); + } } diff --git a/modules/monitoring/library/Monitoring/Object/ObjectList.php b/modules/monitoring/library/Monitoring/Object/ObjectList.php index 75fe1ba76..c4ecdddb2 100644 --- a/modules/monitoring/library/Monitoring/Object/ObjectList.php +++ b/modules/monitoring/library/Monitoring/Object/ObjectList.php @@ -193,6 +193,11 @@ abstract class ObjectList implements Countable, IteratorAggregate return $this->newFromArray($handledObjects); } + /** + * @return ObjectList + */ + public abstract function getUnacknowledgedObjects(); + /** * Create a ObjectList from an array of hosts without querying a backend * diff --git a/modules/monitoring/library/Monitoring/Object/ServiceList.php b/modules/monitoring/library/Monitoring/Object/ServiceList.php index 5ae9b8193..01ecf4da9 100644 --- a/modules/monitoring/library/Monitoring/Object/ServiceList.php +++ b/modules/monitoring/library/Monitoring/Object/ServiceList.php @@ -147,4 +147,19 @@ class ServiceList extends ObjectList ->applyFilter(clone $this->filter) ->where('downtime_objecttype', 'service'); } + + /** + * @return ObjectList + */ + public function getUnacknowledgedObjects() + { + $unhandledObjects = array(); + foreach ($this as $object) { + if (! in_array((int) $object->state, array(0, 99)) && + (bool) $object->service_acknowledged === false) { + $unhandledObjects[] = $object; + } + } + return $this->newFromArray($unhandledObjects); + } }