From bcdbf413a64b40d7660c189268eb1a85d100b454 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 1 Sep 2015 16:38:06 +0200 Subject: [PATCH] Add acknowledgement view and query Add backend queries and the controller to inspect active acknowledgements. refs #10032 --- .../controllers/AcknowledgementController.php | 78 +++++++++++++ .../views/scripts/acknowledgement/index.phtml | 104 ++++++++++++++++++ modules/monitoring/configuration.php | 5 +- .../Ido/Query/AcknowledgementQuery.php | 80 ++++++++++++++ .../Monitoring/DataView/Acknowledgement.php | 54 +++++++++ 5 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 modules/monitoring/application/controllers/AcknowledgementController.php create mode 100644 modules/monitoring/application/views/scripts/acknowledgement/index.phtml create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/AcknowledgementQuery.php create mode 100644 modules/monitoring/library/Monitoring/DataView/Acknowledgement.php diff --git a/modules/monitoring/application/controllers/AcknowledgementController.php b/modules/monitoring/application/controllers/AcknowledgementController.php new file mode 100644 index 000000000..a229a22a3 --- /dev/null +++ b/modules/monitoring/application/controllers/AcknowledgementController.php @@ -0,0 +1,78 @@ +getTabs()->add( + 'acknowledgement', + array( + 'title' => $this->translate( + 'Show acknowledgements' + ), + 'label' => $this->translate('Acknowledgements'), + 'url' => Url::fromRequest() + ) + )->extend(new DashboardAction())->activate('acknowledgement'); + $this->view->title = $this->translate('Acknowledgement'); + $this->setAutorefreshInterval(15); + $query = $this->backend->select()->from( + 'acknowledgement', + array( + 'acknowledgement_id', + 'instance_id', + 'entry_time', + 'acknowledgement_type', + 'object_id', + 'state', + 'author_name', + 'comment_data', + 'is_sticky', + 'persistent_comment', + 'acknowledgement_id', + 'notify_contacts', + 'end_time', + 'endpoint_object_id', + 'acknowledgement_is_service', + 'service', + 'host' + ) + ); + + $this->applyRestriction('monitoring/filter/objects', $query); + $this->filterQuery($query); + $this->view->acknowledgements = $query; + + $this->setupLimitControl(); + $this->setupPaginationControl($this->view->acknowledgements); + $this->setupSortControl(array( + 'entry_time' => $this->translate('Entry Time'), + 'end_time' => $this->translate('End Time'), + 'state' => $this->translate('Object State'), + 'author_name' => $this->translate('Author Name') + ), $query); + } + + /** + * Apply filters on a DataView + * + * @param DataView $dataView The DataView to apply filters on + * + * @return DataView $dataView + */ + protected function filterQuery(DataView $dataView) + { + $this->setupFilterControl($dataView); + $this->handleFormatRequest($dataView); + return $dataView; + } +} diff --git a/modules/monitoring/application/views/scripts/acknowledgement/index.phtml b/modules/monitoring/application/views/scripts/acknowledgement/index.phtml new file mode 100644 index 000000000..83d41e4c1 --- /dev/null +++ b/modules/monitoring/application/views/scripts/acknowledgement/index.phtml @@ -0,0 +1,104 @@ + + +compact): ?> +
+ tabs; ?> +
+ render('list/components/selectioninfo.phtml'); ?> +
+

translate('Acknowledgements') ?>

