From d4bbd3a323f8db52009a1405c9a416979aa3f010 Mon Sep 17 00:00:00 2001 From: Carlos Cesario Date: Tue, 16 Dec 2014 09:31:20 -0200 Subject: [PATCH 01/16] Add more support to plural strings translation Add more support to plural strings translation refs #8092 --- .../application/views/scripts/hosts/show.phtml | 17 +++++++++++------ .../scripts/multi/components/comments.phtml | 4 ++-- .../views/scripts/services/show.phtml | 8 ++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index 6ab717635..8ae19aa0b 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -6,7 +6,7 @@ translate('No hosts matching the filter') ?>
- translate('Hosts (%u)'), array_sum(array_values($hostStates))) ?> + translatePlural('Host (%u)', 'Hosts (%u)', array_sum(array_values($hostStates))), array_sum(array_values($hostStates))) ?>
hostStatesPieChart ?> @@ -18,9 +18,14 @@

- translate('%u Hosts'), - count($objects)) - ?> + translatePlural( + '%u Host', + '%u Hosts', + count($objects) + ), + count($objects) + ) ?>

@@ -102,7 +107,7 @@ icon('plug') ?> - translate(sprintf('%u hosts are in downtime', count($objectsInDowntime))) ?> + translatePlural('%u host is in downtime', '%u hosts are in downtime', count($objectsInDowntime)),count($objectsInDowntime)) ?> @@ -112,7 +117,7 @@ icon('comment') ?> - translate(sprintf('%u comments', count($objects->getComments()))) ?> + translatePlural('%u comment', '%u comments', count($objects->getComments())), count($objects->getComments())) ?> diff --git a/modules/monitoring/application/views/scripts/multi/components/comments.phtml b/modules/monitoring/application/views/scripts/multi/components/comments.phtml index f0b262c9d..f477cd953 100644 --- a/modules/monitoring/application/views/scripts/multi/components/comments.phtml +++ b/modules/monitoring/application/views/scripts/multi/components/comments.phtml @@ -3,7 +3,7 @@ $objectName = $this->is_service ? 'Services' : 'Hosts'; ?> - translate('Comments') ?> + translatePlural('%u Comment', '%u Comments', count($comments)), count($comments)) ?> icon('cancel') @@ -20,6 +20,6 @@ $objectName = $this->is_service ? 'Services' : 'Hosts'; 'monitoring/list/comments', array('comment_internal_id' => '(' . implode('|', $this->comments) . ')') ); - ?>"> comments . + ?>"> translatePlural('%u comment', '%u comments', count($comments)), count($comments)) ?>. diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 18071c152..e8a4c70a1 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -8,7 +8,7 @@
- translate('Services (%u)'), array_sum(array_values($serviceStates))) ?> + translatePlural('Service (%u)', 'Services (%u)', array_sum(array_values($serviceStates))), array_sum(array_values($serviceStates))) ?>
serviceStatesPieChart ?> @@ -22,7 +22,7 @@
- translate('Hosts (%u)'), array_sum(array_values($hostStates))) ?> + translatePlural('Host (%u)', 'Hosts (%u)', array_sum(array_values($hostStates))), array_sum(array_values($hostStates))) ?>
hostStatesPieChart ?> @@ -114,7 +114,7 @@ icon('plug') ?> - translate(sprintf('%u services are in downtime', count($objectsInDowntime))) ?> + translatePlural('%u service is in downtime', '%u services are in downtime', count($objectsInDowntime)), count($objectsInDowntime)) ?> @@ -124,7 +124,7 @@ icon('comment') ?> - translate(sprintf('%u comments', count($objects->getComments()))) ?> + translatePlural('%u comment', '%u comments', count($objects->getComments())), count($objects->getComments())) ?> From c87733debc65ceba04c499cc31ad5fbd680a6091 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:26:19 +0100 Subject: [PATCH 02/16] monitoring: Count hosts once in hosts/show.phtml --- .../application/views/scripts/hosts/show.phtml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index 8ae19aa0b..a4629e652 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -2,11 +2,12 @@ tabs ?>
- + + translate('No hosts matching the filter') ?>
- translatePlural('Host (%u)', 'Hosts (%u)', array_sum(array_values($hostStates))), array_sum(array_values($hostStates))) ?> + translatePlural('Host (%u)', 'Hosts (%u)', $hostCount), $hostCount) ?>
hostStatesPieChart ?> @@ -22,9 +23,9 @@ $this->translatePlural( '%u Host', '%u Hosts', - count($objects) - ), - count($objects) + $hostCount + ), + $hostCount ) ?> From 507aefa9dd64cf3e934f4ebd1b9cea74a238e68d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:30:31 +0100 Subject: [PATCH 03/16] monitoring: Count unhandled hosts once in hosts/show.phtml --- .../monitoring/application/views/scripts/hosts/show.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index a4629e652..f1db2d9b0 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -62,13 +62,14 @@

+ translatePlural( '%u Unhandled Host Problem', '%u Unhandled Host Problems', - count($unhandledObjects) + $unhandledCount ), - count($unhandledObjects) + $unhandledCount ) ?>

From 3745d3ebefce5b370d98c896d02521c8a22b0098 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:31:23 +0100 Subject: [PATCH 04/16] monitoring: Count acknowledged hosts once in hosts/show.phtml --- .../monitoring/application/views/scripts/hosts/show.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index f1db2d9b0..e6fc7f8be 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -90,13 +90,14 @@

+ translatePlural( '%u Acknowledged Host Problem', '%u Acknowledged Host Problems', - count($acknowledgedObjects) + $acknowledgedCount ), - count($acknowledgedObjects) + $acknowledgedCount ) ?>

From b82f4e53565b0ceb0ba8930cbbc1555f1093f4d5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:33:32 +0100 Subject: [PATCH 05/16] monitoring: Count hosts in downtime once in hosts/show.phtml --- .../application/views/scripts/hosts/show.phtml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index e6fc7f8be..dc0165497 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -107,10 +107,18 @@

+ icon('plug') ?> - translatePlural('%u host is in downtime', '%u hosts are in downtime', count($objectsInDowntime)),count($objectsInDowntime)) ?> + translatePlural( + '%u host is in downtime', + '%u hosts are in downtime', + $inDowntimeCount + ), + $inDowntimeCount + ) ?>

