From 3c56f5c53aff142d601a6ce8c7b55647a208ce6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Mon, 12 Aug 2013 11:09:22 +0200 Subject: [PATCH] Remove qUrl, use ListController::query, proper default sorting refs #4187 --- .../controllers/ListController.php | 15 ++- .../views/helpers/MonitoringProperties.php | 53 ++++++++--- .../views/scripts/list/notifications.phtml | 93 ++++++------------- 3 files changed, 75 insertions(+), 86 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index a2afad499..f1947ea02 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -219,8 +219,9 @@ class Monitoring_ListController extends ModuleActionController */ public function notificationsAction() { - $query = $this->backend->select() - ->from('notification', array( + $this->view->notifications = $this->query( + 'notification', + array( 'host_name', 'service_description', 'notification_type', @@ -229,14 +230,12 @@ class Monitoring_ListController extends ModuleActionController 'notification_contact', 'notification_information', 'notification_command' - )); + ) + ); if (!$this->_getParam('sort')) { - // TODO: Remove this once MonitoringView::applyRequestSorting - // applies NotificationView::sortDefaults - $this->_request->setParam('sort', 'notification_start_time'); - $this->_request->setParam('dir', -1); // Query is still using ASC!? + $this->view->notifications->order('notification_start_time DESC'); } - $this->view->notifications = $query->applyRequest($this->_request); + $this->inheritCurrentSortColumn(); } diff --git a/modules/monitoring/application/views/helpers/MonitoringProperties.php b/modules/monitoring/application/views/helpers/MonitoringProperties.php index beb58a837..3d7de7fbd 100644 --- a/modules/monitoring/application/views/helpers/MonitoringProperties.php +++ b/modules/monitoring/application/views/helpers/MonitoringProperties.php @@ -2,6 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} + /** * Class Zend_View_Helper_MonitoringProperties */ @@ -57,12 +58,25 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract 'status_update_time' => 'Last update' ); + private static $notificationReasons = array( + 0 => 'NORMAL', + 1 => 'ACKNOWLEDGEMENT', + 2 => 'FLAPPING START', + 3 => 'FLAPPING STOP', + 4 => 'FLAPPING DISABLED', + 5 => 'DOWNTIME START', + 6 => 'DOWNTIME END', + 7 => 'DOWNTIME CANCELLED', + 8 => 'CUSTOM', + 9 => 'STALKING' + ); + /** * Return the object type * @param stdClass $object * @return mixed */ - private function getObjectType(\stdClass $object) + private function getObjectType(stdClass $object) { $keys = array_keys(get_object_vars($object)); $keyParts = explode('_', array_shift($keys), 2); @@ -75,7 +89,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param $type * @return object */ - private function dropObjectType(\stdClass $object, $type) + private function dropObjectType(stdClass $object, $type) { $vars = get_object_vars($object); $out = array(); @@ -91,7 +105,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildAttempt(\stdClass $object) + private function buildAttempt(stdClass $object) { return sprintf( '%s/%s (%s state)', @@ -116,7 +130,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildCheckType(\stdClass $object) + private function buildCheckType(stdClass $object) { if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') { return self::CHECK_PASSIVE; @@ -132,7 +146,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildLatency(\stdClass $object) + private function buildLatency(stdClass $object) { $val = ''; if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { @@ -155,7 +169,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildNextCheck(\stdClass $object) + private function buildNextCheck(stdClass $object) { if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { return self::VALUE_NA; @@ -169,7 +183,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildLastStateChange(\stdClass $object) + private function buildLastStateChange(stdClass $object) { return strftime('%Y-%m-%d %H:%M:%S', $object->last_state_change); } @@ -179,7 +193,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildLastNotification(\stdClass $object) + private function buildLastNotification(stdClass $object) { $val = ''; @@ -199,7 +213,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildFlapping(\stdClass $object) + private function buildFlapping(stdClass $object) { $val = ''; @@ -219,7 +233,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return string */ - private function buildScheduledDowntime(\stdClass $object) + private function buildScheduledDowntime(stdClass $object) { if ($object->in_downtime === '1') { return self::VALUE_YES; @@ -234,7 +248,7 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract * @param stdClass $object * @return array */ - public function monitoringProperties(\stdClass $object) + public function monitoringProperties(stdClass $object) { $type = $this->getObjectType($object); $object = $this->dropObjectType($object, $type); @@ -252,4 +266,21 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract return $out; } + + public function getNotificationType(stdClass $notification) + { + $reason = intval($notification->notification_reason); + if (!isset(self::$notificationReasons[$reason])) { + return 'N/A'; + } + $type = self::$notificationReasons[$reason]; + if ($reason === 8 ) { + if (intval($notification->notification_type) === 0) { + $type .= '(UP)'; + } else { + $type .= '(OK)'; + } + } + return $type; + } } diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index 4e4b26d06..fd3aebf5f 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -1,9 +1,16 @@ tabs->render($this); ?> -
Sort by formSelect( 'sort', @@ -44,49 +51,9 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t host_name ?> - service_description) ? 'N/A' : $notification->service_description ?> + service_description) ? '' : $notification->service_description; ?> - notification_reason) - { - case 0: - echo 'NORMAL'; - break; - case 1: - echo 'ACKNOWLEDGEMENT'; - break; - case 2: - echo 'FLAPPINGSTART'; - break; - case 3: - echo 'FLAPPINGSTOP'; - break; - case 4: - echo 'FLAPPINGDISABLED'; - break; - case 5: - echo 'DOWNTIMESTART'; - break; - case 6: - echo 'DOWNTIMEEND'; - break; - case 7: - echo 'DOWNTIMECANCELLED'; - break; - case 8: - if (intval($notification->notification_type) === 0) { - echo 'CUSTOM(UP)'; - } else { - echo 'CUSTOM(OK)'; - } - break; - case 9: - echo 'STALKING'; - break; - default: - echo 'N/A'; - } -?> + getNotificationType($notification); ?> notification_start_time ?> @@ -100,32 +67,24 @@ echo $this->paginationControl($notifications, null, null, array('preserve' => $t escape(substr(strip_tags($notification->notification_information), 0, 10000)); ?> - notification_type) === 0) { - echo $this->qlink( - '', + + notification_type) === 0): ?> + + + + +