+ sortBox; ?> + limiter; ?> + paginator; ?> + filterEditor; ?> +
+ +
+ + + + acknowledgement_is_service ? + Service::getStateText($acknowledgement->state) : Host::getStateText($acknowledgement->state); + ?> + + + + + + + +
+ icon('ok') ?> + timeAgo($acknowledgement->entry_time, $this->compact); ?> +
+ translate( + 'State was %s.', + 'Describes the past host or service state when an acknowledgement was set.' + ), $state) ?> +
+ acknowledgement_is_service): ?> + icon('service', $this->translate('Service Acknowledgement')) ?> + qlink( + $this->escape($acknowledgement->host) . ': ' . $this->escape($acknowledgement->service), + 'monitoring/service/show', + array( + 'service' => $acknowledgement->service, + 'host' => $acknowledgement->host + ), + array( + 'title' => sprintf( + $this->translate( + 'Show detailed information for this acknowledgement about service %s on host %s' + ), + $acknowledgement->service, + $acknowledgement->host + ), + 'class' => 'rowaction' + ) + ); ?> + + icon('host', $this->translate('Host Acknowledgement')) ?> + qlink( + $this->escape($acknowledgement->host), + 'monitoring/host/show', + array( + 'host' => $acknowledgement->host + ), + array( + 'title' => sprintf( + $this->translate('Show detailed information for this acknowledgement on host %s'), + $acknowledgement->host + ), + 'class' => 'rowaction' + ) + ); ?> + + +
+ icon('comment_data', $this->translate('Comment')); ?> + author_name) ? '[' . $this->escape($acknowledgement->author_name) . '] ' : ''; ?> + escape($acknowledgement->comment_data); ?> + +
+ is_sticky ? $this->icon( + 'attach', + $this->translate('Sticky, all notifications are disabled until the host or services recovers' + )) : ''; ?> + notify_contacts ? $this->icon( + 'bell', + $this->translate('Contacts are being notified about this acknowledgement.' + )) : ''; ?> + end_time ? sprintf( + $this->translate('Expires %s.'), + '' . $this->timeUntil($acknowledgement->end_time) . '' + ) : $this->translate('Does not expire.'); ?> +
+ + + translate('No comments found matching the filter'); ?> + +
diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index 12b8236ab..4d915c123 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -184,7 +184,10 @@ $section->add($this->translate('Notifications'), array( 'url' => 'monitoring/list/notifications', 'priority' => 80 )); - +$section->add($this->translate('Acknowledgements'), array( + 'url' => 'monitoring/acknowledgement', + 'priority' => 90 +)); /* * History Section diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/AcknowledgementQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/AcknowledgementQuery.php new file mode 100644 index 000000000..a65eb0240 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/AcknowledgementQuery.php @@ -0,0 +1,80 @@ + array( + 'acknowledgement_id' => 'a.acknowledgement_id', + 'instance_id' => 'a.instance_id', + 'entry_time' => 'UNIX_TIMESTAMP(a.entry_time)', + 'acknowledgement_type' => 'IF (a.acknowledgement_type = 0, \'host\', \'service\')', + 'object_id' => 'a.object_id', + 'state' => 'a.state', + 'author_name' => 'a.author_name', + 'comment_data' => 'a.comment_data', + 'is_sticky' => 'a.is_sticky', + 'persistent_comment' => 'a.persistent_comment', + 'acknowledgement_id' => 'a.acknowledgement_id', + 'notify_contacts' => 'a.notify_contacts', + 'end_time' => 'UNIX_TIMESTAMP(a.end_time)', + 'endpoint_object_id' => 'a.endpoint_object_id' + ), + 'objects' => array( + 'acknowledgement_is_service' => 'IF (o.objecttype_id = 2, 1, 0)', + 'host' => 'o.name1', + 'service' => 'o.name2' + ) + ); + + /** + * @var Zend_Db_Select + */ + protected $acknowledgementQuery; + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->acknowledgementQuery = $this->db->select(); + $this->select = $this->select->from( + array('o' => $this->prefix . 'objects') + ); + $this->select->joinLeft( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = o.object_id AND o.is_active = 1', + array() + ); + $this->select->joinLeft( + array('ss' => $this->prefix . 'servicestatus'), + 'ss.service_object_id = o.object_id AND o.is_active = 1', + array() + ); + $ackTable = $this->prefix . 'acknowledgements'; + $subQuery = '(SELECT MAX(acknowledgement_id) FROM ' . $ackTable . ' WHERE object_id = a.object_id)'; + $this->select->join( + array('a' => $ackTable), + 'o.object_id = a.object_id ' . + 'AND ((o.objecttype_id = 2 AND ss.problem_has_been_acknowledged AND ss.acknowledgement_type = 2) ' . + ' OR (o.objecttype_id = 1 AND hs.problem_has_been_acknowledged AND hs.acknowledgement_type = 2)) ' . + 'AND o.is_active = 1 AND a.acknowledgement_id = ' . $subQuery, + array() + ); + + $this->joinedVirtualTables['objects'] = true; + $this->joinedVirtualTables['acknowledgements'] = true; + $this->joinedVirtualTables['hoststatus'] = true; + $this->joinedVirtualTables['servicestatus'] = true; + } +} diff --git a/modules/monitoring/library/Monitoring/DataView/Acknowledgement.php b/modules/monitoring/library/Monitoring/DataView/Acknowledgement.php new file mode 100644 index 000000000..2ed457af4 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Acknowledgement.php @@ -0,0 +1,54 @@ +