From 99041d0f15c2a1574f54268bb87eb70ff424ec58 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 21 Mar 2014 10:24:17 +0000 Subject: [PATCH] Prepare support for custom additional columns --- .../controllers/ListController.php | 71 ++++++++++++++++++- .../library/Monitoring/Controller.php | 58 --------------- 2 files changed, 70 insertions(+), 59 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 7fc2f3cce..48cdaa972 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -80,6 +80,18 @@ class Monitoring_ListController extends Controller $this->view->compact = ($this->_request->getParam('view') === 'compact'); } + protected function extraColumns() + { + $columns = preg_split( + '~,~', + $this->_request->getParam('addcolumns', ''), + -1, + PREG_SPLIT_NO_EMPTY + ); + $this->view->extraColumns = $columns; + return $columns; + } + /** * Overwrite the backend to use (used for testing) * @@ -458,7 +470,6 @@ class Monitoring_ListController extends Controller $this->view->history = $query->paginate(); } - // TODO: Should be able to identify hosts that have not a single service (without compromising the pagination) public function servicematrixAction() { $this->view->title = 'Servicematrix'; @@ -508,6 +519,64 @@ class Monitoring_ListController extends Controller return $query; } + /** + * Retrieve services from either given parameters or request + * + * @param array $params + * + * @return \Zend_Paginator + */ + protected function fetchServices(array $params = null) + { + $columns = array_merge(array( + 'host_name', + 'host_state', + 'host_state_type', + 'host_last_state_change', + 'host_address', + 'host_handled', + 'service_description', + 'service_display_name', + 'service_state', + 'service_in_downtime', + 'service_acknowledged', + 'service_handled', + 'service_output', + 'service_perfdata', + 'service_attempt', + 'service_last_state_change', + 'service_icon_image', + // 'service_long_output', + 'service_is_flapping', + 'service_state_type', + 'service_handled', + 'service_severity', + 'service_last_check', + 'service_notifications_enabled', + 'service_action_url', + 'service_notes_url', + // 'service_last_comment', + 'service_active_checks_enabled', + 'service_passive_checks_enabled', + 'current_check_attempt' => 'service_current_check_attempt', + 'max_check_attempts' => 'service_max_check_attempts' + ), $this->extraColumns()); + if ($params === null) { + $query = ServiceStatusView::fromRequest( + $this->_request, + $columns + )->getQuery(); + } else { + $params['backend'] = $this->_request->getParam('backend'); + $query = ServiceStatusView::fromParams( + $params, + $columns + )->getQuery(); + } + $this->handleFormatRequest($query); + return $query; + } + /** * Create a sort control box at the 'sortControl' view parameter * diff --git a/modules/monitoring/library/Monitoring/Controller.php b/modules/monitoring/library/Monitoring/Controller.php index 42501eb7b..3ae5e14a4 100644 --- a/modules/monitoring/library/Monitoring/Controller.php +++ b/modules/monitoring/library/Monitoring/Controller.php @@ -49,64 +49,6 @@ class Controller extends ActionController */ protected $compactView; - /** - * Retrieve services from either given parameters or request - * - * @param array $params - * - * @return \Zend_Paginator - */ - protected function fetchServices(array $params = null) - { - $columns = array( - 'host_name', - 'host_state', - 'host_state_type', - 'host_last_state_change', - 'host_address', - 'host_handled', - 'service_description', - 'service_display_name', - 'service_state', - 'service_in_downtime', - 'service_acknowledged', - 'service_handled', - 'service_output', - 'service_perfdata', - 'service_attempt', - 'service_last_state_change', - 'service_icon_image', - // 'service_long_output', - 'service_is_flapping', - 'service_state_type', - 'service_handled', - 'service_severity', - 'service_last_check', - 'service_notifications_enabled', - 'service_action_url', - 'service_notes_url', - // 'service_last_comment', - 'service_active_checks_enabled', - 'service_passive_checks_enabled', - 'current_check_attempt' => 'service_current_check_attempt', - 'max_check_attempts' => 'service_max_check_attempts' - ); - if ($params === null) { - $query = ServiceStatusView::fromRequest( - $this->_request, - $columns - )->getQuery(); - } else { - $params['backend'] = $this->_request->getParam('backend'); - $query = ServiceStatusView::fromParams( - $params, - $columns - )->getQuery(); - } - $this->handleFormatRequest($query); - return $query; - } - protected function handleFormatRequest($query) { if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {