From 85aa447516520759d26fa10aa4ae343cff74e416 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 21 Jan 2015 12:52:29 +0100 Subject: [PATCH] monitoring: Support host and service display_name in the DowntimeQuery refs #7843 --- .../Backend/Ido/Query/DowntimeQuery.php | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index f9d0d93a2..efc10f6a5 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -6,28 +6,34 @@ class DowntimeQuery extends IdoQuery { protected $columnMap = array( 'downtime' => array( - 'downtime_author' => 'sd.author_name', - 'author' => 'sd.author_name', - 'downtime_comment' => 'sd.comment_data', - 'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', - 'downtime_is_fixed' => 'sd.is_fixed', - 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', - 'downtime_triggered_by_id' => 'sd.triggered_by_id', - 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', - 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', - 'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)", - 'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END', - 'downtime_duration' => 'sd.duration', - 'downtime_is_in_effect' => 'sd.is_in_effect', - 'downtime_internal_id' => 'sd.internal_downtime_id', - 'downtime_host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', // #7278, #7279 - 'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', - 'downtime_service' => 'so.name2 COLLATE latin1_general_ci', - 'service' => 'so.name2 COLLATE latin1_general_ci', // #7278, #7279 - 'downtime_objecttype' => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END", - 'downtime_host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', - 'downtime_service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + 'downtime_author' => 'sd.author_name', + 'author' => 'sd.author_name', + 'downtime_comment' => 'sd.comment_data', + 'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', + 'downtime_is_fixed' => 'sd.is_fixed', + 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', + 'downtime_triggered_by_id' => 'sd.triggered_by_id', + 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', + 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', + 'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)", + 'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END', + 'downtime_duration' => 'sd.duration', + 'downtime_is_in_effect' => 'sd.is_in_effect', + 'downtime_internal_id' => 'sd.internal_downtime_id', + 'downtime_host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', // #7278, #7279 + 'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', + 'downtime_service' => 'so.name2 COLLATE latin1_general_ci', + 'service' => 'so.name2 COLLATE latin1_general_ci', // #7278, #7279 + 'downtime_objecttype' => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END", + 'downtime_host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', + 'downtime_service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' ), + 'hosts' => array( + 'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END' + ), + 'services' => array( + 'service_display_name' => 's.display_name' + ) ); protected function joinBaseTables() @@ -58,4 +64,29 @@ class DowntimeQuery extends IdoQuery ); $this->joinedVirtualTables = array('downtime' => true); } + + protected function joinHosts() + { + $this->select->joinLeft( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + return $this; + } + + protected function joinServices() + { + $this->select->joinLeft( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + $this->select->joinLeft( + array('sh' => $this->prefix . 'hosts'), + 'sh.host_object_id = s.host_object_id', + array() + ); + return $this; + } }