From 56102a1e39092c9229f9730a48974ddce740a14e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:35:18 +0100 Subject: [PATCH 06/16] monitoring: Count hosts having comments once in hosts/show.phtml --- .../application/views/scripts/hosts/show.phtml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/hosts/show.phtml b/modules/monitoring/application/views/scripts/hosts/show.phtml index dc0165497..739069416 100644 --- a/modules/monitoring/application/views/scripts/hosts/show.phtml +++ b/modules/monitoring/application/views/scripts/hosts/show.phtml @@ -123,12 +123,20 @@ - getComments())): ?> + getComments()) ?> +

icon('comment') ?> - translatePlural('%u comment', '%u comments', count($objects->getComments())), count($objects->getComments())) ?> + translatePlural( + '%u comment', + '%u comments', + $havingCommentsCount + ), + $havingCommentsCount + ) ?>

From 8594ff6843b4767609cb5f48ca2ee370597ee227 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:38:02 +0100 Subject: [PATCH 07/16] monitoring: Remove multi/* view scripts They are no longer used. --- .../scripts/multi/components/comments.phtml | 25 ------- .../scripts/multi/components/downtimes.phtml | 19 ------ .../scripts/multi/components/flags.phtml | 25 ------- .../scripts/multi/components/objectlist.phtml | 65 ------------------- .../scripts/multi/components/summary.phtml | 59 ----------------- .../views/scripts/multi/host.phtml | 62 ------------------ .../views/scripts/multi/service.phtml | 61 ----------------- 7 files changed, 316 deletions(-) delete mode 100644 modules/monitoring/application/views/scripts/multi/components/comments.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/components/downtimes.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/components/flags.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/components/objectlist.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/components/summary.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/host.phtml delete mode 100644 modules/monitoring/application/views/scripts/multi/service.phtml diff --git a/modules/monitoring/application/views/scripts/multi/components/comments.phtml b/modules/monitoring/application/views/scripts/multi/components/comments.phtml deleted file mode 100644 index f477cd953..000000000 --- a/modules/monitoring/application/views/scripts/multi/components/comments.phtml +++ /dev/null @@ -1,25 +0,0 @@ -is_service ? 'Services' : 'Hosts'; - -?> - translatePlural('%u Comment', '%u Comments', count($comments)), count($comments)) ?> - - icon('cancel') - ?> translate('Remove Comments') ?>
- icon('bell-off-empty') - ?> translate('Delay Notifications') ?>
- - icon('ok') ?> Acknowledge - - - translatePlural('%u comment', '%u comments', count($comments)), count($comments)) ?>. - - diff --git a/modules/monitoring/application/views/scripts/multi/components/downtimes.phtml b/modules/monitoring/application/views/scripts/multi/components/downtimes.phtml deleted file mode 100644 index af8d841b4..000000000 --- a/modules/monitoring/application/views/scripts/multi/components/downtimes.phtml +++ /dev/null @@ -1,19 +0,0 @@ -is_service ? 'Services' : 'Hosts'; - -?> - - Downtimes - - icon('cancel') ?>Remove Downtimes
- icon('plug') - ?> Schedule Downtimes - - - Change downtimes. - - diff --git a/modules/monitoring/application/views/scripts/multi/components/flags.phtml b/modules/monitoring/application/views/scripts/multi/components/flags.phtml deleted file mode 100644 index 1269e2f49..000000000 --- a/modules/monitoring/application/views/scripts/multi/components/flags.phtml +++ /dev/null @@ -1,25 +0,0 @@ -
- - form->getElements() as $name => $element): - if ($element instanceof \Icinga\Web\Form\Element\TriStateCheckbox): - $element->setDecorators(array('ViewHelper')); - ?> - - - - - - - - - - - -
render() ?>
render() ?>
-
\ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/multi/components/objectlist.phtml b/modules/monitoring/application/views/scripts/multi/components/objectlist.phtml deleted file mode 100644 index 879a13a1d..000000000 --- a/modules/monitoring/application/views/scripts/multi/components/objectlist.phtml +++ /dev/null @@ -1,65 +0,0 @@ -is_service) { - $links[] = $this->qlink( - $object->host_name . ' ' . $object->service_description, - 'monitoring/show/service', - array( - 'host' => $object->host_name, - 'service' => $object->service_description - ) - ); - } else { - $links[] = $this->qlink( - $object->host_name, - 'monitoring/show/host', - array( - 'host' => $object->host_name - ) - ); - } -} - -if ($this->is_service) { - $objectName = $this->translate('Services'); - $link = 'monitoring/list/services'; - $target = array( - 'host' => $this->hostquery, - 'service' => $this->servicequery - ); -} else { - $objectName = $this->translate('Hosts'); - $link = 'monitoring/list/hosts'; - $target = array( - 'host' => $this->hostquery - ); -} - -$more = clone $this->url; - - -?> -qlink( - $this->translate('List all'), - $more->setPath($link), - null, - array('title' => $this->translate('List all selected objects')) -) ?> - - 5) { - echo ' ' . sprintf($this->translate('and %d more'), count($objects) - 5); -} - -?> - - diff --git a/modules/monitoring/application/views/scripts/multi/components/summary.phtml b/modules/monitoring/application/views/scripts/multi/components/summary.phtml deleted file mode 100644 index d832624c7..000000000 --- a/modules/monitoring/application/views/scripts/multi/components/summary.phtml +++ /dev/null @@ -1,59 +0,0 @@ -getHelper('CommandForm'); -$servicequery = isset($this->servicequery) ? $this->servicequery : ''; -$objectName = $this->is_service ? $this->translate('Services') : $this->translate('Hosts'); - -$params = array( - 'host' => $this->target['host'], - 'service' => null, - 'checktime' => time(), - 'forcecheck' => '1' -); -if (array_key_exists('service', $this->target)) { - $params['service'] = $this->target['service']; -} else { - unset($params['service']); -} -?> - - - - icon('rescheduel') - ?> Recheck
- icon('reschedule') - ?> Reschedule
- - Perform actions on . - - - - problems ?> Problems - - icon('plug') - ?> Schedule Downtimes - - problems, - count($this->objects), - $objectName - ) ?> - - - unhandled) ?> Unhandled - - icon('ok') - ?> Acknowledge
- icon('remove_petrol.png') ?> Remove Acknowledgements - - diff --git a/modules/monitoring/application/views/scripts/multi/host.phtml b/modules/monitoring/application/views/scripts/multi/host.phtml deleted file mode 100644 index 6179f6339..000000000 --- a/modules/monitoring/application/views/scripts/multi/host.phtml +++ /dev/null @@ -1,62 +0,0 @@ -is_service = false; -$this->hostquery = implode($this->hostnames, ','); -$this->target = array('host' => $this->hostquery); -?> - -
- tabs; ?> -
- -
- - - -

Summary for hosts

- render('multi/components/objectlist.phtml'); ?> - - - - - - - - - - -
-

Hosts

-
- pie->render(); ?> - - $count) { - if ($count > 0) { - echo ucfirst($state) . ': ' . $count . '
'; - } - } - ?> -
- -

icon('host')?> Host Actions

- - - - render('multi/components/summary.phtml'); ?> - render('multi/components/comments.phtml'); ?> - render('multi/components/downtimes.phtml'); ?> - -
- - render('multi/components/flags.phtml') ?> - -
- - - - diff --git a/modules/monitoring/application/views/scripts/multi/service.phtml b/modules/monitoring/application/views/scripts/multi/service.phtml deleted file mode 100644 index dc2e9f19e..000000000 --- a/modules/monitoring/application/views/scripts/multi/service.phtml +++ /dev/null @@ -1,61 +0,0 @@ -is_service = true; -$this->hostquery = implode($this->hostnames, ','); -$this->servicequery = implode($this->servicenames, ','); -$this->target = array( - 'host' => $this->hostquery, - 'service' => $this->servicequery -); -?> - -
-tabs ?> -
- -
- - - -

Summary for services

- - - - - - - - - - - - -
Services Hosts
service_pie->render() ?> $count) { - if ($count > 0) { - echo ucfirst($state) . ': ' . $count . '
'; - } - } - - ?>
host_pie->render() ?> $count) { - if ($count > 0) { - echo ucfirst($state) . ': ' . $count . '
'; - } - } - ?>
- -

icon('conf')?> Service Actions

- - - - render('multi/components/objectlist.phtml') ?> - render('multi/components/summary.phtml') ?> - render('multi/components/comments.phtml') ?> - render('multi/components/downtimes.phtml') ?> - -
- - render('multi/components/flags.phtml') ?> - -
From b7d6ee75f245250c9dd971b474e8a944c9c3ee84 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:38:43 +0100 Subject: [PATCH 08/16] monitoring: Remove the MultiController The controller is no longer used. --- .../controllers/MultiController.php | 282 ------------------ 1 file changed, 282 deletions(-) delete mode 100644 modules/monitoring/application/controllers/MultiController.php diff --git a/modules/monitoring/application/controllers/MultiController.php b/modules/monitoring/application/controllers/MultiController.php deleted file mode 100644 index 6deff2fc3..000000000 --- a/modules/monitoring/application/controllers/MultiController.php +++ /dev/null @@ -1,282 +0,0 @@ -backend->select()->from( - 'hostStatus', - array( - 'host_name', - 'host_in_downtime', - 'host_passive_checks_enabled', - 'host_obsessing', - 'host_state', - 'host_notifications_enabled', - 'host_event_handler_enabled', - 'host_flap_detection_enabled', - 'host_active_checks_enabled', - // columns intended for filter-request - 'host_problem', - 'host_handled' - ) - )->getQuery(); - $this->applyQueryFilter($query); - $hosts = $query->fetchAll(); - - $comments = $this->backend->select()->from('comment', array( - 'comment_internal_id', - 'comment_host', - )); - $this->applyQueryFilter($comments); - $uniqueComments = array_keys($this->getUniqueValues($comments->getQuery()->fetchAll(), 'comment_internal_id')); - - // Populate view - $this->view->objects = $this->view->hosts = $hosts; - $this->view->problems = $this->getProblems($hosts); - $this->view->comments = $uniqueComments; - $this->view->hostnames = $this->getProperties($hosts, 'host_name'); - $this->view->downtimes = $this->getDowntimes($hosts); - $this->view->errors = $errors; - $this->view->states = $this->countStates($hosts, 'host', 'host_name'); - $this->view->pie = $this->createPie( - $this->view->states, - $this->view->getHelper('MonitoringState')->getHostStateColors(), - mt('monitoring', 'Host State') - ); - - // Handle configuration changes - $this->handleConfigurationForm(array( - 'host_passive_checks_enabled' => $this->translate('Passive Checks'), - 'host_active_checks_enabled' => $this->translate('Active Checks'), - 'host_notifications_enabled' => $this->translate('Notifications'), - 'host_event_handler_enabled' => $this->translate('Event Handler'), - 'host_flap_detection_enabled' => $this->translate('Flap Detection'), - 'host_obsessing' => $this->translate('Obsessing') - )); - } - - public function serviceAction() - { - $errors = array(); - $query = $this->backend->select()->from('serviceStatus', array( - 'host_name', - 'host_state', - 'service_description', - 'service_handled', - 'service_state', - 'service_in_downtime', - 'service_passive_checks_enabled', - 'service_notifications_enabled', - 'service_event_handler_enabled', - 'service_flap_detection_enabled', - 'service_active_checks_enabled', - 'service_obsessing', - // also accept all filter-requests from ListView - 'service_problem', - 'service_severity', - 'service_last_check', - 'service_state_type', - 'host_severity', - 'host_address', - 'host_last_check' - )); - - $this->applyQueryFilter($query); - $services = $query->getQuery()->fetchAll(); - - $comments = $this->backend->select()->from('comment', array( - 'comment_internal_id', - 'comment_host', - 'comment_service' - )); - $this->applyQueryFilter($comments); - $uniqueComments = array_keys($this->getUniqueValues($comments->getQuery()->fetchAll(), 'comment_internal_id')); - - // populate the view - $this->view->objects = $this->view->services = $services; - $this->view->problems = $this->getProblems($services); - $this->view->comments = $uniqueComments; - $this->view->hostnames = $this->getProperties($services, 'host_name'); - $this->view->servicenames = $this->getProperties($services, 'service_description'); - $this->view->downtimes = $this->getDowntimes($services); - $this->view->service_states = $this->countStates($services, 'service'); - $this->view->host_states = $this->countStates($services, 'host', 'host_name'); - $this->view->service_pie = $this->createPie( - $this->view->service_states, - $this->view->getHelper('MonitoringState')->getServiceStateColors(), - mt('monitoring', 'Service State') - ); - $this->view->host_pie = $this->createPie( - $this->view->host_states, - $this->view->getHelper('MonitoringState')->getHostStateColors(), - mt('monitoring', 'Host State') - ); - $this->view->errors = $errors; - - $this->handleConfigurationForm(array( - 'service_passive_checks_enabled' => $this->translate('Passive Checks'), - 'service_active_checks_enabled' => $this->translate('Active Checks'), - 'service_notifications_enabled' => $this->translate('Notifications'), - 'service_event_handler_enabled' => $this->translate('Event Handler'), - 'service_flap_detection_enabled' => $this->translate('Flap Detection'), - 'service_obsessing' => $this->translate('Obsessing'), - )); - } - - protected function applyQueryFilter($query) - { - $params = clone $this->params; - $modifyFilter = $params->shift('modifyFilter'); - - $filter = Filter::fromQueryString((string) $params); - if ($modifyFilter) { - $this->view->filterWidget = Widget::create('filterEditor', array( - 'filter' => $filter, - 'query' => $query - )); - } - $this->view->filter = $filter; - $query->applyFilter($filter); - return $query; - } - - /** - * Create an array with all unique values as keys. - * - * @param array $values The array containing the objects - * @param $key The key to access - * - * @return array - */ - private function getUniqueValues($values, $key) - { - $unique = array(); - foreach ($values as $value) { - if (is_array($value)) { - $unique[$value[$key]] = $value[$key]; - } else { - $unique[$value->$key] = $value->$key; - } - } - return $unique; - } - - /** - * Get the numbers of problems of the given objects - * - * @param $objects The objects containing the problems - * - * @return int The problem count - */ - private function getProblems($objects) - { - $problems = 0; - foreach ($objects as $object) { - if (property_exists($object, 'host_unhandled_service_count')) { - $problems += $object->host_unhandled_service_count; - } else if ( - property_exists($object, 'service_handled') && - !$object->service_handled && - $object->service_state > 0 - ) { - $problems++; - } - } - return $problems; - } - - private function countStates($objects, $type = 'host', $unique = null) - { - $known = array(); - if ($type === 'host') { - $states = array_fill_keys($this->view->getHelper('MonitoringState')->getHostStateNames(), 0); - } else { - $states = array_fill_keys($this->view->getHelper('MonitoringState')->getServiceStateNames(), 0); - } - foreach ($objects as $object) { - if (isset($unique)) { - if (array_key_exists($object->$unique, $known)) { - continue; - } - $known[$object->$unique] = true; - } - $states[$this->view->monitoringState($object, $type)]++; - } - return $states; - } - - private function createPie($states, $colors, $title) - { - $chart = new InlinePie(array_values($states), $title, $colors); - $chart->setLabel(array_keys($states))->setSize(100); - $chart->setTitle($title); - return $chart; - } - - - private function getComments($objects) - { - $unique = array(); - foreach ($objects as $object) { - $unique = array_merge($unique, $this->getUniqueValues($object->comments, 'comment_internal_id')); - } - return array_keys($unique); - } - - private function getProperties($objects, $property) - { - $objectnames = array(); - foreach ($objects as $object) { - $objectnames[] = $object->$property; - } - return $objectnames; - } - - private function getDowntimes($objects) - { - $downtimes = array(); - foreach ($objects as $object) - { - if ( - (property_exists($object, 'host_in_downtime') && $object->host_in_downtime) || - (property_exists($object, 'service_in_downtime') && $object->service_in_downtime) - ) { - $downtimes[] = true; - } - } - return $downtimes; - } - - - /** - * Handle the form to edit configuration flags. - * - * @param $flags array The used flags. - */ - private function handleConfigurationForm(array $flags) - { - $this->view->form = $form = new MultiCommandFlagForm($flags); - $this->view->formElements = $form->buildCheckboxes(); - $form->setRequest($this->_request); - if ($form->isSubmittedAndValid()) { - // TODO: Handle commands - $changed = $form->getChangedValues(); - } - if ($this->_request->isPost() === false) { - $this->view->form->initFromItems($this->view->objects); - } - } -} From 41ef926fd6511aecba184a803c2ed81b3a044a5d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:39:33 +0100 Subject: [PATCH 09/16] monitoring: Remove the CommandController The controller is no longer used. --- .../controllers/CommandController.php | 1098 ----------------- 1 file changed, 1098 deletions(-) delete mode 100644 modules/monitoring/application/controllers/CommandController.php diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php deleted file mode 100644 index d2615104a..000000000 --- a/modules/monitoring/application/controllers/CommandController.php +++ /dev/null @@ -1,1098 +0,0 @@ -form = $form; - } - - /** - * Test if we have a valid form object - * - * @return bool - */ - public function issetForm() - { - return $this->form !== null && ($this->form instanceof Form); - } - - protected function addTitleTab($action) - { - $this->getTabs()->add($action, array( - 'title' => ucfirst($action), - 'url' => Url::fromRequest() - ))->activate($action); - } - - /** - * Post dispatch method - * - * When we have a form put it into the view - */ - public function postDispatch() - { - - if ($this->issetForm()) { - if ($this->form->isSubmittedAndValid()) { - $this->_helper->viewRenderer->setNoRender(true); - $this->_helper->layout()->disableLayout(); - $this->ignoreXhrBody(); - if ($this->_request->getHeader('referer') && ! $this->getRequest()->isXmlHttpRequest()) { - $this->redirect($this->_request->getHeader('referer')); - } - } else { - $this->view->form = $this->form; - } - } - parent::postDispatch(); - } - - /** - * Controller configuration - * - * @throws Icinga\Exception\ConfigurationError - */ - public function init() - { - if ($this->_request->isPost()) { - $instance = $this->_request->getPost('instance'); - $targetConfig = Config::module('monitoring', 'instances'); - if ($instance) { - if ($targetConfig->get($instance)) { - $this->target = new CommandPipe($targetConfig->get($instance)); - } else { - throw new ConfigurationError( - $this->translate('Instance is not configured: %s'), - $instance - ); - } - } else { - if ($targetConfig && $targetInfo = $targetConfig->current()) { - // Take the very first section - $this->target = new CommandPipe($targetInfo); - } else { - throw new ConfigurationError($this->translate('No instances are configured yet')); - } - } - } - - if ($this->getRequest()->getActionName() !== 'list') { - $this->_helper->viewRenderer->setRender(self::DEFAULT_VIEW_SCRIPT); - } - - $this->view->objects = array(); - } - - /** - * Retrieve all existing targets for host- and service combination - * - * @param $hostOnly Ignore the service parameters - * (for example when using commands that only make sense for hosts) - * @return array Array of monitoring objects - * @throws Icinga\Exception\MissingParameterException - */ - private function selectCommandTargets($hostOnly = false) - { - $query = null; - - $fields = array( - 'host_name', - 'host_state' - ); - - try { - $hostname = $this->getParam('host', null); - $servicename = $this->getParam('service', null); - - if (!$hostname && !$servicename) { - throw new MissingParameterException('No target given for this command'); - } - - if ($servicename && !$hostOnly) { - $fields[] = 'service_description'; - $query = $this->backend->select() - ->from('serviceStatus', $fields) - ->where('host', $hostname) - ->where('service', $servicename); - } elseif ($hostname) { - $query = $this->backend->select()->from('hostStatus', $fields)->where('host', $hostname); - } else { - throw new MissingParameterException('hostOnly command got no hostname'); - } - return $query->getQuery()->fetchAll(); - - } catch (\Exception $e) { - Logger::error( - "CommandController: SQL Query '%s' failed (message %s) ", - $query ? (string) $query->dump() : '--', $e->getMessage() - ); - return array(); - } - } - - /** - * Convert other params into valid command structure - * - * @param array $supported Array of supported parameter names - * @param array $params Parameters from request - * - * @return array Return - */ - private function selectOtherTargets(array $supported, array $params) - { - $others = array_diff_key($supported, array('host' => true, 'service' => true)); - $otherParams = array_intersect_key($params, $others); - $out = array(); - - foreach ($otherParams as $name => $value) { - $data = new stdClass(); - $data->{$name} = $value; - $out[] = $data; - } - - return $out; - } - - /** - * Displays a list of all commands - * - * This method uses reflection on the sourcecode to determine all *Action classes and return - * a list of them (ignoring the listAction) - */ - public function listAction() - { - $reflection = new ReflectionObject($this); - $commands = array(); - $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC); - foreach ($methods as $method) { - $name = $method->getName(); - if ($name !== 'listAction' && preg_match('/Action$/', $name)) { - $commands[] = preg_replace('/Action$/', '', $name); - } - } - $this->view->commands = $commands; - } - - /** - * Tell the controller that at least one of the parameters in $supported is required to be availabe - * - * @param array $supported An array of properties to check for existence in the POST or GET parameter list - * @throws Exception When non of the supported parameters is given - */ - private function setSupportedParameters(array $supported) - { - $objects = array(); - - $supported = array_flip($supported); - - $given = array_intersect_key($supported, $this->getRequest()->getParams()); - - if (empty($given)) { - throw new IcingaException( - 'Missing parameter, supported: %s', - implode(', ', array_flip($supported)) - ); - } - - if (isset($given['host'])) { - $objects = $this->selectCommandTargets(!in_array("service", $supported)); - if (empty($objects)) { - throw new IcingaException('No objects found for your command'); - } - } - - $this->view->objects = $objects; - } - - // ------------------------------------------------------------------------ - // Commands for hosts / services - // ------------------------------------------------------------------------ - - /** - * Handle command disableactivechecks - */ - public function disableactivechecksAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - - $form = new SingleArgumentCommandForm(); - - $form->setCommand( - 'DISABLE_HOST_CHECK', - 'DISABLE_SVC_CHECK' - ); - - $form->setGlobalCommands( - 'STOP_EXECUTING_HOST_CHECKS', - 'STOP_EXECUTING_SVC_CHECKS' - ); - - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Disable Active Checks')); - - if ($form->provideGlobalCommand()) { - $form->addNote($this->translate('Disable active checks on a program-wide basis.')); - } else { - $form->addNote($this->translate('Disable active checks for this object.')); - } - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, active checks will be disabled')); - } - } - - /** - * Handle command enableactivechecks - */ - public function enableactivechecksAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setCommand('ENABLE_HOST_CHECK', 'ENABLE_SVC_CHECK'); - $form->setGlobalCommands('START_EXECUTING_HOST_CHECKS', 'START_EXECUTING_SVC_CHECKS'); - - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Enable Active Checks')); - if ($form->provideGlobalCommand()) { - $form->addNote($this->translate('Enable active checks on a program-wide basis.')); - } else { - $form->addNote($this->translate('Enable active checks for this object.')); - } - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, active checks will be enabled')); - } - } - - /** - * Handle command reschedulenextcheck - */ - public function reschedulenextcheckAction() - { - $this->addTitleTab('Reschedule Next Check'); - $this->setSupportedParameters(array('host', 'service')); - $form = new RescheduleNextCheckForm(); - $form->setRequest($this->getRequest()); - $form->setConfiguration(Config::app()); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, check will be rescheduled')); - } - } - - /** - * Handle command submitpassivecheckresult - */ - public function submitpassivecheckresultAction() - { - $this->setSupportedParameters(array('host', 'service')); - $type = SubmitPassiveCheckResultForm::TYPE_SERVICE; - if ($this->getParam('service', null) === null) { - $type = SubmitPassiveCheckResultForm::TYPE_HOST; - } - - $form = new SubmitPassiveCheckResultForm(); - $form->setRequest($this->getRequest()); - $form->setType($type); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Passive check result has been submitted')); - } - } - - /** - * Handle command stopobsessing - */ - public function stopobsessingAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Stop obsessing')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Disable obsessing on a program-wide basis.')); - } else { - $form->addNote($this->translate('Stop obsessing over this object.')); - } - - $form->setCommand( - 'STOP_OBSESSING_OVER_HOST', - 'STOP_OBSESSING_OVER_SVC' - ); - - $form->setGlobalCommands( - 'STOP_OBSESSING_OVER_HOST_CHECKS', - 'STOP_OBSESSING_OVER_SVC_CHECKS' - ); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, obsessing will be disabled')); - } - } - - /** - * Handle command startobsessing - */ - public function startobsessingAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Start obsessing')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Enable obsessing on a program-wide basis.')); - } else { - $form->addNote($this->translate('Start obsessing over this object.')); - } - - $form->setCommand( - 'START_OBSESSING_OVER_HOST', - 'START_OBSESSING_OVER_SVC' - ); - - $form->setGlobalCommands( - 'START_OBSESSING_OVER_HOST_CHECKS', - 'START_OBSESSING_OVER_SVC_CHECKS' - ); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, obsessing will be enabled')); - } - } - - /** - * Handle command stopacceptingpassivechecks - */ - public function stopacceptingpassivechecksAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Stop Accepting Passive Checks')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Disable passive checks on a program-wide basis.')); - } else { - $form->addNote($this->translate('Passive checks for this object will be omitted.')); - } - - $form->setCommand( - 'DISABLE_PASSIVE_HOST_CHECKS', - 'DISABLE_PASSIVE_SVC_CHECKS' - ); - - $form->setGlobalCommands( - 'STOP_ACCEPTING_PASSIVE_HOST_CHECKS', - 'STOP_ACCEPTING_PASSIVE_SVC_CHECKS' - ); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, passive check results will be refused')); - } - } - - /** - * Handle command startacceptingpassivechecks - */ - public function startacceptingpassivechecksAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Start Accepting Passive Checks')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Enable passive checks on a program-wide basis.')); - } else { - $form->addNote($this->translate('Passive checks for this object will be accepted.')); - } - - $form->setCommand( - 'ENABLE_PASSIVE_HOST_CHECKS', - 'ENABLE_PASSIVE_SVC_CHECKS' - ); - - $form->setGlobalCommands( - 'START_ACCEPTING_PASSIVE_HOST_CHECKS', - 'START_ACCEPTING_PASSIVE_SVC_CHECKS' - ); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, passive check results will be accepted')); - } - } - - /** - * Disable notifications with expiration - * - * This is a global command only - */ - public function disablenotificationswithexpireAction() - { - $this->setParam('global', 1); - $form = new DisableNotificationWithExpireForm(); - $form->setRequest($this->_request); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, notifications will be disabled')); - } - } - - /** - * Handle command disablenotifications - */ - public function disablenotificationsAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - - $form->setSubmitLabel($this->translate('Disable Notifications')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Disable notifications on a program-wide basis.')); - } else { - $form->addNote($this->translate('Notifications for this object will be disabled.')); - } - - $form->setCommand('DISABLE_HOST_NOTIFICATIONS', 'DISABLE_SVC_NOTIFICATIONS'); - $form->setGlobalCommands('DISABLE_NOTIFICATIONS'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, notifications will be disabled')); - } - - } - - /** - * Handle command enablenotifications - */ - public function enablenotificationsAction() - { - $this->addTitleTab('Enable Notifications'); - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - - $form->setSubmitLabel($this->translate('Enable Notifications')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Enable notifications on a program-wide basis.')); - } else { - $form->addNote($this->translate('Notifications for this object will be enabled.')); - } - - $form->setCommand('ENABLE_HOST_NOTIFICATIONS', 'ENABLE_SVC_NOTIFICATIONS'); - $form->setGlobalCommands('ENABLE_NOTIFICATIONS'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, notifications will be enabled')); - } - } - - /** - * Handle command sendcustomnotification - */ - public function sendcustomnotificationAction() - { - $this->setSupportedParameters(array('host', 'service')); - $form = new CustomNotificationForm(); - $form->setRequest($this->getRequest()); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Custom notification has been sent')); - } - } - - /** - * Handle command scheduledowntime - */ - public function scheduledowntimeAction() - { - $this->addTitleTab('Schedule Downtime'); - $this->setSupportedParameters(array('host', 'service')); - $form = new ScheduleDowntimeForm(); - $form->setRequest($this->getRequest()); - $form->setConfiguration(Config::app()); - $form->setWithChildren(false); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Downtime scheduling requested')); - } - } - - /** - * Handle command scheduledowntimeswithchildren - */ - public function scheduledowntimeswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new ScheduleDowntimeForm(); - $form->setRequest($this->getRequest()); - $form->setConfiguration(Config::app()); - $form->setWithChildren(true); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Downtime scheduling requested')); - } - } - - /** - * Handle command removedowntimeswithchildren - */ - public function removedowntimeswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Remove Downtime(s)')); - $form->addNote($this->translate('Remove downtime(s) from this host and its services.')); - $form->setCommand('DEL_DOWNTIME_BY_HOST_NAME', 'DEL_DOWNTIME_BY_HOST_NAME'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Downtime removal requested')); - } - } - - /** - * Handle command disablenotificationswithchildren - */ - public function disablenotificationswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Disable Notifications')); - $form->addNote($this->translate('Notifications for this host and its services will be disabled.')); - $form->setCommand('DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - $form->setCommand('DISABLE_HOST_NOTIFICATIONS', 'DISABLE_SVC_NOTIFICATIONS'); - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, notifications will be disabled')); - } - } - - /** - * Handle command enablenotificationswithchildren - */ - public function enablenotificationswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Enable Notifications')); - $form->addNote($this->translate('Notifications for this host and its services will be enabled.')); - $form->setCommand('ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - $form->setCommand('ENABLE_HOST_NOTIFICATIONS', 'ENABLE_SVC_NOTIFICATIONS'); - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, notifications will be enabled')); - } - } - - /** - * Handle command reschedulenextcheckwithchildren - */ - public function reschedulenextcheckwithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new RescheduleNextCheckForm(); - $form->setRequest($this->getRequest()); - $form->setConfiguration(Config::app()); - $form->setWithChildren(true); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, checks will be rescheduled')); - } - } - - /** - * Handle command disableactivecheckswithchildren - */ - public function disableactivecheckswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Disable Active Checks')); - $form->addNote($this->translate('Disable active checks for this host and its services.')); - $form->setCommand('DISABLE_HOST_CHECK'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - // @TODO(mh): Missing child command - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, active checks will be disabled')); - } - } - - /** - * Handle command enableactivecheckswithchildren - */ - public function enableactivecheckswithchildrenAction() - { - $this->setSupportedParameters(array('host')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Enable Active Checks')); - $form->addNote($this->translate('Enable active checks for this host and its services.')); - $form->setCommand('ENABLE_HOST_CHECK'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - // @TODO(mh): Missing child command - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, active checks will be enabled')); - } - } - - /** - * Handle command disableeventhandler - */ - public function disableeventhandlerAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Disable Event Handler')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Disable event handler for the whole system.')); - } else { - $form->addNote($this->translate('Disable event handler for this object.')); - } - - $form->setCommand( - 'DISABLE_HOST_EVENT_HANDLER', - 'DISABLE_SVC_EVENT_HANDLER' - ); - - $form->setGlobalCommands('DISABLE_EVENT_HANDLERS'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, event handlers will be disabled')); - } - } - - /** - * Handle command enableeventhandler - */ - public function enableeventhandlerAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Enable Event Handler')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Enable event handlers on the whole system.')); - } else { - $form->addNote($this->translate('Enable event handler for this object.')); - } - - $form->setCommand( - 'ENABLE_HOST_EVENT_HANDLER', - 'ENABLE_SVC_EVENT_HANDLER' - ); - - $form->setGlobalCommands('ENABLE_EVENT_HANDLERS'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, event handlers will be enabled')); - } - } - - /** - * Handle command disableflapdetection - */ - public function disableflapdetectionAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Disable Flapping Detection')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Disable flapping detection on a program-wide basis.')); - } else { - $form->addNote($this->translate('Disable flapping detection for this object.')); - } - - $form->setCommand( - 'DISABLE_HOST_FLAP_DETECTION', - 'DISABLE_SVC_FLAP_DETECTION' - ); - - $form->setGlobalCommands( - 'DISABLE_FLAP_DETECTION' - ); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, flap detection will be disabled')); - } - } - - /** - * Handle command enableflapdetection - */ - public function enableflapdetectionAction() - { - $this->setSupportedParameters(array('host', 'service', 'global')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Enable Flapping Detection')); - - if ($form->provideGlobalCommand() === true) { - $form->addNote($this->translate('Enable flapping detection on a program-wide basis.')); - } else { - $form->addNote($this->translate('Enable flapping detection for this object.')); - } - - $form->setCommand( - 'ENABLE_HOST_FLAP_DETECTION', - 'ENABLE_SVC_FLAP_DETECTION' - ); - - $form->setGlobalCommands( - 'ENABLE_FLAP_DETECTION' - ); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, flap detection will be enabled')); - } - } - - /** - * Handle command addcomment - */ - public function addcommentAction() - { - $this->addTitleTab('Add comment'); - $this->setSupportedParameters(array('host', 'service')); - $form = new CommentForm(); - $form->setRequest($this->_request); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Your new comment has been submitted')); - } - } - - /** - * Remove a single comment - */ - public function removecommentAction() - { - $this->addTitleTab('Remove Comment'); - $this->setSupportedParameters(array('commentid', 'host', 'service')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->_request); - $form->setCommand('DEL_HOST_COMMENT', 'DEL_SVC_COMMENT'); - $form->setParameterName('commentid'); - $form->setSubmitLabel($this->translate('Remove comment')); - $form->setObjectIgnoreFlag(true); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Comment removal has been requested')); - } - } - - /** - * Handle command resetattributes - */ - public function resetattributesAction() - { - $this->setSupportedParameters(array('host', 'service')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Reset Attributes')); - $form->addNote($this->translate('Reset modified attributes to its default.')); - $form->setCommand('CHANGE_HOST_MODATTR', 'CHANGE_SVC_MODATTR'); - $form->setParameterValue(0); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - } - } - - /** - * Handle command acknowledgeproblem - */ - public function acknowledgeproblemAction() - { - $this->addTitleTab('Acknowledge Problem'); - $this->setSupportedParameters(array('host', 'service')); - $form = new AcknowledgeForm(); - $form->setRequest($this->getRequest()); - $form->setConfiguration(Config::app()); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Acknowledgement has been sent')); - } - - $this->setForm($form); - } - - /** - * Handle command removeacknowledgement - */ - public function removeacknowledgementAction() - { - $this->addTitleTab('Remove Acknowledgement'); - $this->setSupportedParameters(array('host', 'service')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - $form->setSubmitLabel($this->translate('Remove Problem Acknowledgement')); - $form->addNote($this->translate('Remove problem acknowledgement for this object.')); - $form->setCommand('REMOVE_HOST_ACKNOWLEDGEMENT', 'REMOVE_SVC_ACKNOWLEDGEMENT'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Acknowledgement removal has been requested')); - } - } - - /** - * Handle command delaynotification - */ - public function delaynotificationAction() - { - $this->setSupportedParameters(array('host', 'service')); - $form = new DelayNotificationForm(); - $form->setRequest($this->getRequest()); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Notification delay has been requested')); - } - } - - /** - * Handle command removedowntime - */ - public function removedowntimeAction() - { - $this->setSupportedParameters(array('host', 'service', 'downtimeid')); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->getRequest()); - - $form->setSubmitLabel($this->translate('Delete Downtime')); - $form->setParameterName('downtimeid'); - $form->addNote($this->translate('Delete a single downtime with the id shown above')); - $form->setCommand('DEL_HOST_DOWNTIME', 'DEL_SVC_DOWNTIME'); - $form->setObjectIgnoreFlag(true); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Downtime removal has been requested')); - } - } - - /** - * Shutdown the icinga process - */ - public function shutdownprocessAction() - { - $this->setParam('global', '1'); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->_request); - - $form->setSubmitLabel($this->translate('Shutdown monitoring process')); - $form->addNote($this->translate('Stop monitoring instance. You have to start it again from command line.')); - $form->setGlobalCommands('SHUTDOWN_PROCESS'); - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, process will shut down')); - } - } - - /** - * Restart the icinga process - */ - public function restartprocessAction() - { - $this->setParam('global', '1'); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->_request); - - $form->setSubmitLabel($this->translate('Restart monitoring process')); - $form->addNote($this->translate('Restart the monitoring process.')); - $form->setGlobalCommands('RESTART_PROCESS'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, monitoring process will restart now')); - } - } - - /** - * Disable processing of performance data - */ - public function disableperformancedataAction() - { - $this->setParam('global', 1); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->_request); - - $form->setSubmitLabel($this->translate('Disable Performance Data')); - $form->addNote($this->translate('Disable processing of performance data on a program-wide basis.')); - - $form->setGlobalCommands('DISABLE_PERFORMANCE_DATA'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, performance data processing will be disabled')); - } - } - - /** - * Enable processing of performance data - */ - public function enableperformancedataAction() - { - $this->setParam('global', 1); - $form = new SingleArgumentCommandForm(); - $form->setRequest($this->_request); - - $form->setSubmitLabel($this->translate('Enable Performance Data')); - $form->addNote($this->translate('Enable processing of performance data on a program-wide basis.')); - - $form->setGlobalCommands('ENABLE_PERFORMANCE_DATA'); - - $this->setForm($form); - - if ($form->IsSubmittedAndValid() === true) { - $this->target->sendCommand($form->createCommand(), $this->view->objects); - Notification::success($this->translate('Command has been sent, performance data processing will be enabled')); - } - } -} From c28f4284e4536378e81856e5c3d4934c70999381 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:40:56 +0100 Subject: [PATCH 10/16] monitoring: Remove the command/* view scripts They are no longer used. --- .../views/scripts/command/list.phtml | 10 -------- .../views/scripts/command/renderform.phtml | 25 ------------------- 2 files changed, 35 deletions(-) delete mode 100644 modules/monitoring/application/views/scripts/command/list.phtml delete mode 100644 modules/monitoring/application/views/scripts/command/renderform.phtml diff --git a/modules/monitoring/application/views/scripts/command/list.phtml b/modules/monitoring/application/views/scripts/command/list.phtml deleted file mode 100644 index 747dd4b5e..000000000 --- a/modules/monitoring/application/views/scripts/command/list.phtml +++ /dev/null @@ -1,10 +0,0 @@ -

- \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/command/renderform.phtml b/modules/monitoring/application/views/scripts/command/renderform.phtml deleted file mode 100644 index 9c8e79428..000000000 --- a/modules/monitoring/application/views/scripts/command/renderform.phtml +++ /dev/null @@ -1,25 +0,0 @@ -
-tabs ?> -
-
-objects) && !empty($this->objects) && isset($this->objects[0]->host_name)): ?> - - - - - - - - -objects as $object): ?> - - - - - - -
icon('host') ?> Hosticon('conf') ?> Service
host_name; ?>service_description) ? $object->service_description : '') ?>
- - -form ?> -
From 3d95e37b7f99ad42d9990b50c28a4635b88a017b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:43:39 +0100 Subject: [PATCH 11/16] monitoring: Count services once in services/show.phtml --- .../monitoring/application/views/scripts/services/show.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index e8a4c70a1..5b39489e2 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -2,13 +2,14 @@ tabs ?>
- + + translate('No services matching the filter') ?>
- translatePlural('Service (%u)', 'Services (%u)', array_sum(array_values($serviceStates))), array_sum(array_values($serviceStates))) ?> + translatePlural('Service (%u)', 'Services (%u)', $serviceCount), $serviceCount) ?>
serviceStatesPieChart ?> From a7a99b5856423ddbb29807886a11a2f5d2b1ca6f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:44:22 +0100 Subject: [PATCH 12/16] monitoring: Count hosts once in services/show.phtml --- .../monitoring/application/views/scripts/services/show.phtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 5b39489e2..2e73c8c5d 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -23,7 +23,8 @@
- translatePlural('Host (%u)', 'Hosts (%u)', array_sum(array_values($hostStates))), array_sum(array_values($hostStates))) ?> + + translatePlural('Host (%u)', 'Hosts (%u)', $hostCount), $hostCount) ?>
hostStatesPieChart ?> From df3d7d2034772d12c7cac6e49d6663babeaf4970 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:45:24 +0100 Subject: [PATCH 13/16] monitoring: Count unhandled services once in services/show.phtml --- .../monitoring/application/views/scripts/services/show.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 2e73c8c5d..794849141 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -70,13 +70,14 @@

