From ff9c29472e0a5f94e771abbcfd343383e58048f3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 25 Jun 2014 21:38:55 +0200 Subject: [PATCH] monitoring/status: re-introduce comments, problems This re-introduces expensive columns been disabled time ago and adds even more to it. We are now showing last comment, last ack comment and service problem count on hosts in list views. It still costs performance, but seems that we can stand it. I'd like to add more like this to the host view. --- .../controllers/ListController.php | 9 ++- .../views/scripts/list/hosts.phtml | 10 +-- .../views/scripts/list/services.phtml | 8 ++- .../Backend/Ido/Query/StatusQuery.php | 72 +++++++++++++------ .../Monitoring/DataView/HostStatus.php | 6 +- .../Monitoring/DataView/ServiceStatus.php | 3 + .../library/Monitoring/Object/Service.php | 2 +- 7 files changed, 78 insertions(+), 32 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 8f939bf91..f18296b07 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -82,9 +82,12 @@ class Monitoring_ListController extends Controller 'host_last_state_change', 'host_notifications_enabled', // 'host_unhandled_service_count', + 'host_unhandled_services', 'host_action_url', 'host_notes_url', - // 'host_last_comment', + 'host_last_comment', + 'host_last_ack', + 'host_last_downtime', 'host_active_checks_enabled', 'host_passive_checks_enabled', 'host_current_check_attempt', @@ -147,7 +150,9 @@ class Monitoring_ListController extends Controller 'service_notifications_enabled', 'service_action_url', 'service_notes_url', - // 'service_last_comment', + 'service_last_comment', + 'service_last_ack', + 'service_last_downtime', 'service_active_checks_enabled', 'service_passive_checks_enabled', 'current_check_attempt' => 'service_current_check_attempt', diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index c94d146a3..e484a6fe7 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -65,18 +65,17 @@ if ($hosts->count() === 0) { } } - // Not available right now: if (isset($host->host_last_comment) && $host->host_last_comment !== null) { - $icons[] = $this->icon('comment.png', 'Comments'); + $icons[] = $this->icon('comment.png', 'Comment: ' . $host->host_last_comment); } ?>
- host_unhandled_service_count) && $host->host_unhandled_service_count > 0): ?> - - host_unhandled_service_count; ?> + host_unhandled_services) && $host->host_unhandled_services > 0): ?> + + host_unhandled_services ?> @@ -96,6 +95,7 @@ if ($hosts->count() === 0) { host_icon_image) : ?> img($this->resolveMacros($host->host_icon_image, $host), array('align' => 'right')) ?> + host_name ?>
escape(substr(strip_tags($host->host_output), 0, 10000)); ?> diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 75258c9db..10c78fd27 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -64,7 +64,9 @@ foreach ($services as $service): service_acknowledged && !$service->service_in_downtime): ?> - icon('acknowledgement.png', 'Acknowledged') ?> + icon('acknowledgement.png', 'Acknowledged' . ( + $service->service_last_ack ? ': ' . $service->service_last_ack : '' + )) ?> service_is_flapping): ?> @@ -79,6 +81,10 @@ foreach ($services as $service): icon('in_downtime.png', 'In Downtime') ?> + service_last_comment) && $service->service_last_comment !== null): ?> + icon('comment.png', 'Comment: ' . $service->service_last_comment) ?> + + service_active_checks_enabled): ?> service_passive_checks_enabled): ?> icon('active_passive_checks_disabled.png', 'Active And Passive Checks Disabled') ?> diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index 7a9af1524..9144567fd 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -30,6 +30,8 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; + class StatusQuery extends IdoQuery { protected $allowCustomVars = true; @@ -293,16 +295,19 @@ class StatusQuery extends IdoQuery END' ), 'serviceproblemsummary' => array( -// 'host_unhandled_service_count' => 'sps.unhandled_service_count' - 'host_unhandled_service_count' => '(NULL)' + 'host_unhandled_services' => 'sps.unhandled_services_count' ), 'lasthostcomment' => array( -// 'host_last_comment' => 'hlc.comment_id' - 'host_last_comment' => '(NULL)' + 'host_last_comment' => 'hlc.last_comment_data', + 'host_last_downtime' => 'hlc.last_downtime_data', + 'host_last_flapping' => 'hlc.last_flapping_data', + 'host_last_ack' => 'hlc.last_ack_data', ), 'lastservicecomment' => array( -// 'service_last_comment' => 'slc.comment_id' - 'service_last_comment' => '(NULL)' + 'service_last_comment' => 'slc.last_comment_data', + 'service_last_downtime' => 'slc.last_downtime_data', + 'service_last_flapping' => 'slc.last_flapping_data', + 'service_last_ack' => 'slc.last_ack_data', ) ); @@ -325,9 +330,6 @@ class StatusQuery extends IdoQuery $this->joinedVirtualTables = array( 'hosts' => true, 'hoststatus' => true, - 'lasthostcomment' => true, - 'lastservicecomment' => true, - 'serviceproblemsummary' => true, ); } @@ -467,10 +469,23 @@ class StatusQuery extends IdoQuery return $this; } - // TODO: This will be obsolete once status is based on the new hoststatus, offering much more - // columns in a more efficient way protected function joinServiceproblemsummary() { + $sub = new Zend_Db_Expr('(SELECT' + . ' SUM(CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 0 ELSE 1 END) AS unhandled_services_count,' + . ' SUM(CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END) AS handled_services_count,' + . ' s.host_object_id FROM icinga_servicestatus ss' + . ' JOIN icinga_services s' + . ' ON s.service_object_id = ss.service_object_id' + . ' AND ss.current_state > 0' + . ' GROUP BY s.host_object_id)'); + $this->select->joinLeft( + array('sps' => $sub), + 'sps.host_object_id = hs.host_object_id', + array() + ); + return; + $this->select->joinleft( array ('sps' => new \Zend_Db_Expr( '(SELECT COUNT(s.service_object_id) as unhandled_service_count, s.host_object_id as host_object_id '. @@ -484,14 +499,30 @@ class StatusQuery extends IdoQuery ); } - // TODO: Terribly slow. As I have no idea of how to fix this we should remove it. + protected function getLastCommentSubQuery() + { + $sub = '(SELECT' + . ' lc.object_id,' + . " CASE WHEN lc.entry_type = 1 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_comment_data," + . " CASE WHEN lc.entry_type = 2 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_downtime_data," + . " CASE WHEN lc.entry_type = 3 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_flapping_data," + . " CASE WHEN lc.entry_type = 4 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_ack_data" + . ' FROM icinga_comments c' + . ' JOIN (SELECT' + . ' MAX(comment_id) as comment_id,' + . ' object_id,' + . ' entry_type' + . ' FROM icinga_comments' + . ' WHERE entry_type = 1 OR entry_type = 4' + . ' GROUP BY object_id, entry_type' + . ') lc ON lc.comment_id = c.comment_id GROUP BY lc.object_id)'; + return new Zend_Db_Expr($sub); + } + protected function joinLasthostcomment() { - $this->select->joinleft( - array ('hlc' => new \Zend_Db_Expr( - '(SELECT MAX(c.comment_id) as comment_id, c.object_id '. - 'FROM icinga_comments c GROUP BY c.object_id)') - ), + $this->select->joinLeft( + array('hlc' => $this->getLastCommentSubQuery()), 'hlc.object_id = hs.host_object_id', array() ); @@ -500,11 +531,8 @@ class StatusQuery extends IdoQuery // TODO: Terribly slow. As I have no idea of how to fix this we should remove it. protected function joinLastservicecomment() { - $this->select->joinleft( - array ('slc' => new \Zend_Db_Expr( - '(SELECT MAX(c.comment_id) as comment_id, c.object_id '. - 'FROM icinga_comments c GROUP BY c.object_id)') - ), + $this->select->joinLeft( + array('slc' => $this->getLastCommentSubQuery()), 'slc.object_id = ss.service_object_id', array() ); diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index aec89a498..9bf1f97a1 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -60,7 +60,8 @@ class HostStatus extends DataView 'host_long_output', 'host_check_command', 'host_perfdata', - 'host_check_source', + 'host_check_source', + 'host_unhandled_services', 'host_passive_checks_enabled', 'host_passive_checks_enabled_changed', 'host_obsessing', @@ -80,6 +81,9 @@ class HostStatus extends DataView 'host_percent_state_change', 'host_is_flapping', 'host_last_comment', + 'host_last_downtime', + 'host_last_ack', + 'host_last_flapping', 'host_action_url', 'host_notes_url', 'host_percent_state_change', diff --git a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php index 563d7aaef..108261b89 100644 --- a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php @@ -66,6 +66,9 @@ class ServiceStatus extends DataView 'service_action_url', 'service_notes_url', 'service_last_comment', + 'service_last_downtime', + 'service_last_flapping', + 'service_last_ack', 'service_last_check', 'service_next_check', 'service_attempt', diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 5fbdf360b..8a48b89e0 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -70,7 +70,7 @@ class Service extends AbstractObject 'host_is_flapping', 'host_last_check', 'host_notifications_enabled', - 'host_unhandled_service_count', + 'host_unhandled_services', 'host_action_url', 'host_notes_url', 'host_display_name',