+ translatePlural( '%u Unhandled Service Problem', '%u Unhandled Service Problems', - count($unhandledObjects) + $unhandledCount ), - count($unhandledObjects) + $unhandledCount ) ?>

From 128f6822f1baf4fb562de8aaff0df8364cd0c8c3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:46:08 +0100 Subject: [PATCH 14/16] monitoring: Count acknowledged services once in services/show.phtml --- .../monitoring/application/views/scripts/services/show.phtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 794849141..46e3babf1 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -98,13 +98,14 @@

+ translatePlural( '%u Acknowledged Service Problem', '%u Acknowledged Service Problems', - count($acknowledgedObjects) + $acknowledgedCount ), - count($acknowledgedObjects) + $acknowledgedCount ) ?>

From 2e4e04551d8e062426ac0df959e768b97b59c801 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:47:10 +0100 Subject: [PATCH 15/16] monitoring: Count services in downtime once in services/show.phtml --- .../application/views/scripts/services/show.phtml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index 46e3babf1..cb19c2f5f 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -115,10 +115,18 @@

+ icon('plug') ?> - translatePlural('%u service is in downtime', '%u services are in downtime', count($objectsInDowntime)), count($objectsInDowntime)) ?> + translatePlural( + '%u service is in downtime', + '%u services are in downtime', + $inDowntimeCount + ), + $inDowntimeCount + ) ?>

From 9c989306d9ba8ca4fddf27793876e8abd55fe768 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 30 Dec 2014 10:48:30 +0100 Subject: [PATCH 16/16] monitoring: Count services having comments once in services/show.phtml --- .../application/views/scripts/services/show.phtml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/services/show.phtml b/modules/monitoring/application/views/scripts/services/show.phtml index cb19c2f5f..65049b792 100644 --- a/modules/monitoring/application/views/scripts/services/show.phtml +++ b/modules/monitoring/application/views/scripts/services/show.phtml @@ -131,12 +131,20 @@ - getComments())): ?> + getComments()) ?> +

icon('comment') ?> - translatePlural('%u comment', '%u comments', count($objects->getComments())), count($objects->getComments())) ?> + translatePlural( + '%u comment', + '%u comments', + $havingCommentsCount + ), + $havingCommentsCount + ) ?>