From e9dd69267cab2460c608f2dc67f42894dacfd3e2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 13:36:53 +0200 Subject: [PATCH 001/237] monitoring: Prepare HoststatusQuery to be used when viewing hosts The Hoststatusquery does not include the joins for last ack, comment and downtime as where unsure whether or not we will still support this. refs #7344 refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 375 +++++++----------- 1 file changed, 140 insertions(+), 235 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index ec9e6bd32..5095b401c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -3,49 +3,86 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; + class HoststatusQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $allowCustomVars = true; + /** + * {@inheritdoc} + */ protected $columnMap = array( 'hosts' => array( - 'host' => 'ho.name1 COLLATE latin1_general_ci', - 'host_name' => 'ho.name1 COLLATE latin1_general_ci', - 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', - 'host_alias' => 'h.alias', - 'host_address' => 'h.address', - 'host_ipv4' => 'INET_ATON(h.address)', - 'host_icon_image' => 'h.icon_image', - 'object_type' => '(\'host\')' + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_action_url' => 'h.action_url', + 'host_address' => 'h.address', + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + 'host_icon_image' => 'h.icon_image', + 'host_icon_image_alt' => 'h.icon_image_alt', + 'host_ipv4' => 'INET_ATON(h.address)', + 'host_name' => 'ho.name1', + 'host_notes_url' => 'h.notes_url', + 'object_type' => '(\'host\')' ), 'hoststatus' => array( - 'problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END', - 'handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', - 'unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END', - 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', - 'host_output' => 'hs.output', - 'host_long_output' => 'hs.long_output', - 'host_perfdata' => 'hs.perfdata', - 'host_problem' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END', - 'host_acknowledged' => 'hs.problem_has_been_acknowledged', - 'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', - 'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', - 'host_does_active_checks' => 'hs.active_checks_enabled', - 'host_accepts_passive_checks' => 'hs.passive_checks_enabled', - 'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)', - 'host_last_hard_state' => 'hs.last_hard_state', - 'host_check_command' => 'hs.check_command', - 'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)', - 'host_next_check' => 'CASE WHEN hs.should_be_scheduled THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END', - 'host_check_execution_time' => 'hs.execution_time', - 'host_check_latency' => 'hs.latency', - 'host_notifications_enabled' => 'hs.notifications_enabled', - 'host_last_time_up' => 'hs.last_time_up', - 'host_last_time_down' => 'hs.last_time_down', - 'host_last_time_unreachable' => 'hs.last_time_unreachable', - 'host_current_check_attempt' => 'hs.current_check_attempt', - 'host_max_check_attempts' => 'hs.max_check_attempts', - 'host_severity' => 'CASE WHEN hs.current_state = 0 + 'host_acknowledged' => 'hs.problem_has_been_acknowledged', + 'host_acknowledgement_type' => 'hs.acknowledgement_type', + 'host_active_checks_enabled' => 'hs.active_checks_enabled', + 'host_active_checks_enabled_changed' => 'CASE WHEN hs.active_checks_enabled = h.active_checks_enabled THEN 0 ELSE 1 END', + 'host_attempt' => 'hs.current_check_attempt || \'/\' || hs.max_check_attempts', + 'host_check_command' => 'hs.check_command', + 'host_check_execution_time' => 'hs.execution_time', + 'host_check_latency' => 'hs.latency', + 'host_check_source' => 'hs.check_source', + 'host_check_type' => 'hs.check_type', + 'host_current_check_attempt' => 'hs.current_check_attempt', + 'host_current_notification_number' => 'hs.current_notification_number', + 'host_event_handler' => 'hs.event_handler', + 'host_event_handler_enabled' => 'hs.event_handler_enabled', + 'host_event_handler_enabled_changed' => 'CASE WHEN hs.event_handler_enabled = h.event_handler_enabled THEN 0 ELSE 1 END', + 'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled', + 'host_flap_detection_enabled' => 'hs.flap_detection_enabled', + 'host_flap_detection_enabled_changed' => 'CASE WHEN hs.flap_detection_enabled = h.flap_detection_enabled THEN 0 ELSE 1 END', + 'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', + 'host_hard_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END', + 'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', + 'host_is_flapping' => 'hs.is_flapping', + 'host_is_reachable' => 'hs.is_reachable', + 'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)', + 'host_last_hard_state' => 'hs.last_hard_state', + 'host_last_hard_state_change' => 'UNIX_TIMESTAMP(hs.last_hard_state_change)', + 'host_last_notification' => 'UNIX_TIMESTAMP(hs.last_notification)', + 'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)', + 'host_last_time_down' => 'UNIX_TIMESTAMP(hs.last_time_down)', + 'host_last_time_unreachable' => 'UNIX_TIMESTAMP(hs.last_time_unreachable)', + 'host_last_time_up' => 'UNIX_TIMESTAMP(hs.last_time_up)', + 'host_long_output' => 'hs.long_output', + 'host_max_check_attempts' => 'hs.max_check_attempts', + 'host_modified_host_attributes' => 'hs.modified_host_attributes', + 'host_next_check' => 'CASE hs.should_be_scheduled WHEN 1 THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END', + 'host_next_notification' => 'UNIX_TIMESTAMP(hs.next_notification)', + 'host_no_more_notifications' => 'hs.no_more_notifications', + 'host_normal_check_interval' => 'hs.normal_check_interval', + 'host_notifications_enabled' => 'hs.notifications_enabled', + 'host_notifications_enabled_changed' => 'CASE WHEN hs.notifications_enabled = h.notifications_enabled THEN 0 ELSE 1 END', + 'host_obsessing' => 'hs.obsess_over_host', + 'host_obsessing_changed' => 'CASE WHEN hs.obsess_over_host = h.obsess_over_host THEN 0 ELSE 1 END', + 'host_output' => 'hs.output', + 'host_passive_checks_enabled' => 'hs.passive_checks_enabled', + 'host_passive_checks_enabled_changed' => 'CASE WHEN hs.passive_checks_enabled = h.passive_checks_enabled THEN 0 ELSE 1 END', + 'host_percent_state_change' => 'hs.percent_state_change', + 'host_perfdata' => 'hs.perfdata', + 'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END', + 'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged', + 'host_process_performance_data' => 'hs.process_performance_data', + 'host_retry_check_interval' => 'hs.retry_check_interval', + 'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth', + 'host_severity' => 'CASE WHEN hs.current_state = 0 THEN CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 16 @@ -80,245 +117,113 @@ class HoststatusQuery extends IdoQuery CASE WHEN hs.state_type = 1 THEN 8 ELSE 0 - END' + END', + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', + 'host_state_type' => 'hs.state_type', + 'host_status_update_time' => 'hs.status_update_time', + 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ), 'hostgroups' => array( 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1', - 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci' - ), - 'servicegroups' => array( - 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', - 'servicegroup_name' => 'sgo.name1', - 'servicegroup_alias' => 'sg.alias' - ), - 'contactgroups' => array( - 'contactgroup' => 'contactgroup', - ), - 'contacts' => array( - 'contact' => 'hco.name1 COLLATE latin1_general_ci', - ), - 'services' => array( - 'services_cnt' => 'SUM(1)', - 'services_ok' => 'SUM(CASE WHEN ss.current_state = 0 THEN 1 ELSE 0 END)', - 'services_warning' => 'SUM(CASE WHEN ss.current_state = 1 THEN 1 ELSE 0 END)', - 'services_critical' => 'SUM(CASE WHEN ss.current_state = 2 THEN 1 ELSE 0 END)', - 'services_unknown' => 'SUM(CASE WHEN ss.current_state = 3 THEN 1 ELSE 0 END)', - 'services_pending' => 'SUM(CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 1 ELSE 0 END)', - 'services_problem' => 'SUM(CASE WHEN ss.current_state > 0 THEN 1 ELSE 0 END)', - 'services_problem_handled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 1 OR ss.scheduled_downtime_depth > 0) THEN 1 ELSE 0 END)', - 'services_problem_unhandled' => 'SUM(CASE WHEN ss.current_state > 0 AND (ss.problem_has_been_acknowledged = 0 AND ss.scheduled_downtime_depth = 0) THEN 1 ELSE 0 END)', - 'services_warning_handled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)', - 'services_critical_handled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)', - 'services_unknown_handled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END)', - 'services_warning_unhandled' => 'SUM(CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)', - 'services_critical_unhandled' => 'SUM(CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)', - 'services_unknown_unhandled' => 'SUM(CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END)', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' ), + 'serviceproblemsummary' => array( + 'host_unhandled_services' => 'sps.unhandled_services_count' + ) ); - protected $aggregateColumnIdx = array( - 'services_cnt' => true, - 'services_problem' => true, - 'services_problem_handled' => true, - 'services_problem_unhandled' => true, - ); - - protected $hcgSub; - - public function getDefaultColumns() - { - return $this->columnMap['hosts'] + $this->columnMap['hoststatus']; - } - + /** + * {@inheritdoc} + */ protected function joinBaseTables() { - // TODO: Shall we always add hostobject? $this->select->from( array('ho' => $this->prefix . 'objects'), array() - )->join( - array('hs' => $this->prefix . 'hoststatus'), - 'ho.' . $this->object_id . ' = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', - array() )->join( array('h' => $this->prefix . 'hosts'), - 'hs.host_object_id = h.host_object_id', + 'h.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() ); - $this->joinedVirtualTables = array( - 'hosts' => true, - 'hoststatus' => true, - ); + $this->joinedVirtualTables['hosts'] = true; } - protected function joinStatus() - { - $this->requireVirtualTable('services'); - } - - protected function joinServiceStatus() - { - $this->requireVirtualTable('services'); - } - - protected function joinServices() + /** + * Join host status + * + * @return $this + */ + protected function joinHoststatus() { $this->select->join( - array('s' => $this->prefix . 'services'), - 's.host_object_id = h.host_object_id', - array() - )->join( - array('so' => $this->prefix . 'objects'), - 'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1', - array() - )->joinLeft( - array('ss' => $this->prefix . 'servicestatus'), - 'so.' . $this->object_id . ' = ss.service_object_id', + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = ho.object_id', array() ); - foreach ($this->getColumns() as $col) { - $real = $this->aliasToColumnName($col); - if (substr($real, 0, 4) === 'SUM(') { - continue; - } - $this->select->group($real); - } - $this->useSubqueryCount = true; + return $this; } + /** + * Join host groups + * + * @return $this + */ protected function joinHostgroups() - { - if ($this->hasJoinedVirtualTable('services')) { - return $this->joinServiceHostgroups(); - } else { - return $this->joinHostHostgroups(); - } - } - - protected function joinServiceHostgroups() { $this->select->join( array('hgm' => $this->prefix . 'hostgroup_members'), - 'hgm.host_object_id = s.host_object_id', + 'hgm.host_object_id = ho.object_id', array() )->join( array('hg' => $this->prefix . 'hostgroups'), - 'hgm.hostgroup_id = hg.' . $this->hostgroup_id, + 'hg.hostgroup_id = hgm.hostgroup_id', array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.' . $this->object_id . ' = hg.hostgroup_object_id' - . ' AND hgo.is_active = 1', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); return $this; } - protected function joinHostHostgroups() + /** + * Join service problem summary + * + * @return $this + */ + protected function joinServiceproblemsummary() { - $this->select->join( - array('hgm' => $this->prefix . 'hostgroup_members'), - 'hgm.host_object_id = h.host_object_id', - array() - )->join( - array('hg' => $this->prefix . 'hostgroups'), - 'hgm.hostgroup_id = hg.' . $this->hostgroup_id, - array() - )->join( - array('hgo' => $this->prefix . 'objects'), - 'hgo.' . $this->object_id . ' = hg.hostgroup_object_id' . ' AND hgo.is_active = 1', - array() - ); - return $this; - } - - protected function joinContacts() - { - $this->hcgcSub = $this->db->select()->distinct()->from( - array('hcgc' => $this->prefix . 'host_contactgroups'), - array('host_name' => 'ho.name1') - )->join( - array('cgo' => $this->prefix . 'objects'), - 'hcg.contactgroup_object_id = cgo.' . $this->object_id . ' AND cgo.is_active = 1', - array() - )->join( - array('h' => $this->prefix . 'hosts'), - 'hcg.host_id = h.host_id', - array() - )->join( - array('ho' => $this->prefix . 'objects'), - 'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1', - array() - ); - $this->select->join( - array('hcg' => $this->hcgSub), - 'hcg.host_name = ho.name1', - array() - ); - - return $this; - } - - protected function filterContactgroup($value) - { - $this->hcgSub->where( - $this->prepareFilterStringForColumn( - 'cgo.name1 COLLATE latin1_general_ci', - $value - ) - ); - return $this; - } - - protected function joinContactgroups() - { - $this->hcgSub = $this->createContactgroupFilterSubselect(); - $this->select->join( - array('hcg' => $this->hcgSub), - 'hcg.object_id = ho.object_id', - array() - ); - return $this; - } - - protected function createContactgroupFilterSubselect() - { - die((string) $this->db->select()->distinct()->from( - array('hcg' => $this->prefix . 'host_contactgroups'), - array('object_id' => 'ho.object_id') - )->join( - array('cgo' => $this->prefix . 'objects'), - 'hcg.contactgroup_object_id = cgo.' . $this->object_id - . ' AND cgo.is_active = 1', - array() - )->join( - array('h' => $this->prefix . 'hosts'), - 'hcg.host_id = h.host_id', - array() - )->join( - array('ho' => $this->prefix . 'objects'), - 'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1', - array() - )); - } - - protected function joinServicegroups() - { - // TODO: Only hosts with services having such servicegroups - $this->requireVirtualTable('services'); - $this->select->join( - array('sgm' => $this->prefix . 'servicegroup_members'), - 'sgm.service_object_id = s.service_object_id', - array() - )->join( - array('sg' => $this->prefix . 'servicegroups'), - 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, - array() - )->join( - array('sgo' => $this->prefix . 'objects'), - 'sgo.' . $this->object_id . ' = sg.servicegroup_object_id' - . ' AND sgo.is_active = 1', + $select = <<<'SQL' +SELECT + SUM( + CASE WHEN(ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 + THEN 0 + ELSE 1 + END + ) AS unhandled_services_count, + SUM( + CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0) ) > 0 + THEN 1 + ELSE 0 + END + ) AS handled_services_count, + s.host_object_id +FROM + icinga_servicestatus ss + JOIN icinga_objects o ON o.object_id = ss.service_object_id + JOIN icinga_services s ON s.service_object_id = o.object_id + JOIN icinga_hoststatus hs ON hs.host_object_id = s.host_object_id +WHERE + o.is_active = 1 + AND o.objecttype_id = 2 + AND ss.current_state > 0 +GROUP BY + s.host_object_id +SQL; + $this->select->joinLeft( + array('sps' => new Zend_Db_Expr('(' . $select . ')')), + 'sps.host_object_id = ho.object_id', array() ); return $this; From c81d13d77a0f1bb2a6d146be6cee73840e65455c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 13:42:42 +0200 Subject: [PATCH 002/237] monitoring: Use the HostatusQuery in the HostStatus data view refs #7344 refs #9009 --- .../Monitoring/DataView/HostStatus.php | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index a7c77e2e2..90d58643a 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -6,17 +6,7 @@ namespace Icinga\Module\Monitoring\DataView; class HostStatus extends DataView { /** - * @see DataView::init() - */ - public function init() - { - $this->query->setMode('host'); - } - - /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} */ public function getColumns() { @@ -76,11 +66,6 @@ class HostStatus extends DataView ); } - public static function getQueryName() - { - return 'status'; - } - /** * The sort rules for this query * @@ -112,11 +97,17 @@ class HostStatus extends DataView ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { return array('host', 'hostgroup', 'hostgroup_name', 'service', 'servicegroup', 'servicegroup_name'); } + /** + * {@inheritdoc} + */ public function isValidFilterTarget($column) { if ($column[0] === '_' From e240f7b9550c9ed72b0d9840a140cc57180a8451 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 13:43:49 +0200 Subject: [PATCH 003/237] monitoring: Don't select host last ack, comment and downtime Where unsure whether or not we will still support this. refs #7344 refs #9009 --- .../monitoring/application/controllers/ListController.php | 6 +++--- .../monitoring/library/Monitoring/DataView/HostStatus.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 1c49e36d1..f771d3376 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -89,9 +89,9 @@ class Monitoring_ListController extends Controller 'host_unhandled_services', 'host_action_url', 'host_notes_url', - 'host_last_comment', - 'host_last_ack', - 'host_last_downtime', +// 'host_last_comment', +// 'host_last_ack', +// 'host_last_downtime', 'host_active_checks_enabled', 'host_passive_checks_enabled', 'host_current_check_attempt', diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index 90d58643a..40b6645e6 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -52,10 +52,10 @@ class HostStatus extends DataView 'host_current_notification_number', 'host_percent_state_change', 'host_is_flapping', - 'host_last_comment', - 'host_last_downtime', - 'host_last_ack', - 'host_last_flapping', +// 'host_last_comment', +// 'host_last_downtime', +// 'host_last_ack', +// 'host_last_flapping', 'host_action_url', 'host_notes_url', 'host_percent_state_change', From b24e3393f02675ecfa9828d60b976069a72d1a16 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 13:48:48 +0200 Subject: [PATCH 004/237] monitoring: Prohibit sorting the HostStatus data view by service columns refs #7344 refs #9009 --- .../Monitoring/DataView/HostStatus.php | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index 40b6645e6..45c0ee05e 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -5,6 +5,19 @@ namespace Icinga\Module\Monitoring\DataView; class HostStatus extends DataView { + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_host_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } + /** * {@inheritdoc} */ @@ -66,6 +79,22 @@ class HostStatus extends DataView ); } + /** + * {@inheritdoc} + */ + public function getFilterColumns() + { + return array('host', 'hostgroup', 'hostgroup_name'); + } + + /** + * {@inheritdoc} + */ + public function getSearchColumns() + { + return array('host', 'host_display_name'); + } + /** * The sort rules for this query * @@ -96,33 +125,4 @@ class HostStatus extends DataView ) ); } - - /** - * {@inheritdoc} - */ - public function getFilterColumns() - { - return array('host', 'hostgroup', 'hostgroup_name', 'service', 'servicegroup', 'servicegroup_name'); - } - - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_(?:host|service)_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - - /** - * {@inheritdoc} - */ - public function getSearchColumns() - { - return array('host', 'host_display_name'); - } } From b0576d93defeb1224e7ca2ebffea2c8c28a387a0 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 16:59:38 +0200 Subject: [PATCH 005/237] monitoring: Support selecting NULL as column refs #9009 --- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 9371399bc..9cd7eff08 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -3,14 +3,15 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; -use Icinga\Exception\IcingaException; +use Zend_Db_Expr; +use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Data\Db\DbQuery; -use Icinga\Exception\ProgrammingError; -use Icinga\Application\Icinga; -use Icinga\Web\Session; use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\FilterExpression; +use Icinga\Exception\IcingaException; +use Icinga\Exception\ProgrammingError; +use Icinga\Web\Session; /** * Base class for Ido Queries @@ -471,6 +472,11 @@ abstract class IdoQuery extends DbQuery $resolvedColumns = array(); foreach ($columns as $alias => $col) { + if ($col instanceof Zend_Db_Expr) { + // Support selecting NULL as column for example + $resolvedColumns[$alias] = $col; + continue; + } $this->requireColumn($col); if ($this->isCustomvar($col)) { $name = $this->getCustomvarColumnName($col); @@ -682,6 +688,14 @@ abstract class IdoQuery extends DbQuery return $this->idxAliasColumn[$alias]; } + /** + * Create a sub query + * + * @param string $queryName + * @param array $columns + * + * @return static + */ protected function createSubQuery($queryName, $columns = array()) { $class = '\\' From 18499a4a591b126bffc5be19041d2d1436f61811 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:02:13 +0200 Subject: [PATCH 006/237] monitoring: Support joining downtimes on the Hoststatus query refs #7344 refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 5095b401c..d5e9cefd7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -16,6 +16,27 @@ class HoststatusQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( + 'downtimes' => array( + 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', + 'downtime_author_name' => 'sd.author_name', + 'downtime_comment' => 'sd.comment_data', + 'downtime_duration' => 'sd.duration', + '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', + 'downtime_internal_id' => 'sd.internal_downtime_id', + 'downtime_is_fixed' => 'sd.is_fixed', + 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', + 'downtime_is_in_effect' => 'sd.is_in_effect', + 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', + 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', + 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', + 'downtime_triggered_by_id' => 'sd.triggered_by_id' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), 'hosts' => array( 'host' => 'ho.name1 COLLATE latin1_general_ci', 'host_action_url' => 'h.action_url', @@ -123,11 +144,6 @@ class HoststatusQuery extends IdoQuery 'host_status_update_time' => 'hs.status_update_time', 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ), - 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' - ), 'serviceproblemsummary' => array( 'host_unhandled_services' => 'sps.unhandled_services_count' ) @@ -143,31 +159,32 @@ class HoststatusQuery extends IdoQuery array() )->join( array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', + 'h.host_object_id = ho.object_id', array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 ); $this->joinedVirtualTables['hosts'] = true; } /** - * Join host status - * - * @return $this + * Join downtimes */ - protected function joinHoststatus() + protected function joinDowntimes() { $this->select->join( - array('hs' => $this->prefix . 'hoststatus'), - 'hs.host_object_id = ho.object_id', + array('sd' => $this->prefix . 'scheduleddowntime'), + 'sd.object_id = ho.object_id', array() ); - return $this; } /** * Join host groups - * - * @return $this */ protected function joinHostgroups() { @@ -181,16 +198,33 @@ class HoststatusQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->distinct(); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = ho.object_id', array() ); - return $this; } /** * Join service problem summary - * - * @return $this */ protected function joinServiceproblemsummary() { @@ -226,6 +260,5 @@ SQL; 'sps.host_object_id = ho.object_id', array() ); - return $this; } } From 788481e2b11ba4706353ce84c733535b5926cc51 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:02:41 +0200 Subject: [PATCH 007/237] monitoring: Add Servicestatus query refs #7344 refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 257 ++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php new file mode 100644 index 000000000..0e2c9c1c5 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -0,0 +1,257 @@ + array( + 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', + 'downtime_author_name' => 'sd.author_name', + 'downtime_comment' => 'sd.comment_data', + 'downtime_duration' => 'sd.duration', + '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', + 'downtime_internal_id' => 'sd.internal_downtime_id', + 'downtime_is_fixed' => 'sd.is_fixed', + 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', + 'downtime_is_in_effect' => 'sd.is_in_effect', + 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', + 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', + 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', + 'downtime_triggered_by_id' => 'sd.triggered_by_id' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_action_url' => 'h.action_url', + 'host_address' => 'h.address', + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + 'host_icon_image' => 'h.icon_image', + 'host_icon_image_alt' => 'h.icon_image_alt', + 'host_ipv4' => 'INET_ATON(h.address)', + 'host_name' => 'so.name1', + 'host_notes_url' => 'h.notes_url', + 'object_type' => '(\'host\')' + ), + 'hoststatus' => array( + 'host_acknowledged' => 'hs.problem_has_been_acknowledged', + 'host_acknowledgement_type' => 'hs.acknowledgement_type', + 'host_active_checks_enabled' => 'hs.active_checks_enabled', + 'host_active_checks_enabled_changed' => 'CASE WHEN hs.active_checks_enabled = h.active_checks_enabled THEN 0 ELSE 1 END', + 'host_attempt' => 'hs.current_check_attempt || \'/\' || hs.max_check_attempts', + 'host_check_command' => 'hs.check_command', + 'host_check_execution_time' => 'hs.execution_time', + 'host_check_latency' => 'hs.latency', + 'host_check_source' => 'hs.check_source', + 'host_check_type' => 'hs.check_type', + 'host_current_check_attempt' => 'hs.current_check_attempt', + 'host_current_notification_number' => 'hs.current_notification_number', + 'host_event_handler' => 'hs.event_handler', + 'host_event_handler_enabled' => 'hs.event_handler_enabled', + 'host_event_handler_enabled_changed' => 'CASE WHEN hs.event_handler_enabled = h.event_handler_enabled THEN 0 ELSE 1 END', + 'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled', + 'host_flap_detection_enabled' => 'hs.flap_detection_enabled', + 'host_flap_detection_enabled_changed' => 'CASE WHEN hs.flap_detection_enabled = h.flap_detection_enabled THEN 0 ELSE 1 END', + 'host_handled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', + 'host_hard_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END', + 'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', + 'host_is_flapping' => 'hs.is_flapping', + 'host_is_reachable' => 'hs.is_reachable', + 'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)', + 'host_last_hard_state' => 'hs.last_hard_state', + 'host_last_hard_state_change' => 'UNIX_TIMESTAMP(hs.last_hard_state_change)', + 'host_last_notification' => 'UNIX_TIMESTAMP(hs.last_notification)', + 'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)', + 'host_last_time_down' => 'UNIX_TIMESTAMP(hs.last_time_down)', + 'host_last_time_unreachable' => 'UNIX_TIMESTAMP(hs.last_time_unreachable)', + 'host_last_time_up' => 'UNIX_TIMESTAMP(hs.last_time_up)', + 'host_long_output' => 'hs.long_output', + 'host_max_check_attempts' => 'hs.max_check_attempts', + 'host_modified_host_attributes' => 'hs.modified_host_attributes', + 'host_next_check' => 'CASE hs.should_be_scheduled WHEN 1 THEN UNIX_TIMESTAMP(hs.next_check) ELSE NULL END', + 'host_next_notification' => 'UNIX_TIMESTAMP(hs.next_notification)', + 'host_no_more_notifications' => 'hs.no_more_notifications', + 'host_normal_check_interval' => 'hs.normal_check_interval', + 'host_notifications_enabled' => 'hs.notifications_enabled', + 'host_notifications_enabled_changed' => 'CASE WHEN hs.notifications_enabled = h.notifications_enabled THEN 0 ELSE 1 END', + 'host_obsessing' => 'hs.obsess_over_host', + 'host_obsessing_changed' => 'CASE WHEN hs.obsess_over_host = h.obsess_over_host THEN 0 ELSE 1 END', + 'host_output' => 'hs.output', + 'host_passive_checks_enabled' => 'hs.passive_checks_enabled', + 'host_passive_checks_enabled_changed' => 'CASE WHEN hs.passive_checks_enabled = h.passive_checks_enabled THEN 0 ELSE 1 END', + 'host_percent_state_change' => 'hs.percent_state_change', + 'host_perfdata' => 'hs.perfdata', + 'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END', + 'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged', + 'host_process_performance_data' => 'hs.process_performance_data', + 'host_retry_check_interval' => 'hs.retry_check_interval', + 'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth', + 'host_severity' => 'CASE WHEN hs.current_state = 0 + THEN + CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL + THEN 16 + ELSE 0 + END + + + CASE WHEN hs.problem_has_been_acknowledged = 1 + THEN 2 + ELSE + CASE WHEN hs.scheduled_downtime_depth > 0 + THEN 1 + ELSE 4 + END + END + ELSE + CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 16 + WHEN hs.current_state = 1 THEN 32 + WHEN hs.current_state = 2 THEN 64 + ELSE 256 + END + + + CASE WHEN hs.problem_has_been_acknowledged = 1 + THEN 2 + ELSE + CASE WHEN hs.scheduled_downtime_depth > 0 + THEN 1 + ELSE 4 + END + END + END + + + CASE WHEN hs.state_type = 1 + THEN 8 + ELSE 0 + END', + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', + 'host_state_type' => 'hs.state_type', + 'host_status_update_time' => 'hs.status_update_time', + 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' + ), + 'services' => array( + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_action_url' => 's.action_url', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1', + 'service_icon_image' => 's.icon_image', + 'service_icon_image_alt' => 's.icon_image_alt', + 'service_notes_url' => 's.notes_url' + ), + 'servicestatus' => array( + 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('so' => $this->prefix . 'objects'), + array() + )->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + $this->joinedVirtualTables['services'] = true; + } + + /** + * Join downtimes + */ + protected function joinDowntimes() + { + $this->select->join( + array('sd' => $this->prefix . 'scheduleddowntime'), + 'sd.object_id = so.object_id', + array() + ); + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + )->where( + 'hgo.objecttype_id = ?', + 3 + ); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service status + */ + protected function joinServicestatus() + { + $this->select->join( + array('ss' => $this->prefix . 'servicestatus'), + 'ss.service_object_id = so.object_id', + array() + ); + } +} From bb9b9bc7547ce1e98c45624a9abc68decd67c317 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:05:47 +0200 Subject: [PATCH 008/237] monitoring: Apply host and service restrictions to downtimes refs #9009 refs #9319 --- .../Backend/Ido/Query/DowntimeQuery.php | 211 ++++++++++-------- 1 file changed, 122 insertions(+), 89 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index a3e66cbaf..b08944e77 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -3,6 +3,11 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Authentication\Manager; +use Icinga\Data\Filter\Filter; + /** * Query for host and service downtimes */ @@ -12,127 +17,155 @@ class DowntimeQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( - 'downtime' => array( - 'downtime_author_name' => 'sd.author_name', - 'author' => 'sd.author_name COLLATE latin1_general_ci', - '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_objecttype' => "CASE WHEN ho.object_id IS NULL THEN 'service' ELSE 'host' END", - 'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', - 'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END', - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_description' => 'so.name2', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', - 'service_host_name' => 'so.name1' + 'downtimes' => array( + 'downtime_author' => 'd.downtime_author', + 'downtime_author_name' => 'd.downtime_author_name', + 'downtime_comment' => 'd.downtime_comment', + 'downtime_duration' => 'd.downtime_duration', + 'downtime_end' => 'd.downtime_end', + 'downtime_entry_time' => 'd.downtime_entry_time', + 'downtime_internal_id' => 'd.downtime_internal_id', + 'downtime_is_fixed' => 'd.downtime_is_fixed', + 'downtime_is_flexible' => 'd.downtime_is_flexible', + 'downtime_is_in_effect' => 'd.downtime_is_in_effect', + 'downtime_scheduled_end' => 'd.downtime_scheduled_end', + 'downtime_scheduled_start' => 'd.downtime_scheduled_start', + 'downtime_start' => 'd.downtime_start', + 'object_type' => 'd.object_type' ), 'hosts' => array( - 'host_display_name' => 'CASE WHEN h.display_name IS NULL THEN sh.display_name ELSE h.display_name END' - ), - 'hoststatus' => array( - 'downtime_host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + 'host_display_name' => 'd.host_display_name', + 'host_name' => 'd.host_name', + 'host_state' => 'd.host_state' ), 'services' => array( - 'service_display_name' => 's.display_name' - ), - 'servicestatus' => array( - 'downtime_service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + 'service_description' => 'd.service_description', + 'service_display_name' => 'd.service_display_name', + 'service_host_name' => 'd.service_host_name', + 'service_state' => 'd.service_state' ) ); + /** + * The union + * + * @var Zend_Db_Select + */ + protected $downtimeQuery; + + /** + * Subqueries used for the downtime query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } + + /** + * Apply host restrictions to a query + * + * @param IdoQuery $query + */ + protected function applyHostRestrictions(IdoQuery $query) + { + $hostRestrictions = Filter::matchAny(); + foreach (Manager::getInstance()->getRestrictions('monitoring/hosts/filter') as $restriction) { + $hostRestrictions->addFilter(Filter::fromQueryString($restriction)); + } + $query->addFilter($hostRestrictions); + } + + /** + * Apply host and service restrictions to a query + * + * @param IdoQuery $query + */ + protected function applyServiceRestrictions(IdoQuery $query) + { + $hostAndServiceRestrictions = Filter::matchAll(); + $hostRestrictions = Filter::matchAny(); + $serviceRestrictions = Filter::matchAny(); + foreach (Manager::getInstance()->getRestrictions('monitoring/hosts/filter') as $restriction) { + $hostRestrictions->addFilter(Filter::fromQueryString($restriction)); + } + foreach (Manager::getInstance()->getRestrictions('monitoring/services/filter') as $restriction) { + $serviceRestrictions->addFilter(Filter::fromQueryString($restriction)); + } + $hostAndServiceRestrictions->addFilter($hostRestrictions); + $hostAndServiceRestrictions->addFilter($serviceRestrictions); + $query->addFilter($hostAndServiceRestrictions); + } + /** * {@inheritdoc} */ protected function joinBaseTables() { + $this->downtimeQuery = $this->db->select(); $this->select->from( - array('sd' => $this->prefix . 'scheduleddowntime'), + array('d' => $this->downtimeQuery), array() ); - $this->select->joinLeft( - array('ho' => $this->prefix . 'objects'), - 'sd.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', - array() - ); - $this->select->joinLeft( - array('so' => $this->prefix . 'objects'), - 'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2', - array() - ); - $this->joinedVirtualTables = array('downtime' => true); + $this->joinedVirtualTables['downtimes'] = true; } /** - * Join downtimes' hosts - * - * @return $this + * Join hosts */ protected function joinHosts() { - $this->select->joinLeft( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = ho.object_id', - array() - ); - return $this; + $columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts']); + foreach (array_keys($this->columnMap['services']) as $column) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + $hosts = $this->createSubQuery('hoststatus', $columns); + $this->applyHostRestrictions($hosts); + $this->subQueries[] = $hosts; + $this->downtimeQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); } /** - * Join downtimes' hosts' status - * - * @return $this - */ - protected function joinHoststatus() - { - $this->select->joinLeft( - array('hs' => $this->prefix . 'hoststatus'), - 'ho.object_id = hs.host_object_id', - array() - ); - return $this; - } - - /** - * Join downtimes' services - * - * @return $this + * Join services */ 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; + $columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts'] + $this->columnMap['services']); + $services = $this->createSubQuery('servicestatus', $columns); + $this->applyServiceRestrictions($services); + $this->subQueries[] = $services; + $this->downtimeQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); } /** - * Join downtimes' services' status - * - * @return $this + * {@inheritdoc} */ - protected function joinServicestatus() + public function order($columnOrAlias, $dir = null) { - $this->select->joinLeft( - array('ss' => $this->prefix . 'servicestatus'), - 'so.object_id = ss.service_object_id', - array() - ); + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } return $this; } } From cd1ee3e306f83c3ae9181d5a9fe2f866591736a8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:07:58 +0200 Subject: [PATCH 009/237] monitoring: Fix select columns for downtimes refs #9009 refs #9319 --- .../monitoring/application/controllers/ListController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index f771d3376..197bf5b69 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -229,7 +229,7 @@ class Monitoring_ListController extends Controller $query = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', - 'objecttype' => 'downtime_objecttype', + 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', @@ -241,8 +241,8 @@ class Monitoring_ListController extends Controller 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', - 'host_state' => 'downtime_host_state', - 'service_state' => 'downtime_service_state', + 'host_state', + 'service_state', 'host_name', 'service_description', 'host_display_name', From 61565543ab675356b5beb0de7aec5d02addcd71a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:10:23 +0200 Subject: [PATCH 010/237] monitoring: Fix downtime filter columns refs #9009 refs #9319 --- .../library/Monitoring/DataView/Downtime.php | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php index 4eaab1860..366e80d78 100644 --- a/modules/monitoring/library/Monitoring/DataView/Downtime.php +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -6,9 +6,20 @@ namespace Icinga\Module\Monitoring\DataView; class Downtime extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } + + /** + * {@inheritdoc} */ public function getColumns() { @@ -37,6 +48,17 @@ class Downtime extends DataView ); } + /** + * {@inheritdoc} + */ + public function getFilterColumns() + { + return array('hostgroup', 'hostgroup_alias', 'hostgroup_name', 'servicegroup', 'servicegroup_alias', 'servicegroup_name'); + } + + /** + * {@inheritdoc} + */ public function getSortRules() { return array( @@ -66,9 +88,4 @@ class Downtime extends DataView ) ); } - - public function getFilterColumns() - { - return array('author', 'host', 'service', 'service_host'); - } } From 0c1df335fcee05ac1609a38d52b5cd27a7a924cd Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 26 May 2015 17:15:03 +0200 Subject: [PATCH 011/237] monitoring: Fix select columns for downtimes, again refs #9009 refs #9319 --- .../controllers/DowntimeController.php | 12 +++++------- .../controllers/DowntimesController.php | 16 +++++++--------- .../Monitoring/Object/MonitoredObject.php | 4 ++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimeController.php b/modules/monitoring/application/controllers/DowntimeController.php index 67b8b6a33..49bcd9529 100644 --- a/modules/monitoring/application/controllers/DowntimeController.php +++ b/modules/monitoring/application/controllers/DowntimeController.php @@ -37,7 +37,7 @@ class Monitoring_DowntimeController extends Controller $this->downtime = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', - 'objecttype' => 'downtime_objecttype', + 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', @@ -49,11 +49,9 @@ class Monitoring_DowntimeController extends Controller 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', - 'host_state' => 'downtime_host_state', - 'service_state' => 'downtime_service_state', + 'host_state', + 'service_state', 'host_name', - 'host', - 'service', 'service_description', 'host_display_name', 'service_display_name' @@ -95,9 +93,9 @@ class Monitoring_DowntimeController extends Controller Host::getStateText($this->downtime->host_state); $this->view->listAllLink = Url::fromPath('monitoring/list/downtimes'); $this->view->showHostLink = Url::fromPath('monitoring/host/show') - ->setParam('host', $this->downtime->host); + ->setParam('host', $this->downtime->host_name); $this->view->showServiceLink = Url::fromPath('monitoring/service/show') - ->setParam('host', $this->downtime->host) + ->setParam('host', $this->downtime->host_name) ->setParam('service', $this->downtime->service_description); if ($this->hasPermission('monitoring/command/downtime/delete')) { $this->view->delDowntimeForm = $this->createDelDowntimeForm(); diff --git a/modules/monitoring/application/controllers/DowntimesController.php b/modules/monitoring/application/controllers/DowntimesController.php index 4ba872bbd..a1d210cc8 100644 --- a/modules/monitoring/application/controllers/DowntimesController.php +++ b/modules/monitoring/application/controllers/DowntimesController.php @@ -41,7 +41,7 @@ class Monitoring_DowntimesController extends Controller )); $this->downtimes = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', - 'objecttype' => 'downtime_objecttype', + 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', @@ -53,11 +53,9 @@ class Monitoring_DowntimesController extends Controller 'is_fixed' => 'downtime_is_fixed', 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time', - 'host_state' => 'downtime_host_state', - 'service_state' => 'downtime_service_state', + 'host_state', + 'service_state', 'host_name', - 'host', - 'service', 'service_description', 'host_display_name', 'service_display_name' @@ -68,7 +66,7 @@ class Monitoring_DowntimesController extends Controller $this->translate('Downtime not found') ); } - + $this->getTabs()->add( 'downtimes', array( @@ -80,14 +78,14 @@ class Monitoring_DowntimesController extends Controller 'url' =>'monitoring/downtimes/show' ) )->activate('downtimes'); - + foreach ($this->downtimes as $downtime) { if (isset($downtime->service_description)) { $downtime->isService = true; } else { $downtime->isService = false; } - + if ($downtime->isService) { $downtime->stateText = Service::getStateText($downtime->service_state); } else { @@ -127,4 +125,4 @@ class Monitoring_DowntimesController extends Controller $delDowntimeForm->setDowntimes($this->downtimes)->handleRequest(); $this->view->delDowntimeForm = $delDowntimeForm; } -} \ No newline at end of file +} diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 05f201428..fdf64fc51 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -274,7 +274,7 @@ abstract class MonitoredObject implements Filterable { $downtimes = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', - 'objecttype' => 'downtime_objecttype', + 'objecttype' => 'object_type', 'comment' => 'downtime_comment', 'author_name' => 'downtime_author_name', 'start' => 'downtime_start', @@ -286,7 +286,7 @@ abstract class MonitoredObject implements Filterable 'is_in_effect' => 'downtime_is_in_effect', 'entry_time' => 'downtime_entry_time' )) - ->where('downtime_objecttype', $this->type) + ->where('object_type', $this->type) ->order('downtime_is_in_effect', 'DESC') ->order('downtime_scheduled_start', 'ASC'); if ($this->type === self::TYPE_SERVICE) { From 41be32adff19bc578731a1d4692a3f7657d850c3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:23:47 +0200 Subject: [PATCH 012/237] monitoring: Provide only the monitoring/filter/objects restriction We'll combine the hosts and services filter restrictions into a single restriction. refs #9009 --- modules/monitoring/configuration.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index fd3ee334d..e548a36e5 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -61,13 +61,8 @@ $this->providePermission( ); $this->provideRestriction( - 'monitoring/hosts/filter', - $this->translate('Restrict hosts view to the hosts that match the filter') -); - -$this->provideRestriction( - 'monitoring/services/filter', - $this->translate('Restrict services view to the services that match the filter') + 'monitoring/filter/objects', + $this->translate('Restrict views to the Icinga objects that match the filter') ); $this->provideConfigTab('backends', array( From 7793b61e4cfd5e341e8d0c88b5e0612101ea2c7d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:40:26 +0200 Subject: [PATCH 013/237] monitoring: Combine restrictions w/ OR If a user has more than one filter for the same restriction, the filters will be combined w/ or. The combined filters will then be applied w/ AND to the query. refs #9009 --- modules/monitoring/library/Monitoring/Controller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Controller.php b/modules/monitoring/library/Monitoring/Controller.php index c3cbe3c2d..b6b65fc0c 100644 --- a/modules/monitoring/library/Monitoring/Controller.php +++ b/modules/monitoring/library/Monitoring/Controller.php @@ -58,9 +58,11 @@ class Controller extends IcingaWebController */ protected function applyRestriction($restriction, Filterable $view) { + $restrictions = Filter::matchAny(); foreach ($this->getRestrictions($restriction) as $filter) { - $view->applyFilter(Filter::fromQueryString($filter)); + $restrictions->addFilter(Filter::fromQueryString($filter)); } + $view->applyFilter($restrictions); return $view; } } From 4544653c2e922fc087b4ccecfc941abdacf9880b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:41:39 +0200 Subject: [PATCH 014/237] monitoring: Don't apply restrictions in the downtime query Restrictions should be applied from the controller. refs #9009 --- .../Backend/Ido/Query/DowntimeQuery.php | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index b08944e77..67be1929b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -71,41 +71,6 @@ class DowntimeQuery extends IdoQuery return $this; } - /** - * Apply host restrictions to a query - * - * @param IdoQuery $query - */ - protected function applyHostRestrictions(IdoQuery $query) - { - $hostRestrictions = Filter::matchAny(); - foreach (Manager::getInstance()->getRestrictions('monitoring/hosts/filter') as $restriction) { - $hostRestrictions->addFilter(Filter::fromQueryString($restriction)); - } - $query->addFilter($hostRestrictions); - } - - /** - * Apply host and service restrictions to a query - * - * @param IdoQuery $query - */ - protected function applyServiceRestrictions(IdoQuery $query) - { - $hostAndServiceRestrictions = Filter::matchAll(); - $hostRestrictions = Filter::matchAny(); - $serviceRestrictions = Filter::matchAny(); - foreach (Manager::getInstance()->getRestrictions('monitoring/hosts/filter') as $restriction) { - $hostRestrictions->addFilter(Filter::fromQueryString($restriction)); - } - foreach (Manager::getInstance()->getRestrictions('monitoring/services/filter') as $restriction) { - $serviceRestrictions->addFilter(Filter::fromQueryString($restriction)); - } - $hostAndServiceRestrictions->addFilter($hostRestrictions); - $hostAndServiceRestrictions->addFilter($serviceRestrictions); - $query->addFilter($hostAndServiceRestrictions); - } - /** * {@inheritdoc} */ @@ -129,7 +94,6 @@ class DowntimeQuery extends IdoQuery $columns[$column] = new Zend_Db_Expr('NULL'); } $hosts = $this->createSubQuery('hoststatus', $columns); - $this->applyHostRestrictions($hosts); $this->subQueries[] = $hosts; $this->downtimeQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); } @@ -141,7 +105,6 @@ class DowntimeQuery extends IdoQuery { $columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts'] + $this->columnMap['services']); $services = $this->createSubQuery('servicestatus', $columns); - $this->applyServiceRestrictions($services); $this->subQueries[] = $services; $this->downtimeQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); } From c17334deeeb6196c7f6cefa3746baef854cf8a0e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:42:05 +0200 Subject: [PATCH 015/237] monitoring: Support restricting the downtimes overview refs #9009 --- modules/monitoring/application/controllers/ListController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 197bf5b69..816aeb153 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -249,6 +249,9 @@ class Monitoring_ListController extends Controller 'service_display_name' )); $this->filterQuery($query); + + $this->applyRestriction('monitoring/filter/objects', $query); + $this->view->downtimes = $query; $this->setupLimitControl(); From b1446fcb232d55d26fe1034432e3dc9b2b117ad4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:43:41 +0200 Subject: [PATCH 016/237] monitoring: Allow the hoststatus query to be filtered by restrictable columns refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 71 +++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index d5e9cefd7..3c0ee9688 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -144,8 +144,18 @@ class HoststatusQuery extends IdoQuery 'host_status_update_time' => 'hs.status_update_time', 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), 'serviceproblemsummary' => array( 'host_unhandled_services' => 'sps.unhandled_services_count' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', ) ); @@ -204,10 +214,10 @@ class HoststatusQuery extends IdoQuery 'hgo.is_active = ?', 1 ) - ->where( - 'hgo.objecttype_id = ?', - 3 - ); + ->where( + 'hgo.objecttype_id = ?', + 3 + ); $this->distinct(); } @@ -223,6 +233,59 @@ class HoststatusQuery extends IdoQuery ); } + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = h.host_object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id AND so.is_active = 1', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->distinct(); + } + /** * Join service problem summary */ From 3a69e8185fd3bf3c875a5037ce9e223d406e917b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 11:44:34 +0200 Subject: [PATCH 017/237] monitoring: Add restrictable filter columns to the downtime data view refs #9009 --- .../library/Monitoring/DataView/Downtime.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php index 366e80d78..3664bf95b 100644 --- a/modules/monitoring/library/Monitoring/DataView/Downtime.php +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -24,27 +24,25 @@ class Downtime extends DataView public function getColumns() { return array( - 'downtime_objecttype', + 'downtime_author', 'downtime_author_name', 'downtime_comment', + 'downtime_duration', + 'downtime_end', 'downtime_entry_time', + 'downtime_internal_id', 'downtime_is_fixed', 'downtime_is_flexible', - 'downtime_start', - 'downtime_scheduled_start', - 'downtime_scheduled_end', - 'downtime_end', - 'downtime_duration', 'downtime_is_in_effect', - 'downtime_triggered_by_id', - 'downtime_internal_id', - 'downtime_host_state', - 'downtime_service_state', + 'downtime_scheduled_end', + 'downtime_scheduled_start', + 'downtime_start', 'host_display_name', - 'service_display_name', 'host_name', - 'service_host_name', - 'service_description' + 'object_type', + 'service_description', + 'service_display_name', + 'service_host_name' ); } @@ -53,7 +51,10 @@ class Downtime extends DataView */ public function getFilterColumns() { - return array('hostgroup', 'hostgroup_alias', 'hostgroup_name', 'servicegroup', 'servicegroup_alias', 'servicegroup_name'); + return array( + 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } /** From 3e53426ecefe5032957122e86b0d866c030a4e0e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:10:20 +0200 Subject: [PATCH 018/237] monitoring: Add query for host downtimes refs #9009 --- .../Backend/Ido/Query/HostdowntimeQuery.php | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php new file mode 100644 index 000000000..7d123132d --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -0,0 +1,189 @@ + array( + 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', + 'downtime_author_name' => 'sd.author_name', + 'downtime_comment' => 'sd.comment_data', + 'downtime_duration' => 'sd.duration', + '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', + 'downtime_internal_id' => 'sd.internal_downtime_id', + 'downtime_is_fixed' => 'sd.is_fixed', + 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', + 'downtime_is_in_effect' => 'sd.is_in_effect', + 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', + 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', + 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', + 'downtime_triggered_by_id' => 'sd.triggered_by_id', + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'hoststatus' => array( + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sd' => $this->prefix . 'scheduleddowntime'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'sd.object_id = ho.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->joinedVirtualTables['downtimes'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->distinct(); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = h.host_object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id AND so.is_active = 1', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->distinct(); + } +} From 22a83b738884f100e5f6bf67d29b62f1ff8f52fd Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:11:32 +0200 Subject: [PATCH 019/237] monitoring: Add data view for host downtimes refs #9009 --- .../Monitoring/DataView/Hostdowntime.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostdowntime.php diff --git a/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php b/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php new file mode 100644 index 000000000..f95f82da2 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php @@ -0,0 +1,59 @@ + Date: Fri, 29 May 2015 13:11:48 +0200 Subject: [PATCH 020/237] monitoring: Add query for service downtimes refs #9009 --- .../Ido/Query/ServicedowntimeQuery.php | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php new file mode 100644 index 000000000..67f21c67c --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -0,0 +1,195 @@ + array( + 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', + 'downtime_author_name' => 'sd.author_name', + 'downtime_comment' => 'sd.comment_data', + 'downtime_duration' => 'sd.duration', + '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', + 'downtime_internal_id' => 'sd.internal_downtime_id', + 'downtime_is_fixed' => 'sd.is_fixed', + 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', + 'downtime_is_in_effect' => 'sd.is_in_effect', + 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', + 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', + 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', + 'downtime_triggered_by_id' => 'sd.triggered_by_id', + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'hoststatus' => array( + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ), + 'servicestatus' => array( + 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sd' => $this->prefix . 'scheduleddowntime'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'sd.object_id = so.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = 2', + 1 + ); + $this->joinedVirtualTables['downtimes'] = true; + } + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->distinct(); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } + + /** + * Join service status + */ + protected function joinServicestatus() + { + $this->select->join( + array('ss' => $this->prefix . 'servicestatus'), + 'ss.service_object_id = so.object_id', + array() + ); + } +} From b833a04110927f59b464f61699d2dd65f650c863 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:12:03 +0200 Subject: [PATCH 021/237] monitoring: Add data view for service downtimes refs #9009 --- .../Monitoring/DataView/Servicedowntime.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicedowntime.php diff --git a/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php b/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php new file mode 100644 index 000000000..1969aec44 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php @@ -0,0 +1,59 @@ + Date: Fri, 29 May 2015 13:12:34 +0200 Subject: [PATCH 022/237] monitoring: Use host and service downtime query in the downtime query refs #9009 --- .../library/Monitoring/Backend/Ido/Query/DowntimeQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index 67be1929b..3ff4a9a24 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -93,7 +93,7 @@ class DowntimeQuery extends IdoQuery foreach (array_keys($this->columnMap['services']) as $column) { $columns[$column] = new Zend_Db_Expr('NULL'); } - $hosts = $this->createSubQuery('hoststatus', $columns); + $hosts = $this->createSubQuery('hostdowntime', $columns); $this->subQueries[] = $hosts; $this->downtimeQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); } @@ -104,7 +104,7 @@ class DowntimeQuery extends IdoQuery protected function joinServices() { $columns = array_keys($this->columnMap['downtimes'] + $this->columnMap['hosts'] + $this->columnMap['services']); - $services = $this->createSubQuery('servicestatus', $columns); + $services = $this->createSubQuery('servicedowntime', $columns); $this->subQueries[] = $services; $this->downtimeQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); } From ba07077ca834d926b5a091c86a1af595ca9c0dc0 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:13:28 +0200 Subject: [PATCH 023/237] monitoring: Don't join downtimes in the hoststatus query refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 3c0ee9688..ca8ae8b56 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -16,22 +16,6 @@ class HoststatusQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( - 'downtimes' => array( - 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', - 'downtime_author_name' => 'sd.author_name', - 'downtime_comment' => 'sd.comment_data', - 'downtime_duration' => 'sd.duration', - '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', - 'downtime_internal_id' => 'sd.internal_downtime_id', - 'downtime_is_fixed' => 'sd.is_fixed', - 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', - 'downtime_is_in_effect' => 'sd.is_in_effect', - 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', - 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', - 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', - 'downtime_triggered_by_id' => 'sd.triggered_by_id' - ), 'hostgroups' => array( 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', @@ -181,18 +165,6 @@ class HoststatusQuery extends IdoQuery $this->joinedVirtualTables['hosts'] = true; } - /** - * Join downtimes - */ - protected function joinDowntimes() - { - $this->select->join( - array('sd' => $this->prefix . 'scheduleddowntime'), - 'sd.object_id = ho.object_id', - array() - ); - } - /** * Join host groups */ From e71682ffb3a889adec661f69a5dcb903778820c2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:20:01 +0200 Subject: [PATCH 024/237] monitoring: Don't join downtimes in the servicestatus query refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 0e2c9c1c5..990e5a9b2 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -14,22 +14,6 @@ class ServicestatusQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( - 'downtimes' => array( - 'downtime_author' => 'sd.author_name COLLATE latin1_general_ci', - 'downtime_author_name' => 'sd.author_name', - 'downtime_comment' => 'sd.comment_data', - 'downtime_duration' => 'sd.duration', - '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_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', - 'downtime_internal_id' => 'sd.internal_downtime_id', - 'downtime_is_fixed' => 'sd.is_fixed', - 'downtime_is_flexible' => 'CASE WHEN sd.is_fixed = 0 THEN 1 ELSE 0 END', - 'downtime_is_in_effect' => 'sd.is_in_effect', - 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', - 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', - 'downtime_start' => 'UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)', - 'downtime_triggered_by_id' => 'sd.triggered_by_id' - ), 'hostgroups' => array( 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', @@ -181,18 +165,6 @@ class ServicestatusQuery extends IdoQuery $this->joinedVirtualTables['services'] = true; } - /** - * Join downtimes - */ - protected function joinDowntimes() - { - $this->select->join( - array('sd' => $this->prefix . 'scheduleddowntime'), - 'sd.object_id = so.object_id', - array() - ); - } - /** * Join host groups */ From a93ef04d5db0b1c1c909c073e0f67e3db88151f5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 13:30:02 +0200 Subject: [PATCH 025/237] Revert "Add new tab to switch between host and service multi-selection" This reverts commit 45a0982bebb411ed8a202696965c1438b5948c2c. Conflicts: modules/monitoring/application/controllers/HostsController.php modules/monitoring/application/controllers/ServicesController.php The tab was removed w/ another commit I guess. This revert removes the related not yet removed crap. --- .../application/controllers/HostsController.php | 10 ++-------- .../application/controllers/ServicesController.php | 1 - 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index 20ae71e6b..253a1fb74 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -26,14 +26,9 @@ class Monitoring_HostsController extends Controller public function init() { - // Support switching from service-view using the host and service selection. The filter would error - // on any occurrence of a filter based on service. - $filterString = preg_replace('/(service=[^)&]*)/', '', (string)$this->params); - $hostList = new HostList($this->backend); - $hostList->setFilter(Filter::fromQueryString((string) $this->params->without('view'))); + $hostList->setFilter(Filter::fromQueryString((string) $this->params)); $this->hostList = $hostList; - $this->getTabs()->add( 'show', array( @@ -46,8 +41,7 @@ class Monitoring_HostsController extends Controller 'icon' => 'host' ) )->extend(new DashboardAction())->activate('show'); - - $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts')->setQueryString($filterString); + $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts'); } protected function handleCommandForm(ObjectsCommandForm $form) diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 1a8ec9a58..8381a640d 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -32,7 +32,6 @@ class Monitoring_ServicesController extends Controller )); $this->serviceList = $serviceList; $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services'); - $this->getTabs()->add( 'show', array( From 07299730452e49d4de7bac38c3b0976fd35c5d85 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:07:06 +0200 Subject: [PATCH 026/237] monitoring: Add last *comment columns to the host status queries --- .../Backend/Ido/Query/HoststatusQuery.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index ca8ae8b56..e630727d4 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -128,6 +128,18 @@ class HoststatusQuery extends IdoQuery 'host_status_update_time' => 'hs.status_update_time', 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ), + 'lasthostackcomment' => array( + 'host_last_ack' => 'hlac.last_ack_data' + ), + 'lasthostcomment' => array( + 'host_last_comment' => 'hlc.last_comment_data' + ), + 'lasthostdowntimecomment' => array( + 'host_last_downtime' => 'hldc.last_downtime_data' + ), + 'lasthostflappingcomment' => array( + 'host_last_flapping' => 'hlfc.last_flapping_data' + ), 'servicegroups' => array( 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', 'servicegroup_name' => 'sgo.name1', @@ -143,6 +155,37 @@ class HoststatusQuery extends IdoQuery ) ); + /** + * Create a sub query to join comments into status query + * + * @param int $entryType + * @param string $alias + * + * @return Zend_Db_Expr + */ + protected function createLastCommentSubQuery($entryType, $alias) + { + $sql = <<select->joinLeft( + array('hlac' => $this->createLastCommentSubQuery(4, 'last_ack_data')), + 'hlac.object_id = ho.object_id', + array() + ); + } + + /** + * Join last host comment + */ + protected function joinLasthostcomment() + { + $this->select->joinLeft( + array('hlc' => $this->createLastCommentSubQuery(1, 'last_comment_data')), + 'hlc.object_id = ho.object_id', + array() + ); + } + + /** + * Join last host downtime comment + */ + protected function joinLasthostdowntimeComment() + { + $this->select->joinLeft( + array('hldc' => $this->createLastCommentSubQuery(2, 'last_downtime_data')), + 'hldc.object_id = ho.object_id', + array() + ); + } + + /** + * Join last host flapping comment + */ + protected function joinLasthostflappingcomment() + { + $this->select->joinLeft( + array('hlfc' => $this->createLastCommentSubQuery(3, 'last_flapping_data')), + 'hlfc.object_id = ho.object_id', + array() + ); + } + /** * Join service groups */ From 2cbadbf957d6bc7a887ef90e979c0f6ee58f2162 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:09:21 +0200 Subject: [PATCH 027/237] Revert "monitoring: Don't select host last ack, comment and downtime" This reverts commit e240f7b9550c9ed72b0d9840a140cc57180a8451. refs #7344 refs #9009 --- .../monitoring/application/controllers/ListController.php | 6 +++--- .../monitoring/library/Monitoring/DataView/HostStatus.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 816aeb153..2e4e34390 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -89,9 +89,9 @@ class Monitoring_ListController extends Controller 'host_unhandled_services', 'host_action_url', 'host_notes_url', -// 'host_last_comment', -// 'host_last_ack', -// 'host_last_downtime', + 'host_last_comment', + 'host_last_ack', + 'host_last_downtime', 'host_active_checks_enabled', 'host_passive_checks_enabled', 'host_current_check_attempt', diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index 45c0ee05e..cb992752a 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -65,10 +65,10 @@ class HostStatus extends DataView 'host_current_notification_number', 'host_percent_state_change', 'host_is_flapping', -// 'host_last_comment', -// 'host_last_downtime', -// 'host_last_ack', -// 'host_last_flapping', + 'host_last_comment', + 'host_last_downtime', + 'host_last_ack', + 'host_last_flapping', 'host_action_url', 'host_notes_url', 'host_percent_state_change', From f1bb0640209178ee88b831bc14c596147c92614b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:10:00 +0200 Subject: [PATCH 028/237] monitoring: Use the Servicedowntime data view in the ServiceList refs #9009 --- .../library/Monitoring/Object/ServiceList.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/ServiceList.php b/modules/monitoring/library/Monitoring/Object/ServiceList.php index 5ae9b8193..b06cffc89 100644 --- a/modules/monitoring/library/Monitoring/Object/ServiceList.php +++ b/modules/monitoring/library/Monitoring/Object/ServiceList.php @@ -138,13 +138,13 @@ class ServiceList extends ObjectList /** * Get the scheduled downtimes * - * @return type + * @return \Icinga\Module\Monitoring\DataView\Servicedowntime */ public function getScheduledDowntimes() { - return $this->backend->select() - ->from('downtime') - ->applyFilter(clone $this->filter) - ->where('downtime_objecttype', 'service'); + return $this->backend + ->select() + ->from('servicedowntime', array('host_name', 'service_description')) + ->applyFilter(clone $this->filter); } } From bb97269c55cf7b3ae4564ffef7ccb3c6fcb5ea9b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:10:14 +0200 Subject: [PATCH 029/237] monitoring: Use the Hostdowntime data view in the HostList refs #9009 --- .../monitoring/library/Monitoring/Object/HostList.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/HostList.php b/modules/monitoring/library/Monitoring/Object/HostList.php index 2aa5bb04f..31f360d03 100644 --- a/modules/monitoring/library/Monitoring/Object/HostList.php +++ b/modules/monitoring/library/Monitoring/Object/HostList.php @@ -90,13 +90,13 @@ class HostList extends ObjectList /** * Get the scheduled downtimes * - * @return type + * @return \Icinga\Module\Monitoring\DataView\Hostdowntime */ public function getScheduledDowntimes() { - return $this->backend->select() - ->from('downtime') - ->applyFilter(clone $this->filter) - ->where('downtime_objecttype', 'host'); + return $this->backend + ->select() + ->from('hostdowntime', array('host_name')) + ->applyFilter(clone $this->filter); } } From ebe8a409e3b54555cd055f9be7dd7f2e0e9457bc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:34:18 +0200 Subject: [PATCH 030/237] monitoring: Add host comment query refs #9009 --- .../Backend/Ido/Query/HostcommentQuery.php | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php new file mode 100644 index 000000000..a61043b4c --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -0,0 +1,183 @@ + array( + 'comment_author' => 'c.author_name COLLATE latin1_general_ci', + 'comment_author_name' => 'c.author_name', + 'comment_data' => 'c.comment_data', + 'comment_expiration' => 'CASE c.expires WHEN 1 THEN UNIX_TIMESTAMP(c.expiration_time) ELSE NULL END', + 'comment_internal_id' => 'c.internal_comment_id', + 'comment_is_persistent' => 'c.is_persistent', + 'comment_timestamp' => 'UNIX_TIMESTAMP(c.comment_time)', + 'comment_type' => "CASE c.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END", + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'hoststatus' => array( + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('c' => $this->prefix . 'comments'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = c.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->joinedVirtualTables['comments'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->distinct(); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = h.host_object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id AND so.is_active = 1', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->distinct(); + } +} From a9680bfd68a26d83d1036a70ae0395fe92ea46c4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:34:38 +0200 Subject: [PATCH 031/237] monitoring: Add host comment data view refs #9009 --- .../Monitoring/DataView/Hostcomment.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Hostcomment.php diff --git a/modules/monitoring/library/Monitoring/DataView/Hostcomment.php b/modules/monitoring/library/Monitoring/DataView/Hostcomment.php new file mode 100644 index 000000000..b751a82b9 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hostcomment.php @@ -0,0 +1,54 @@ + Date: Fri, 29 May 2015 15:34:52 +0200 Subject: [PATCH 032/237] monitoring: Add service comment query refs #9009 --- .../Backend/Ido/Query/ServicecommentQuery.php | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php new file mode 100644 index 000000000..655f0c0cc --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -0,0 +1,189 @@ + array( + 'comment_author' => 'c.author_name COLLATE latin1_general_ci', + 'comment_author_name' => 'c.author_name', + 'comment_data' => 'c.comment_data', + 'comment_expiration' => 'CASE c.expires WHEN 1 THEN UNIX_TIMESTAMP(c.expiration_time) ELSE NULL END', + 'comment_internal_id' => 'c.internal_comment_id', + 'comment_is_persistent' => 'c.is_persistent', + 'comment_timestamp' => 'UNIX_TIMESTAMP(c.comment_time)', + 'comment_type' => "CASE c.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END", + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'hoststatus' => array( + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ), + 'servicestatus' => array( + 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('c' => $this->prefix . 'comments'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = c.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = 2', + 1 + ); + $this->joinedVirtualTables['comments'] = true; + } + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->distinct(); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } + + /** + * Join service status + */ + protected function joinServicestatus() + { + $this->select->join( + array('ss' => $this->prefix . 'servicestatus'), + 'ss.service_object_id = so.object_id', + array() + ); + } +} From 82644b6122ed9927fc0cc6c3aff349f47596e08e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:35:08 +0200 Subject: [PATCH 033/237] monitoring: Add service comment data view refs #9009 --- .../Monitoring/DataView/Servicecomment.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicecomment.php diff --git a/modules/monitoring/library/Monitoring/DataView/Servicecomment.php b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php new file mode 100644 index 000000000..64d193cfa --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php @@ -0,0 +1,57 @@ + Date: Fri, 29 May 2015 15:35:39 +0200 Subject: [PATCH 034/237] monitoring: Use the host and service comment queries in the comment query refs #9009 --- .../Backend/Ido/Query/CommentQuery.php | 152 ++++++++++++------ 1 file changed, 100 insertions(+), 52 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php index eff3bc1e7..d80f74d36 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php @@ -3,78 +3,126 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + /** - * Query map for comments + * Query for host and service comments */ class CommentQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( 'comments' => array( - 'comment_internal_id' => 'cm.internal_comment_id', - 'comment_data' => 'cm.comment_data', - 'comment_author' => 'cm.author_name COLLATE latin1_general_ci', - 'comment_author_name' => 'cm.author_name', - 'comment_timestamp' => 'UNIX_TIMESTAMP(cm.comment_time)', - 'comment_type' => "CASE cm.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'downtime' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END", - 'comment_is_persistent' => 'cm.is_persistent', - 'comment_expiration' => 'CASE cm.expires WHEN 1 THEN UNIX_TIMESTAMP(cm.expiration_time) ELSE NULL END', - 'comment_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", - 'host' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', - 'host_name' => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END', - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_description' => 'so.name2', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', - 'service_host_name' => 'so.name1' + 'comment_author' => 'c.comment_author', + 'comment_author_name' => 'c.comment_author_name', + 'comment_data' => 'c.comment_data', + 'comment_expiration' => 'c.comment_expiration', + 'comment_internal_id' => 'c.comment_internal_id', + 'comment_is_persistent' => 'c.comment_is_persistent', + 'comment_timestamp' => 'c.comment_timestamp', + 'comment_type' => 'c.comment_type', + 'object_type' => 'c.object_type' ), 'hosts' => array( - 'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END' + 'host_display_name' => 'c.host_display_name', + 'host_name' => 'c.host_name', + 'host_state' => 'c.host_state' ), 'services' => array( - 'service_display_name' => 's.display_name' + 'service_description' => 'c.service_description', + 'service_display_name' => 'c.service_display_name', + 'service_host_name' => 'c.service_host_name', + 'service_state' => 'c.service_state' ) ); - protected function joinBaseTables() - { - $this->select->from( - array('cm' => $this->prefix . 'comments'), - array() - ); - $this->select->joinLeft( - array('ho' => $this->prefix . 'objects'), - 'cm.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', - array() - ); - $this->select->joinLeft( - array('so' => $this->prefix . 'objects'), - 'cm.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2', - array() - ); - $this->joinedVirtualTables = array('comments' => true); - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $commentQuery; - protected function joinHosts() + /** + * Subqueries used for the comment query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) { - $this->select->joinLeft( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = ho.object_id', - array() - ); + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } return $this; } + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->commentQuery = $this->db->select(); + $this->select->from( + array('c' => $this->commentQuery), + array() + ); + $this->joinedVirtualTables['comments'] = true; + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts']); + foreach (array_keys($this->columnMap['services']) as $column) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + $hosts = $this->createSubQuery('hostcomment', $columns); + $this->subQueries[] = $hosts; + $this->commentQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ 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() - ); + $columns = array_keys($this->columnMap['comments'] + $this->columnMap['hosts'] + $this->columnMap['services']); + $services = $this->createSubQuery('servicecomment', $columns); + $this->subQueries[] = $services; + $this->commentQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } return $this; } } From 16ab26cb7cbf0e66778716dc2a086d09340b29dc Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:36:03 +0200 Subject: [PATCH 035/237] monitoring: Remove unused alias from the downtime query refs #9009 --- .../library/Monitoring/Backend/Ido/Query/DowntimeQuery.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index 3ff4a9a24..1127a537c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -5,7 +5,6 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; use Zend_Db_Expr; use Zend_Db_Select; -use Icinga\Authentication\Manager; use Icinga\Data\Filter\Filter; /** From 41bc4e3b21faf554f6bff84bfcd5d49715c83241 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:36:42 +0200 Subject: [PATCH 036/237] monitoring: Provide downtime_author only as filter column refs #9009 --- modules/monitoring/library/Monitoring/DataView/Downtime.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php index 3664bf95b..c654716ba 100644 --- a/modules/monitoring/library/Monitoring/DataView/Downtime.php +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\DataView; +/** + * Host and service downtimes view + */ class Downtime extends DataView { /** @@ -24,7 +27,6 @@ class Downtime extends DataView public function getColumns() { return array( - 'downtime_author', 'downtime_author_name', 'downtime_comment', 'downtime_duration', @@ -52,6 +54,7 @@ class Downtime extends DataView public function getFilterColumns() { return array( + 'downtime_author', 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); From 54eb0eaf221b5957c2816903fe4f804058ab6cc1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:37:05 +0200 Subject: [PATCH 037/237] monitoring: Add restrictable filter columns to the comment data view refs #9009 --- .../library/Monitoring/DataView/Comment.php | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Comment.php b/modules/monitoring/library/Monitoring/DataView/Comment.php index 1fadd8b62..9d7aa612e 100644 --- a/modules/monitoring/library/Monitoring/DataView/Comment.php +++ b/modules/monitoring/library/Monitoring/DataView/Comment.php @@ -4,32 +4,57 @@ namespace Icinga\Module\Monitoring\DataView; /** - * View representation for comments + * Host and service comments view */ class Comment extends DataView { + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } + /** * {@inheritdoc} */ public function getColumns() { return array( - 'comment_objecttype', - 'comment_internal_id', - 'comment_data', 'comment_author_name', + 'comment_data', + 'comment_expiration', + 'comment_internal_id', + 'comment_is_persistent', 'comment_timestamp', 'comment_type', - 'comment_is_persistent', - 'comment_expiration', - 'host_name', - 'service_description', 'host_display_name', + 'host_name', + 'object_type', + 'service_description', 'service_display_name', 'service_host_name' ); } + /** + * {@inheritdoc} + */ + public function getFilterColumns() + { + return array( + 'comment_author ', + 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + /** * {@inheritdoc} */ @@ -55,12 +80,4 @@ class Comment extends DataView ) ); } - - /** - * {@inheritdoc} - */ - public function getFilterColumns() - { - return array('comment_author', 'host', 'service', 'service_host'); - } } From 46fdaf4698cde5ddd062a840c284e7d837667717 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:38:03 +0200 Subject: [PATCH 038/237] monitoring: Fix select columns for the comment data views refs #9009 --- .../application/controllers/CommentController.php | 2 +- .../application/controllers/CommentsController.php | 6 +++--- .../application/controllers/ListController.php | 2 +- .../library/Monitoring/Object/HostList.php | 13 +++++++++++++ .../library/Monitoring/Object/MonitoredObject.php | 2 +- .../library/Monitoring/Object/ServiceList.php | 13 +++++++++++++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 4237d598b..7ab331adc 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -27,7 +27,7 @@ class Monitoring_CommentController extends Controller $this->comment = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', - 'objecttype' => 'comment_objecttype', + 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index e1092b033..9b31755cc 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -32,7 +32,7 @@ class Monitoring_CommentsController extends Controller )); $this->comments = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', - 'objecttype' => 'comment_objecttype', + 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', @@ -44,11 +44,11 @@ class Monitoring_CommentsController extends Controller 'host_display_name', 'service_display_name' ))->addFilter($this->filter)->getQuery()->fetchAll(); - + if (false === $this->comments) { throw new Zend_Controller_Action_Exception($this->translate('Comment not found')); } - + $this->getTabs()->add( 'comments', array( diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 2e4e34390..1a3733a7a 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -431,7 +431,7 @@ class Monitoring_ListController extends Controller $query = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', - 'objecttype' => 'comment_objecttype', + 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', diff --git a/modules/monitoring/library/Monitoring/Object/HostList.php b/modules/monitoring/library/Monitoring/Object/HostList.php index 31f360d03..cbbafdecf 100644 --- a/modules/monitoring/library/Monitoring/Object/HostList.php +++ b/modules/monitoring/library/Monitoring/Object/HostList.php @@ -87,6 +87,19 @@ class HostList extends ObjectList return FilterOr::matchAny($filterExpression); } + /** + * Get the comments + * + * @return \Icinga\Module\Monitoring\DataView\Hostcomment + */ + public function getComments() + { + return $this->backend + ->select() + ->from('hostcomment', array('host_name')) + ->applyFilter(clone $this->filter); + } + /** * Get the scheduled downtimes * diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index fdf64fc51..626b5cd3d 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -253,7 +253,7 @@ abstract class MonitoredObject implements Filterable 'type' => 'comment_type', )) ->where('comment_type', array('comment', 'ack')) - ->where('comment_objecttype', $this->type); + ->where('object_type', $this->type); if ($this->type === self::TYPE_SERVICE) { $comments ->where('service_host_name', $this->host_name) diff --git a/modules/monitoring/library/Monitoring/Object/ServiceList.php b/modules/monitoring/library/Monitoring/Object/ServiceList.php index b06cffc89..f4cc38598 100644 --- a/modules/monitoring/library/Monitoring/Object/ServiceList.php +++ b/modules/monitoring/library/Monitoring/Object/ServiceList.php @@ -135,6 +135,19 @@ class ServiceList extends ObjectList return FilterOr::matchAny($filterExpression); } + /** + * Get the comments + * + * @return \Icinga\Module\Monitoring\DataView\Hostcomment + */ + public function getComments() + { + return $this->backend + ->select() + ->from('servicecomment', array('host_name', 'service_description')) + ->applyFilter(clone $this->filter); + } + /** * Get the scheduled downtimes * From 42d9f05c0f8661bac9392fc9c72e46223aec0461 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 29 May 2015 15:39:41 +0200 Subject: [PATCH 039/237] monitoring: Apply host and service restrctions to the comments overview refs #9009 --- modules/monitoring/application/controllers/ListController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 1a3733a7a..fa9c25546 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -444,6 +444,9 @@ class Monitoring_ListController extends Controller 'service_display_name' )); $this->filterQuery($query); + + $this->applyRestriction('monitoring/filter/objects', $query); + $this->view->comments = $query; $this->setupLimitControl(); From 798f4adc3454621663edf214bcaa3e1f9ee30ae8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:40:03 +0200 Subject: [PATCH 040/237] monitoring: Add query for the host group summary refs #9009 --- .../Ido/Query/HostgroupsummaryQuery.php | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php new file mode 100644 index 000000000..eee708fa1 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php @@ -0,0 +1,151 @@ + array( + 'hostgroup' => 'hostgroup COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hostgroup_alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hostgroup_name', + 'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)', + 'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_down_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled != 0 THEN state_change ELSE 0 END)', + 'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)', + 'hosts_down_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN state_change ELSE 0 END)', + 'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)', + 'hosts_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 99 THEN state_change ELSE 0 END)', + 'hosts_severity' => 'MAX(CASE WHEN object_type = \'host\' THEN severity ELSE 0 END)', + 'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)', + 'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)', + 'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled != 0 THEN state_change ELSE 0 END)', + 'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN state_change ELSE 0 END)', + 'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)', + 'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)', + 'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)', + 'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN state_change ELSE 0 END)', + 'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)', + 'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)', + 'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)', + 'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)', + 'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)', + 'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)', + 'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)', + 'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN state_change ELSE 0 END)', + 'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)', + 'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN state_change ELSE 0 END)' + ) + ); + + /** + * The union + * + * @var Zend_Db_Select + */ + protected $summaryQuery; + + /** + * Subqueries used for the summary query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + // TODO(el): Allow to switch between hard and soft states + $hosts = $this->createSubQuery( + 'Hoststatus', + array( + 'handled' => 'host_handled', + 'host_state' => new Zend_Db_Expr('NULL'), + 'hostgroup_alias', + 'hostgroup_name', + 'object_type', + 'severity' => 'host_severity', + 'state' => 'host_hard_state', + 'state_change' => 'host_last_hard_state_change' + ) + ); + $this->subQueries[] = $hosts; + $services = $this->createSubQuery( + 'Servicestatus', + array( + 'handled' => 'service_handled', + 'host_state' => 'host_hard_state', + 'hostgroup_alias', + 'hostgroup_name', + 'object_type', + 'severity' => new Zend_Db_Expr('NULL'), + 'state' => 'service_hard_state', + 'state_change' => 'service_last_hard_state_change' + ) + ); + $this->subQueries[] = $services; + $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); + $this->select->from(array('statussummary' => $this->summaryQuery), array())->group('hostgroup_name'); + $this->joinedVirtualTables['hoststatussummary'] = true; + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + if (! $this->hasAliasName($columnOrAlias)) { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } +} From 4b2c83fbf72ecd634ad52fdbab42442d1fad1a13 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:40:55 +0200 Subject: [PATCH 041/237] monitoring: Use the host group summary query refs #9009 --- .../library/Monitoring/DataView/Hostgroupsummary.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php index 63c04df79..31a1ae035 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php @@ -50,14 +50,6 @@ class Hostgroupsummary extends DataView return array('hostgroup'); } - /** - * {@inheritdoc} - */ - public static function getQueryName() - { - return 'groupsummary'; - } - /** * {@inheritdoc} */ From 947b5436c37188e7b35b3623d691c42cc3335d17 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:41:31 +0200 Subject: [PATCH 042/237] monitoring: Fix host group summary select columns refs #9009 --- .../monitoring/application/controllers/ListController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index fa9c25546..d470d6498 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -525,15 +525,15 @@ class Monitoring_ListController extends Controller 'hostgroup_alias', 'hostgroup_name', 'hosts_down_handled', - 'hosts_down_last_state_change_handled', - 'hosts_down_last_state_change_unhandled', + 'hosts_down_last_state_change_handled' => 'hosts_down_handled_last_state_change', + 'hosts_down_last_state_change_unhandled' => 'hosts_down_unhandled_last_state_change', 'hosts_down_unhandled', 'hosts_pending', 'hosts_pending_last_state_change', 'hosts_total', 'hosts_unreachable_handled', - 'hosts_unreachable_last_state_change_handled', - 'hosts_unreachable_last_state_change_unhandled', + 'hosts_unreachable_last_state_change_handled' => 'hosts_unreachable_handled_last_state_change', + 'hosts_unreachable_last_state_change_unhandled' => 'hosts_unreachable_unhandled_last_state_change', 'hosts_unreachable_unhandled', 'hosts_up', 'hosts_up_last_state_change', From 761de2eb33e1bab7df830bf014c67b9a2f0b93be Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:48:14 +0200 Subject: [PATCH 043/237] monitoring: Fix a join condition in the host status query refs #9009 --- .../library/Monitoring/Backend/Ido/Query/HoststatusQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index e630727d4..ca7089e79 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -336,7 +336,7 @@ SQL; array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id AND so.is_active = 1', + 'so.object_id = s.service_object_id', array() )->where( 'so.is_active = ?', From 71f19b2cc6d8a0f19e861bb5b5ce7b496cadf1bf Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:48:34 +0200 Subject: [PATCH 044/237] monitoring: Add missing columns to the service status query refs #9009 --- .../Monitoring/Backend/Ido/Query/ServicestatusQuery.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 990e5a9b2..78e4053b3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -139,7 +139,11 @@ class ServicestatusQuery extends IdoQuery 'service_notes_url' => 's.notes_url' ), 'servicestatus' => array( - 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END' + 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', + 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', + 'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)', + 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', + 'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ) ); From 69264522688ba640eb8496da8d430d507b2e9de6 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:49:21 +0200 Subject: [PATCH 045/237] monitoring: Add restrictable filter columns to the host group summary refs #9009 --- .../Monitoring/DataView/Hostgroupsummary.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php index 31a1ae035..56ae7be35 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php @@ -17,17 +17,16 @@ class Hostgroupsummary extends DataView 'hostgroup_alias', 'hostgroup_name', 'hosts_down_handled', - 'hosts_down_last_state_change_handled', - 'hosts_down_last_state_change_unhandled', + 'hosts_down_handled_last_state_change', 'hosts_down_unhandled', + 'hosts_down_unhandled_last_state_change', 'hosts_pending', 'hosts_pending_last_state_change', - 'hosts_severity', 'hosts_total', 'hosts_unreachable_handled', - 'hosts_unreachable_last_state_change_handled', - 'hosts_unreachable_last_state_change_unhandled', + 'hosts_unreachable_handled_last_state_change', 'hosts_unreachable_unhandled', + 'hosts_unreachable_unhandled_last_state_change', 'hosts_up', 'hosts_up_last_state_change', 'services_critical_handled', @@ -47,7 +46,11 @@ class Hostgroupsummary extends DataView */ public function getFilterColumns() { - return array('hostgroup'); + return array( + 'hosts_severity', + 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } /** From c1c8c1c005dcc5f47ae091ee716c32bfa3bab7a5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 11:49:31 +0200 Subject: [PATCH 046/237] monitoring: Restrict the host group summary refs #9009 --- modules/monitoring/application/controllers/ListController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index d470d6498..741ca3360 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -548,6 +548,9 @@ class Monitoring_ListController extends Controller 'services_warning_unhandled' )); $this->filterQuery($query); + + $this->applyRestriction('monitoring/filter/objects', $query); + $this->view->hostgroups = $query; $this->setupLimitControl(); From 8bc9e46757edd2df9bf6ba8aac2a928d731b9cf5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:21:29 +0200 Subject: [PATCH 047/237] monitoring: Don't select host counts in the service group overview We're not showing the counts. refs #9009 --- .../monitoring/application/controllers/ListController.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 741ca3360..f46370261 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -478,12 +478,6 @@ class Monitoring_ListController extends Controller $this->setAutorefreshInterval(12); $query = $this->backend->select()->from('servicegroupsummary', array( - 'hosts_down_handled', - 'hosts_down_unhandled', - 'hosts_pending', - 'hosts_unreachable_handled', - 'hosts_unreachable_unhandled', - 'hosts_up', 'servicegroup_alias', 'servicegroup_name', 'services_critical_handled', From 082f9b1edd9afb3e493d760a0abfd23759df31e1 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:26:01 +0200 Subject: [PATCH 048/237] monitoring: Don't provide unnecessary columns in the host group summary query refs #9009 --- .../Backend/Ido/Query/HostgroupsummaryQuery.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php index eee708fa1..42e379e01 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php @@ -8,7 +8,7 @@ use Zend_Db_Expr; use Zend_Db_Select; /** - * Query for host and service group summaries + * Query for host group summary */ class HostgroupsummaryQuery extends IdoQuery { @@ -38,25 +38,17 @@ class HostgroupsummaryQuery extends IdoQuery 'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)', 'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)', 'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)', - 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN state_change ELSE 0 END)', 'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)', - 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN state_change ELSE 0 END)', 'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)', - 'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)', 'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)', - 'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)', 'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)', 'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)', 'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)', 'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)', - 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN state_change ELSE 0 END)', 'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)', - 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN state_change ELSE 0 END)', 'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)', 'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)', - 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN state_change ELSE 0 END)', 'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)', - 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN state_change ELSE 0 END)' ) ); From d1bb19d0371db0d492d82f4918f743ca96b72674 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:48:04 +0200 Subject: [PATCH 049/237] monitoring: Add service status summary query refs #9009 --- .../Ido/Query/ServicestatussummaryQuery.php | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php new file mode 100644 index 000000000..0a04e9c41 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php @@ -0,0 +1,186 @@ + array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_alias' => 'h.alias COLLATE latin1_general_ci', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + 'host_name' => 'so.name1' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ), + 'servicestatussummary' => array( + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1', + 'services_critical' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 THEN 1 ELSE 0 END END)', + 'services_critical_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', + 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_critical_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', + 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_ok' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 0 THEN 1 ELSE 0 END END)', + 'services_ok_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_pending' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 1 ELSE 0 END)', + 'services_pending_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END)', + 'services_total' => 'SUM(1)', + 'services_unknown' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 THEN 1 ELSE 0 END END)', + 'services_unknown_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', + 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_unknown_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', + 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_warning' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 THEN 1 ELSE 0 END END)', + 'services_warning_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', + 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', + 'services_warning_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', + 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('so' => $this->prefix . 'objects'), + array() + )->join( + array('ss' => $this->prefix . 'servicestatus'), + 'ss.service_object_id = so.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + $this->joinedVirtualTables['servicestatussummary'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + )->where( + 'hgo.objecttype_id = ?', + 3 + ); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + // TODO(el): Join host objects for is_active check? + } + + /** + * Join host status + */ + protected function joinHoststatus() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hs' => $this->prefix . 'hoststatus'), + 'hs.host_object_id = s.host_object_id', + array() + ); + // TODO(el): Join host objects for is_active check? + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ) + ->group('sgo.name1'); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } +} From a8b925e2ec8925a9787f23716f51981a0cb37e92 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:48:22 +0200 Subject: [PATCH 050/237] monitoring: Use the service status summary query in the service groups overview refs #9009 --- .../library/Monitoring/DataView/Servicegroupsummary.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php index 11d6ec07e..b37af02aa 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -11,12 +11,6 @@ class Servicegroupsummary extends DataView public function getColumns() { return array( - 'hosts_down_handled', - 'hosts_down_unhandled', - 'hosts_pending', - 'hosts_unreachable_handled', - 'hosts_unreachable_unhandled', - 'hosts_up', 'servicegroup_alias', 'servicegroup_name', 'services_critical_handled', @@ -53,7 +47,7 @@ class Servicegroupsummary extends DataView */ public static function getQueryName() { - return 'groupsummary'; + return 'servicestatussummary'; } /** From 6588c73b4e038fb209c42afebc0bd5b8359c1451 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:53:56 +0200 Subject: [PATCH 051/237] monitoring: Add restrictable filter columns to the service group summary refs #9009 --- .../DataView/Servicegroupsummary.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php index b37af02aa..37045a4d5 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\DataView; +/** + * Data view for service group summaries + */ class Servicegroupsummary extends DataView { /** @@ -14,23 +17,22 @@ class Servicegroupsummary extends DataView 'servicegroup_alias', 'servicegroup_name', 'services_critical_handled', - 'services_critical_last_state_change_handled', - 'services_critical_last_state_change_unhandled', + 'services_critical_handled_last_state_change', 'services_critical_unhandled', + 'services_critical_unhandled_last_state_change', 'services_ok', 'services_ok_last_state_change', 'services_pending', 'services_pending_last_state_change', - 'services_severity', 'services_total', 'services_unknown_handled', - 'services_unknown_last_state_change_handled', - 'services_unknown_last_state_change_unhandled', + 'services_unknown_handled_last_state_change', 'services_unknown_unhandled', + 'services_unknown_unhandled_last_state_change', 'services_warning_handled', - 'services_warning_last_state_change_handled', - 'services_warning_last_state_change_unhandled', - 'services_warning_unhandled' + 'services_warning_handled_last_state_change', + 'services_warning_unhandled', + 'services_warning_unhandled_last_state_change' ); } @@ -39,7 +41,11 @@ class Servicegroupsummary extends DataView */ public function getFilterColumns() { - return array('servicegroup'); + return array( + 'services_severity', + 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } /** From fe488c7b77e3ece1d89395bb6213738724189773 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:54:25 +0200 Subject: [PATCH 052/237] monitoring: Restrict the service group overview refs #9009 --- .../application/controllers/ListController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index f46370261..5f5162532 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -481,8 +481,8 @@ class Monitoring_ListController extends Controller 'servicegroup_alias', 'servicegroup_name', 'services_critical_handled', - 'services_critical_last_state_change_handled', - 'services_critical_last_state_change_unhandled', + 'services_critical_last_state_change_handled' => 'services_critical_handled_last_state_change', + 'services_critical_last_state_change_unhandled' => 'services_critical_unhandled_last_state_change', 'services_critical_unhandled', 'services_ok', 'services_ok_last_state_change', @@ -490,15 +490,18 @@ class Monitoring_ListController extends Controller 'services_pending_last_state_change', 'services_total', 'services_unknown_handled', - 'services_unknown_last_state_change_handled', - 'services_unknown_last_state_change_unhandled', + 'services_unknown_last_state_change_handled' => 'services_unknown_handled_last_state_change', + 'services_unknown_last_state_change_unhandled' => 'services_unknown_unhandled_last_state_change', 'services_unknown_unhandled', 'services_warning_handled', - 'services_warning_last_state_change_handled', - 'services_warning_last_state_change_unhandled', + 'services_warning_last_state_change_handled' => 'services_warning_handled_last_state_change', + 'services_warning_last_state_change_unhandled' => 'services_warning_unhandled_last_state_change', 'services_warning_unhandled' )); $this->filterQuery($query); + + $this->applyRestriction('monitoring/filter/objects', $query); + $this->view->servicegroups = $query; $this->setupLimitControl(); From 8e88864f4a0ef2bb89d7348ac7ce015416fb2667 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 12:54:51 +0200 Subject: [PATCH 053/237] monitoring: Fix host columns of the service status query refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 78e4053b3..7c099b058 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query for service status + */ class ServicestatusQuery extends IdoQuery { /** @@ -20,17 +23,14 @@ class ServicestatusQuery extends IdoQuery 'hostgroup_name' => 'hgo.name1' ), 'hosts' => array( - 'host' => 'so.name1 COLLATE latin1_general_ci', 'host_action_url' => 'h.action_url', 'host_address' => 'h.address', - 'host_alias' => 'h.alias', + 'host_alias' => 'h.alias COLLATE latin1_general_ci', 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', 'host_icon_image' => 'h.icon_image', 'host_icon_image_alt' => 'h.icon_image_alt', 'host_ipv4' => 'INET_ATON(h.address)', - 'host_name' => 'so.name1', - 'host_notes_url' => 'h.notes_url', - 'object_type' => '(\'host\')' + 'host_notes_url' => 'h.notes_url' ), 'hoststatus' => array( 'host_acknowledged' => 'hs.problem_has_been_acknowledged', @@ -127,16 +127,18 @@ class ServicestatusQuery extends IdoQuery 'host_unhandled' => 'CASE WHEN (hs.problem_has_been_acknowledged + hs.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ), 'services' => array( - 'object_type' => '(\'service\')', - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_action_url' => 's.action_url', - 'service_description' => 'so.name2', - 'service_display_name' => 's.display_name COLLATE latin1_general_ci', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', - 'service_host_name' => 'so.name1', - 'service_icon_image' => 's.icon_image', - 'service_icon_image_alt' => 's.icon_image_alt', - 'service_notes_url' => 's.notes_url' + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_action_url' => 's.action_url', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1', + 'service_icon_image' => 's.icon_image', + 'service_icon_image_alt' => 's.icon_image_alt', + 'service_notes_url' => 's.notes_url' ), 'servicestatus' => array( 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', From ae7861344388d986d3b95e3179c9919cae7cbb3c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:13:15 +0200 Subject: [PATCH 054/237] lib: Add sub query mode to the DbQuery refs #9009 --- library/Icinga/Data/Db/DbQuery.php | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 4fa7f132d..42937147b 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -23,6 +23,15 @@ class DbQuery extends SimpleQuery */ protected $db; + /** + * Whether or not the query is a sub query + * + * Sub queries are automatically wrapped in parentheses + * + * @var bool + */ + protected $isSubQuery = false; + /** * Select query * @@ -71,6 +80,27 @@ class DbQuery extends SimpleQuery parent::init(); } + /** + * Get whether or not the query is a sub query + */ + public function getIsSubQuery() + { + return $this->isSubQuery; + } + + /** + * Set whether or not the query is a sub query + * + * @param bool $isSubQuery + * + * @return $this + */ + public function setIsSubQuery($isSubQuery = true) + { + $this->isSubQuery = (bool) $isSubQuery; + return $this; + } + public function setUseSubqueryCount($useSubqueryCount = true) { $this->useSubqueryCount = $useSubqueryCount; @@ -331,7 +361,8 @@ class DbQuery extends SimpleQuery */ public function __toString() { - return (string) $this->getSelectQuery(); + $select = (string) $this->getSelectQuery(); + return $this->getIsSubQuery() ? ('(' . $select . ')') : $select; } /** From 131af8e818f3cf84f9973100b6d2a47c77de7078 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:14:55 +0200 Subject: [PATCH 055/237] monitoring: Add host status summary query refs #9009 --- .../Ido/Query/HoststatussummaryQuery.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php new file mode 100644 index 000000000..7965d897a --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php @@ -0,0 +1,80 @@ + array( + 'hosts_down' => 'SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END)', + 'hosts_down_handled' => 'SUM(CASE WHEN state = 1 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_down_unhandled' => 'SUM(CASE WHEN state = 1 AND handled = 0 THEN 1 ELSE 0 END)', + 'hosts_pending' => 'SUM(CASE WHEN state = 99 THEN 1 ELSE 0 END)', + 'hosts_total' => 'SUM(1)', + 'hosts_unreachable' => 'SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END)', + 'hosts_unreachable_handled' => 'SUM(CASE WHEN state = 2 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_unhandled' => 'SUM(CASE WHEN state = 2 AND handled = 0 THEN 1 ELSE 0 END)', + 'hosts_up' => 'SUM(CASE WHEN state = 0 THEN 1 ELSE 0 END)' + ) + ); + + /** + * The host status sub select + * + * @var HostStatusQuery + */ + protected $subSelect; + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + $this->subSelect->applyFilter(clone $filter); + return $this; + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + // TODO(el): Allow to switch between hard and soft states + $this->subSelect = $this->createSubQuery( + 'Hoststatus', + array( + 'handled' => 'host_handled', + 'state' => 'host_hard_state', + 'state_change' => 'host_last_hard_state_change' + ) + ); + $this->select->from( + array('hoststatussummary' => $this->subSelect->setIsSubQuery(true)), + array() + ); + $this->joinedVirtualTables['hoststatussummary'] = true; + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->subSelect->where($condition, $value); + return $this; + } +} From e9308e847ab8f6a974cf7f94ae27f70673b3d0ab Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:15:09 +0200 Subject: [PATCH 056/237] monitoring: Add host status summary data view refs #9009 --- .../Monitoring/DataView/Hoststatussummary.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php diff --git a/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php new file mode 100644 index 000000000..094c40b95 --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php @@ -0,0 +1,47 @@ +getFilterColumns()); + } +} From 8f111406f300a1d217eccd8a8ed5461bb1c12381 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:16:22 +0200 Subject: [PATCH 057/237] monitoring: Restrict the host overview and the host status summary refs #9009 --- .../application/controllers/ListController.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 5f5162532..b08a84e3d 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -66,10 +66,9 @@ class Monitoring_ListController extends Controller $stateColumn = 'host_state'; $stateChangeColumn = 'host_last_state_change'; } - $this->addTitleTab('hosts', $this->translate('Hosts'), $this->translate('List hosts')); $this->setAutorefreshInterval(10); - $query = $this->backend->select()->from('hostStatus', array_merge(array( + $query = $this->backend->select()->from('hoststatus', array_merge(array( 'host_icon_image', 'host_icon_image_alt', 'host_name', @@ -98,10 +97,9 @@ class Monitoring_ListController extends Controller 'host_max_check_attempts' ), $this->addColumns())); $this->filterQuery($query); - $this->applyRestriction('monitoring/hosts/filter', $query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->hosts = $query; - - $this->view->stats = $this->backend->select()->from('statusSummary', array( + $stats = $this->backend->select()->from('hoststatussummary', array( 'hosts_total', 'hosts_up', 'hosts_down', @@ -111,8 +109,9 @@ class Monitoring_ListController extends Controller 'hosts_unreachable_handled', 'hosts_unreachable_unhandled', 'hosts_pending', - ))->getQuery()->fetchRow(); - + )); + $this->applyRestriction('monitoring/filter/objects', $stats); + $this->view->stats = $stats->fetchRow(); $this->setupLimitControl(); $this->setupPaginationControl($this->view->hosts); $this->setupSortControl(array( From f2f3fe2c07c9fe489f2476a30aef042f1550e510 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:39:10 +0200 Subject: [PATCH 058/237] monitoring: Add missing restrictable filter columns to the host status data view refs #9009 --- .../Monitoring/DataView/HostStatus.php | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index cb992752a..a9d6be771 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -5,19 +5,6 @@ namespace Icinga\Module\Monitoring\DataView; class HostStatus extends DataView { - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_host_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - /** * {@inheritdoc} */ @@ -84,7 +71,12 @@ class HostStatus extends DataView */ public function getFilterColumns() { - return array('host', 'hostgroup', 'hostgroup_name'); + return array( + 'host', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } /** @@ -125,4 +117,17 @@ class HostStatus extends DataView ) ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } } From fc2a50a9ffa40c1b67f78d7e5bea208c3c7e99d8 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:39:43 +0200 Subject: [PATCH 059/237] monitoring: Add missing restrictable filter columns to the host status summary data view refs #9009 --- .../library/Monitoring/DataView/Hoststatussummary.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php index 094c40b95..292698376 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Hoststatussummary.php @@ -30,7 +30,7 @@ class Hoststatussummary extends DataView public function getFilterColumns() { return array( - 'host', 'host_alias', 'host_name', + 'host', 'host_alias', 'host_display_name', 'host_name', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', 'service', 'service_description', 'service_display_name', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' @@ -42,6 +42,12 @@ class Hoststatussummary extends DataView */ public function isValidFilterTarget($column) { - return in_array($column, $this->getFilterColumns()); + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return in_array($column, $this->getFilterColumns()); + } } } From 7ffa1b93a3dc07999b9a05dfad71c3ff85f58d5b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:44:16 +0200 Subject: [PATCH 060/237] monitoring: Add service status summary data view refs #9009 --- .../DataView/Servicestatussummary.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php diff --git a/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php b/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php new file mode 100644 index 000000000..5cb6b137f --- /dev/null +++ b/modules/monitoring/library/Monitoring/DataView/Servicestatussummary.php @@ -0,0 +1,58 @@ +getFilterColumns()); + } + } +} From f479ea1da8aaead5b9d45918d3e4973642f5e251 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:44:36 +0200 Subject: [PATCH 061/237] monitoring: Restrict the service status summary refs #9009 --- .../controllers/ListController.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index b08a84e3d..4eb95f7df 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -199,23 +199,22 @@ class Monitoring_ListController extends Controller 'host_last_check' => $this->translate('Last Host Check') ), $query); - $this->view->stats = $this->backend->select()->from('statusSummary', array( - 'services_total', - 'services_ok', - 'services_problem', - 'services_problem_handled', - 'services_problem_unhandled', + $stats = $this->backend->select()->from('servicestatussummary', array( 'services_critical', - 'services_critical_unhandled', 'services_critical_handled', - 'services_warning', - 'services_warning_unhandled', - 'services_warning_handled', - 'services_unknown', - 'services_unknown_unhandled', - 'services_unknown_handled', + 'services_critical_unhandled', + 'services_ok', 'services_pending', - ))->getQuery()->fetchRow(); + 'services_total', + 'services_unknown', + 'services_unknown_handled', + 'services_unknown_unhandled', + 'services_warning', + 'services_warning_handled', + 'services_warning_unhandled' + )); + $this->applyRestriction('monitoring/filter/objects', $stats); + $this->view->stats = $stats->fetchRow(); } /** From f8b49864bb861c5d47910b8b31aa6697dc020e94 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 3 Jun 2015 14:59:20 +0200 Subject: [PATCH 062/237] monitoring: Restrict the services overview refs #9009 --- modules/monitoring/application/controllers/ListController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 4eb95f7df..9e5ac6d33 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -182,7 +182,7 @@ class Monitoring_ListController extends Controller ), $this->addColumns()); $query = $this->backend->select()->from('serviceStatus', $columns); $this->filterQuery($query); - $this->applyRestriction('monitoring/services/filter', $query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->services = $query; $this->setupLimitControl(); From b409609df753e987dc845e12aa534f436d9c5a47 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 09:11:10 +0200 Subject: [PATCH 063/237] monitoring: Use sub query count when joining service related tables to the host query Fixes count problems. refs #9009 --- .../library/Monitoring/Backend/Ido/Query/HoststatusQuery.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index ca7089e79..e515dd8a2 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -323,6 +323,7 @@ SQL; 4 ); $this->distinct(); + $this->setUseSubqueryCount(true); } /** @@ -330,6 +331,7 @@ SQL; */ protected function joinServices() { + $this->requireVirtualTable('hosts'); $this->select->join( array('s' => $this->prefix . 'services'), 's.host_object_id = h.host_object_id', @@ -347,6 +349,7 @@ SQL; 2 ); $this->distinct(); + $this->setUseSubqueryCount(true); } /** From 28b1cf57628b4b5fafd9c6a9ccd0ea6e5329173d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 09:13:17 +0200 Subject: [PATCH 064/237] monitoring: Support joining the service status query by service groups refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 7c099b058..7956082f7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -140,6 +140,11 @@ class ServicestatusQuery extends IdoQuery 'service_icon_image_alt' => 's.icon_image_alt', 'service_notes_url' => 's.notes_url' ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), 'servicestatus' => array( 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', @@ -221,6 +226,34 @@ class ServicestatusQuery extends IdoQuery ); } + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->distinct(); + } + /** * Join service status */ From c299fb3ce9889e1f342b3f07088a69023d908059 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 09:14:26 +0200 Subject: [PATCH 065/237] monitoring: Support filtering the host group overview by service custom variables refs #9009 --- .../Monitoring/DataView/Hostgroupsummary.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php index 56ae7be35..b576c685b 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php @@ -48,8 +48,10 @@ class Hostgroupsummary extends DataView { return array( 'hosts_severity', - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', + 'service', 'service_description', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } @@ -93,4 +95,18 @@ class Hostgroupsummary extends DataView ) ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return parent::isValidFilterTarget($column); + } + } } From 1ea7335b96b9b220b922e0e696856e5f02a3e1f7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 09:15:09 +0200 Subject: [PATCH 066/237] monitoring: Support filtering the service group summary by service custom variables refs #9009 --- .../Ido/Query/ServicestatussummaryQuery.php | 54 ++++++------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php index 0a04e9c41..306e52843 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php @@ -24,24 +24,20 @@ class ServicestatussummaryQuery extends IdoQuery 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', 'hostgroup_name' => 'hgo.name1' ), - 'hosts' => array( - 'host' => 'so.name1 COLLATE latin1_general_ci', - 'host_alias' => 'h.alias COLLATE latin1_general_ci', - 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', - 'host_name' => 'so.name1' - ), 'servicegroups' => array( 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', 'servicegroup_name' => 'sgo.name1', 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), - 'services' => array( - 'service_display_name' => 's.display_name COLLATE latin1_general_ci' - ), 'servicestatussummary' => array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_alias' => 'h.alias COLLATE latin1_general_ci', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + 'host_name' => 'so.name1', 'object_type' => '(\'service\')', 'service' => 'so.name2 COLLATE latin1_general_ci', 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', 'service_host' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1', 'services_critical' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 THEN 1 ELSE 0 END END)', @@ -75,10 +71,18 @@ class ServicestatussummaryQuery extends IdoQuery $this->select->from( array('so' => $this->prefix . 'objects'), array() + )->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() )->join( array('ss' => $this->prefix . 'servicestatus'), 'ss.service_object_id = so.object_id', array() + )->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() )->where( 'so.is_active = ?', 1 @@ -87,6 +91,8 @@ class ServicestatussummaryQuery extends IdoQuery 2 ); $this->joinedVirtualTables['servicestatussummary'] = true; + // Provide table services for custom var joins + $this->joinedVirtualTables['services'] = true; } /** @@ -94,7 +100,6 @@ class ServicestatussummaryQuery extends IdoQuery */ protected function joinHostgroups() { - $this->requireVirtualTable('services'); $this->select->join( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', @@ -116,20 +121,6 @@ class ServicestatussummaryQuery extends IdoQuery ); } - /** - * Join hosts - */ - protected function joinHosts() - { - $this->requireVirtualTable('services'); - $this->select->join( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = s.host_object_id', - array() - ); - // TODO(el): Join host objects for is_active check? - } - /** * Join host status */ @@ -138,10 +129,9 @@ class ServicestatussummaryQuery extends IdoQuery $this->requireVirtualTable('services'); $this->select->join( array('hs' => $this->prefix . 'hoststatus'), - 'hs.host_object_id = s.host_object_id', + 'hs.host_object_id = so.object_id', array() ); - // TODO(el): Join host objects for is_active check? } /** @@ -171,16 +161,4 @@ class ServicestatussummaryQuery extends IdoQuery ) ->group('sgo.name1'); } - - /** - * Join services - */ - protected function joinServices() - { - $this->select->join( - array('s' => $this->prefix . 'services'), - 's.service_object_id = so.object_id', - array() - ); - } } From 82b03547048226362389687b9953d90a0e57b04f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 09:16:28 +0200 Subject: [PATCH 067/237] monitoring: Support filtering the service group overview by custom variables refs #9009 --- .../Monitoring/DataView/Servicegroupsummary.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php index 37045a4d5..6eb2d4711 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -44,7 +44,7 @@ class Servicegroupsummary extends DataView return array( 'services_severity', 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'service', 'servicegroup' ); } @@ -89,4 +89,18 @@ class Servicegroupsummary extends DataView ) ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return parent::isValidFilterTarget($column); + } + } } From 7b176261f896a473b6a26c295114e925c24c58d2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:16:17 +0200 Subject: [PATCH 068/237] monitoring: Add query for service group summaries refs #9009 --- .../Ido/Query/ServicegroupsummaryQuery.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php new file mode 100644 index 000000000..76b004272 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php @@ -0,0 +1,136 @@ + array( + 'servicegroup' => 'servicegroup COLLATE latin1_general_ci', + 'servicegroup_alias' => 'servicegroup_alias COLLATE latin1_general_ci', + 'servicegroup_name' => 'servicegroup_name', + 'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)', + 'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_state = 0 THEN state_change ELSE 0 END)', + 'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)', + 'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)', + 'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)', + 'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)', + 'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)', + 'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)', + 'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)', + 'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_state = 0 THEN state_change ELSE 0 END)', + 'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)', + 'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN 1 ELSE 0 END)', + 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state > 0 THEN state_change ELSE 0 END)', + 'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN 1 ELSE 0 END)', + 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_state = 0 THEN state_change ELSE 0 END)' + ) + ); + + /** + * The union + * + * @var Zend_Db_Select + */ + protected $summaryQuery; + + /** + * Subqueries used for the summary query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + // TODO(el): Allow to switch between hard and soft states + $hosts = $this->createSubQuery( + 'Hoststatus', + array( + 'handled' => 'host_handled', + 'host_state' => new Zend_Db_Expr('NULL'), + 'servicegroup_alias', + 'servicegroup_name', + 'object_type', + 'severity' => 'host_severity', + 'state' => 'host_state', + 'state_change' => 'host_last_state_change' + ) + ); + $this->subQueries[] = $hosts; + $services = $this->createSubQuery( + 'Servicestatus', + array( + 'handled' => 'service_handled', + 'host_state' => 'host_state', + 'servicegroup_alias', + 'servicegroup_name', + 'object_type', + 'severity' => new Zend_Db_Expr('NULL'), + 'state' => 'service_state', + 'state_change' => 'service_last_state_change' + ) + ); + $this->subQueries[] = $services; + $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); + $this->select->from(array('statussummary' => $this->summaryQuery), array()); + $this->group('servicegroup_name'); + $this->joinedVirtualTables['servicestatussummary'] = true; + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + if (! $this->hasAliasName($columnOrAlias)) { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } +} From 480becd3d6b19a4104349c08e29db93f620458fe Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:16:41 +0200 Subject: [PATCH 069/237] monitoring: Fix pagination of the host group overview refs #9009 --- .../Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php index 42e379e01..045682cd6 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php @@ -112,7 +112,8 @@ class HostgroupsummaryQuery extends IdoQuery ); $this->subQueries[] = $services; $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); - $this->select->from(array('statussummary' => $this->summaryQuery), array())->group('hostgroup_name'); + $this->select->from(array('statussummary' => $this->summaryQuery), array()); + $this->group('hostgroup_name'); $this->joinedVirtualTables['hoststatussummary'] = true; } From 3f0219789180c22415f34e6dc54660119dacbb32 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:17:07 +0200 Subject: [PATCH 070/237] monitoring: Remove allowCustomVars form the host status summary query allowCustomVars is not needed on this query because all filters are passed to the underlying query. refs #9009 --- .../Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php index 7965d897a..aed8c20ea 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php @@ -10,11 +10,6 @@ use Icinga\Data\Filter\Filter; */ class HoststatussummaryQuery extends IdoQuery { - /** - * {@inheritdoc} - */ - protected $allowCustomVars = true; - /** * {@inheritdoc} */ From 76e2d8f5eec29d754b4562149ee68cb7962906b5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:17:54 +0200 Subject: [PATCH 071/237] monitoring: Add service_last_state_change to the service status query refs #9009 --- .../library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 7956082f7..aed350491 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -149,6 +149,7 @@ class ServicestatusQuery extends IdoQuery 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', 'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)', + 'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)', 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', 'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' ) From e0b117915ab9a829d52cf9869c861a382f8fc4a3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:28:50 +0200 Subject: [PATCH 072/237] monitoring: Use a sub select in the service status summary refs #9009 --- .../Ido/Query/ServicestatussummaryQuery.php | 179 +++++------------- 1 file changed, 51 insertions(+), 128 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php index 306e52843..325203717 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatussummaryQuery.php @@ -2,6 +2,7 @@ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; /** * Query for service status summary @@ -13,152 +14,74 @@ class ServicestatussummaryQuery extends IdoQuery /** * {@inheritdoc} */ - protected $allowCustomVars = true; + protected $columnMap = array( + 'servicestatussummary' => array( + 'services_critical' => 'SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END)', + 'services_critical_handled' => 'SUM(CASE WHEN state = 2 AND handled = 1 THEN 1 ELSE 0 END)', +// 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN state = 2 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_critical_unhandled' => 'SUM(CASE WHEN state = 2 AND handled = 0 THEN 1 ELSE 0 END)', +// 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN state = 2 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_ok' => 'SUM(CASE WHEN state = 0 THEN 1 ELSE 0 END)', +// 'services_ok_last_state_change' => 'MAX(CASE WHEN state = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_pending' => 'SUM(CASE WHEN state = 99 THEN 1 ELSE 0 END)', +// 'services_pending_last_state_change' => 'MAX(CASE WHEN state = 99 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_total' => 'SUM(1)', + 'services_unknown' => 'SUM(CASE WHEN state = 3 THEN 1 ELSE 0 END)', + 'services_unknown_handled' => 'SUM(CASE WHEN state = 3 AND handled = 1 THEN 1 ELSE 0 END)', +// 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN state = 3 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_unknown_unhandled' => 'SUM(CASE WHEN state = 3 AND handled = 0 THEN 1 ELSE 0 END)', +// 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN state = 3 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_warning' => 'SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END)', + 'services_warning_handled' => 'SUM(CASE WHEN state = 1 AND handled = 1 THEN 1 ELSE 0 END)', +// 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN state = 1 AND handled = 1 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)', + 'services_warning_unhandled' => 'SUM(CASE WHEN state = 1 AND handled = 0 THEN 1 ELSE 0 END)', +// 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN state = 1 AND handled = 0 THEN UNIX_TIMESTAMP(last_state_change) ELSE NULL END)' + ) + ); + + /** + * The service status sub select + * + * @var ServiceStatusQuery + */ + protected $subSelect; /** * {@inheritdoc} */ - protected $columnMap = array( - 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' - ), - 'servicegroups' => array( - 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', - 'servicegroup_name' => 'sgo.name1', - 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' - ), - 'servicestatussummary' => array( - 'host' => 'so.name1 COLLATE latin1_general_ci', - 'host_alias' => 'h.alias COLLATE latin1_general_ci', - 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', - 'host_name' => 'so.name1', - 'object_type' => '(\'service\')', - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_description' => 'so.name2', - 'service_display_name' => 's.display_name COLLATE latin1_general_ci', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', - 'service_host_name' => 'so.name1', - 'services_critical' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 THEN 1 ELSE 0 END END)', - 'services_critical_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', - 'services_critical_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_critical_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', - 'services_critical_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 2 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_ok' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 0 THEN 1 ELSE 0 END END)', - 'services_ok_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_pending' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 1 ELSE 0 END)', - 'services_pending_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END)', - 'services_total' => 'SUM(1)', - 'services_unknown' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 THEN 1 ELSE 0 END END)', - 'services_unknown_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', - 'services_unknown_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_unknown_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', - 'services_unknown_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 3 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_warning' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 THEN 1 ELSE 0 END END)', - 'services_warning_handled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END END)', - 'services_warning_handled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)', - 'services_warning_unhandled' => 'SUM(CASE WHEN ss.has_been_checked != 1 THEN 0 ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END END)', - 'services_warning_unhandled_last_state_change' => 'MAX(CASE WHEN ss.has_been_checked != 1 THEN NULL ELSE CASE WHEN ss.current_state = 1 AND (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN UNIX_TIMESTAMP(ss.last_state_change) ELSE NULL END END)' - ) - ); + public function addFilter(Filter $filter) + { + $this->subSelect->applyFilter(clone $filter); + return $this; + } /** * {@inheritdoc} */ protected function joinBaseTables() { + // TODO(el): Allow to switch between hard and soft states + $this->subSelect = $this->createSubQuery( + 'servicestatus', + array( + 'handled' => 'service_handled', + 'state' => 'service_state', + 'state_change' => 'service_last_state_change' + ) + ); $this->select->from( - array('so' => $this->prefix . 'objects'), + array('servicestatussummary' => $this->subSelect->setIsSubQuery(true)), array() - )->join( - array('s' => $this->prefix . 'services'), - 's.service_object_id = so.object_id', - array() - )->join( - array('ss' => $this->prefix . 'servicestatus'), - 'ss.service_object_id = so.object_id', - array() - )->join( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = s.host_object_id', - array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); $this->joinedVirtualTables['servicestatussummary'] = true; - // Provide table services for custom var joins - $this->joinedVirtualTables['services'] = true; } /** - * Join host groups + * {@inheritdoc} */ - protected function joinHostgroups() + public function where($condition, $value = null) { - $this->select->join( - array('hgm' => $this->prefix . 'hostgroup_members'), - 'hgm.host_object_id = s.host_object_id', - array() - )->join( - array('hg' => $this->prefix . 'hostgroups'), - 'hg.hostgroup_id = hgm.hostgroup_id', - array() - )->join( - array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', - array() - )->where( - 'hgo.is_active = ?', - 1 - )->where( - 'hgo.objecttype_id = ?', - 3 - ); - } - - /** - * Join host status - */ - protected function joinHoststatus() - { - $this->requireVirtualTable('services'); - $this->select->join( - array('hs' => $this->prefix . 'hoststatus'), - 'hs.host_object_id = so.object_id', - array() - ); - } - - /** - * Join service groups - */ - protected function joinServicegroups() - { - $this->select->join( - array('sgm' => $this->prefix . 'servicegroup_members'), - 'sgm.service_object_id = so.object_id', - array() - )->join( - array('sg' => $this->prefix . 'servicegroups'), - 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, - array() - )->join( - array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', - array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 - ) - ->group('sgo.name1'); + $this->subSelect->where($condition, $value); + return $this; } } From 0719c294d8c6ccc2b8010dd7426d2b4e4308ca5c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 10:29:30 +0200 Subject: [PATCH 073/237] monitoring: Use the service group summary query refs #9009 --- .../library/Monitoring/DataView/Servicegroupsummary.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php index 6eb2d4711..290c8f697 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -48,14 +48,6 @@ class Servicegroupsummary extends DataView ); } - /** - * {@inheritdoc} - */ - public static function getQueryName() - { - return 'servicestatussummary'; - } - /** * {@inheritdoc} */ From 044027772dabfe1af1163daa0c15fc1bf5bef30d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:46:45 +0200 Subject: [PATCH 074/237] monitoring: Use grouping instead of distinct in the host comment query refs #9009 --- .../Monitoring/Backend/Ido/Query/HostcommentQuery.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index a61043b4c..aafd7dbae 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -101,7 +101,7 @@ class HostcommentQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->distinct(); + $this->group('ho.name1'); } /** @@ -154,7 +154,7 @@ class HostcommentQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->distinct(); + $this->group('ho.name1'); } /** @@ -178,6 +178,6 @@ class HostcommentQuery extends IdoQuery 'so.objecttype_id = ?', 2 ); - $this->distinct(); + $this->group('ho.name1'); } } From 2539e51549cc914734b9560f3c39d15f76bdfee5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:47:07 +0200 Subject: [PATCH 075/237] monitoring: Use grouping instead of distinct in the host downtime query refs #9009 --- .../Monitoring/Backend/Ido/Query/HostdowntimeQuery.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index 7d123132d..91fe488d3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -107,7 +107,7 @@ class HostdowntimeQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->distinct(); + $this->group('ho.name1'); } /** @@ -160,7 +160,7 @@ class HostdowntimeQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->distinct(); + $this->group('ho.name1'); } /** @@ -184,6 +184,6 @@ class HostdowntimeQuery extends IdoQuery 'so.objecttype_id = ?', 2 ); - $this->distinct(); + $this->group('ho.name1'); } } From c3c1993870dc550b9eca0869c39dc3639727abf4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:47:39 +0200 Subject: [PATCH 076/237] monitoring: Use grouping instead of distinct in the service comment query refs #9009 --- .../Monitoring/Backend/Ido/Query/ServicecommentQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php index 655f0c0cc..40b6e805f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -106,7 +106,7 @@ class ServicecommentQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->distinct(); + $this->group(array('so.name2', 'so.name1')); } /** @@ -160,7 +160,7 @@ class ServicecommentQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->distinct(); + $this->group(array('so.name2', 'so.name1')); } /** From c993ee63b79aa9c16dba957419221159a36d35bb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:48:03 +0200 Subject: [PATCH 077/237] monitoring: Use grouping instead of distinct in the service downtime query refs #9009 --- .../Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php index 67f21c67c..55b8e466c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -112,7 +112,7 @@ class ServicedowntimeQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->distinct(); + $this->group(array('so.name2', 'so.name1')); } /** @@ -166,7 +166,7 @@ class ServicedowntimeQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->distinct(); + $this->group(array('so.name2', 'so.name1')); } /** From c08a98f6acab3113f2c81fe84652bf5f82bee074 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:48:33 +0200 Subject: [PATCH 078/237] monitoring: Use grouping instead of distinct in the host status query refs #9009 --- .../Monitoring/Backend/Ido/Query/HoststatusQuery.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index e515dd8a2..79a8e9e60 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -233,7 +233,7 @@ SQL; 'hgo.objecttype_id = ?', 3 ); - $this->distinct(); + $this->group('ho.name1'); } /** @@ -322,8 +322,7 @@ SQL; 'sgo.objecttype_id = ?', 4 ); - $this->distinct(); - $this->setUseSubqueryCount(true); + $this->group('ho.name1'); } /** @@ -348,8 +347,7 @@ SQL; 'so.objecttype_id = ?', 2 ); - $this->distinct(); - $this->setUseSubqueryCount(true); + $this->group('ho.name1'); } /** From 55921b48545eb148c3dbbe97e31edfa90d7b3d3c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 11:49:00 +0200 Subject: [PATCH 079/237] monitoring: Fix service status query regarding handled/unhandled and using distinct refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index aed350491..7ee5ee2a7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -146,12 +146,12 @@ class ServicestatusQuery extends IdoQuery 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'servicestatus' => array( - 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) > 0 THEN 1 ELSE 0 END', + 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END', 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', 'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)', 'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)', 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', - 'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth) = 0 THEN 1 ELSE 0 END' + 'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END', ) ); @@ -201,6 +201,7 @@ class ServicestatusQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); + $this->group(array('so.name2', 'so.name1')); } /** @@ -248,11 +249,11 @@ class ServicestatusQuery extends IdoQuery 'sgo.is_active = ?', 1 ) - ->where( - 'sgo.objecttype_id = ?', - 4 - ); - $this->distinct(); + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->group(array('so.name2', 'so.name1')); } /** @@ -260,6 +261,7 @@ class ServicestatusQuery extends IdoQuery */ protected function joinServicestatus() { + $this->requireVirtualTable('hoststatus'); $this->select->join( array('ss' => $this->prefix . 'servicestatus'), 'ss.service_object_id = so.object_id', From 99b5c7b243ef3ebf232ff493b2486f0507cb6421 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 12:36:56 +0200 Subject: [PATCH 080/237] monitoring: Add columns the to service status query required by the tactical overview refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 7ee5ee2a7..f336ce30d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -146,10 +146,57 @@ class ServicestatusQuery extends IdoQuery 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'servicestatus' => array( + 'service_active_checks_enabled' => 'ss.active_checks_enabled', + 'service_event_handler_enabled' => 'ss.event_handler_enabled', + 'service_flap_detection_enabled' => 'ss.flap_detection_enabled', 'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END', 'service_hard_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END', + 'service_is_flapping' => 'ss.is_flapping', + 'service_is_passive_checked' => 'CASE WHEN ss.active_checks_enabled = 0 AND ss.passive_checks_enabled = 1 THEN 1 ELSE 0 END', 'service_last_hard_state_change' => 'UNIX_TIMESTAMP(ss.last_hard_state_change)', 'service_last_state_change' => 'UNIX_TIMESTAMP(ss.last_state_change)', + 'service_notifications_enabled' => 'ss.notifications_enabled', + 'service_severity' => 'CASE WHEN ss.current_state = 0 + THEN + CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL + THEN 16 + ELSE 0 + END + + + CASE WHEN ss.problem_has_been_acknowledged = 1 + THEN 2 + ELSE + CASE WHEN ss.scheduled_downtime_depth > 0 + THEN 1 + ELSE 4 + END + END + ELSE + CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 16 + WHEN ss.current_state = 1 THEN 32 + WHEN ss.current_state = 2 THEN 128 + WHEN ss.current_state = 3 THEN 64 + ELSE 256 + END + + + CASE WHEN hs.current_state > 0 + THEN 1024 + ELSE + CASE WHEN ss.problem_has_been_acknowledged = 1 + THEN 512 + ELSE + CASE WHEN ss.scheduled_downtime_depth > 0 + THEN 256 + ELSE 2048 + END + END + END + END + + + CASE WHEN ss.state_type = 1 + THEN 8 + ELSE 0 + END', 'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', 'service_unhandled' => 'CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) = 0 THEN 1 ELSE 0 END', ) From b69b47277ed95debbfc7f5d62358f06cedf3efe9 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 12:37:29 +0200 Subject: [PATCH 081/237] monitoring: Add columns the to host status query required by the tactical overview refs #9009 --- .../library/Monitoring/Backend/Ido/Query/HoststatusQuery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 79a8e9e60..7b0219f89 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -57,6 +57,7 @@ class HoststatusQuery extends IdoQuery 'host_hard_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END', 'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', 'host_is_flapping' => 'hs.is_flapping', + 'host_is_passive_checked' => 'CASE WHEN hs.active_checks_enabled = 0 AND hs.passive_checks_enabled = 1 THEN 1 ELSE 0 END', 'host_is_reachable' => 'hs.is_reachable', 'host_last_check' => 'UNIX_TIMESTAMP(hs.last_check)', 'host_last_hard_state' => 'hs.last_hard_state', From 2b3acc99e29215a9f5fc9121684cd1ae9c068731 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 12:42:27 +0200 Subject: [PATCH 082/237] monitoring: Use host and service status queries in the status summary query refs #9009 --- .../Backend/Ido/Query/StatusSummaryQuery.php | 234 ++++++++++-------- 1 file changed, 129 insertions(+), 105 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php index af67f832a..df30ba103 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php @@ -3,19 +3,19 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; use Zend_Db_Select; +use Icinga\Data\Filter\Filter; +/** + * Query for host and service status summary + */ class StatusSummaryQuery extends IdoQuery { - protected $subHosts; - - protected $subServices; - + /** + * {@inheritdoc} + */ protected $columnMap = array( - 'services' => array( - 'service_host_name' => 'so.name1', - 'service_description' => 'so.name2', - ), 'hoststatussummary' => array( 'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)', 'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)', @@ -23,13 +23,13 @@ class StatusSummaryQuery extends IdoQuery 'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)', 'hosts_pending_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)', - 'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)', + 'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)', 'hosts_down_passive' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'hosts_down_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)', - 'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)', 'hosts_unreachable_passive' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'hosts_unreachable_not_checked' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'hosts_active' => 'SUM(CASE WHEN object_type = \'host\' AND is_active_checked = 1 THEN 1 ELSE 0 END)', @@ -43,25 +43,25 @@ class StatusSummaryQuery extends IdoQuery 'servicestatussummary' => array( 'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)', 'services_problem' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 THEN 1 ELSE 0 END)', - 'services_problem_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)', - 'services_problem_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)', + 'services_problem_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND handled + host_problem > 0 THEN 1 ELSE 0 END)', + 'services_problem_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state > 0 AND handled + host_problem = 0 THEN 1 ELSE 0 END)', 'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)', 'services_ok_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)', 'services_pending_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)', - 'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)', - 'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)', + 'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_problem > 0 THEN 1 ELSE 0 END)', + 'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND handled + host_problem = 0 THEN 1 ELSE 0 END)', 'services_warning_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_warning_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)', - 'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)', - 'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)', + 'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_problem > 0 THEN 1 ELSE 0 END)', + 'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND handled + host_problem = 0 THEN 1 ELSE 0 END)', 'services_critical_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_critical_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)', - 'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_problem > 0 THEN 1 ELSE 0 END)', - 'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_problem = 0 THEN 1 ELSE 0 END)', + 'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_problem > 0 THEN 1 ELSE 0 END)', + 'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND handled + host_problem = 0 THEN 1 ELSE 0 END)', 'services_unknown_passive' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_unknown_not_checked' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_active' => 'SUM(CASE WHEN object_type = \'service\' AND is_active_checked = 1 THEN 1 ELSE 0 END)', @@ -85,114 +85,138 @@ We have to find a better solution here. 'services_ok_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_pending_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 99 THEN 1 ELSE 0 END)', 'services_pending_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_warning_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_warning_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_warning_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_warning_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)', 'services_warning_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_warning_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_critical_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_critical_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_critical_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_critical_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)', 'services_critical_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_critical_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_unknown_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_unknown_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_unknown_handled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_unknown_unhandled_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND handled = 0 THEN 1 ELSE 0 END)', 'services_unknown_passive_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_unknown_not_checked_on_ok_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 1 AND host_state != 2 AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_ok_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 0 THEN 1 ELSE 0 END)', 'services_ok_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 0 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', 'services_pending_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 99 THEN 1 ELSE 0 END)', 'services_pending_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 99 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_warning_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_warning_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_warning_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_warning_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND handled = 0 THEN 1 ELSE 0 END)', 'services_warning_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_warning_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 1 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_critical_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_critical_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_critical_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_critical_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND handled = 0 THEN 1 ELSE 0 END)', 'services_critical_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_critical_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 2 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)', - 'services_unknown_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND acknowledged + in_downtime > 0 THEN 1 ELSE 0 END)', - 'services_unknown_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)', + 'services_unknown_handled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND handled > 0 THEN 1 ELSE 0 END)', + 'services_unknown_unhandled_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND handled = 0 THEN 1 ELSE 0 END)', 'services_unknown_passive_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND is_passive_checked = 1 THEN 1 ELSE 0 END)', 'services_unknown_not_checked_on_problem_hosts' => 'SUM(CASE WHEN object_type = \'service\' AND host_state != 0 AND host_state != 99 AND state = 3 AND is_active_checked = 0 AND is_passive_checked = 0 THEN 1 ELSE 0 END)' ) ); - protected function joinBaseTables() + /** + * The union + * + * @var Zend_Db_Select + */ + protected $summaryQuery; + + /** + * Subqueries used for the summary query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) { - $hosts = $this->db->select()->from( - array('ho' => $this->prefix . 'objects'), - array() - )->join( - array('hs' => $this->prefix . 'hoststatus'), - 'ho.object_id = hs.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', - array( - '' - ) - )->join( - array('h' => $this->prefix . 'hosts'), - 'hs.host_object_id = h.host_object_id', - array() - ); - $services = clone $hosts; - $services->join( - array('s' => $this->prefix . 'services'), - 's.host_object_id = h.host_object_id', - array() - )->join( - array('so' => $this->prefix . 'objects'), - 'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1', - array() - )->joinLeft( - array('ss' => $this->prefix . 'servicestatus'), - 'so.' . $this->object_id . ' = ss.service_object_id', - array() - ); - $hosts->columns(array( - 'state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', - 'acknowledged' => 'hs.problem_has_been_acknowledged', - 'in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', - 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', - 'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END', - 'is_passive_checked' => 'CASE WHEN hs.active_checks_enabled = 0 AND hs.passive_checks_enabled = 1 THEN 1 ELSE 0 END', - 'is_active_checked' => 'hs.active_checks_enabled', - 'is_processing_events' => 'hs.event_handler_enabled', - 'is_triggering_notifications' => 'hs.notifications_enabled', - 'is_allowed_to_flap' => 'hs.flap_detection_enabled', - 'is_flapping' => 'hs.is_flapping', - 'object_type' => '(\'host\')' - )); - $services->columns(array( - 'state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END', - 'acknowledged' => 'ss.problem_has_been_acknowledged', - 'in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END', - 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END', - 'host_problem' => 'CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END', - 'is_passive_checked' => 'CASE WHEN ss.active_checks_enabled = 0 AND ss.passive_checks_enabled = 1 THEN 1 ELSE 0 END', - 'is_active_checked' => 'ss.active_checks_enabled', - 'is_processing_events' => 'ss.event_handler_enabled', - 'is_triggering_notifications' => 'ss.notifications_enabled', - 'is_allowed_to_flap' => 'ss.flap_detection_enabled', - 'is_flapping' => 'ss.is_flapping', - 'object_type' => '(\'service\')' - )); - $union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); - $this->subHosts = $hosts; - $this->subServices = $services; - $this->select->from(array('statussummary' => $union), array()); - $this->joinedVirtualTables = array( - 'services' => true, - 'servicestatussummary' => true, - 'hoststatussummary' => true - ); + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; } - public function whereToSql($col, $sign, $expression) + /** + * {@inheritdoc} + */ + protected function joinBaseTables() { - if ($col === 'so.name1') { - $this->subServices->where('so.name1 ' . $sign . ' ?', $expression); - return ''; - return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); + // TODO(el): Allow to switch between hard and soft states + $hosts = $this->createSubQuery( + 'Hoststatus', + array( + 'handled' => 'host_handled', + 'hostgroup_alias', + 'hostgroup_name', + 'host_problem', + 'host_state' => new Zend_Db_Expr('NULL'), + 'is_active_checked' => 'host_active_checks_enabled', + 'is_allowed_to_flap' => 'host_flap_detection_enabled', + 'is_flapping' => 'host_is_flapping', + 'is_passive_checked' => 'host_is_passive_checked', + 'is_processing_events' => 'host_event_handler_enabled', + 'is_triggering_notifications' => 'host_notifications_enabled', + 'object_type', + 'severity' => 'host_severity', + 'state_change' => 'host_last_state_change', + 'state' => 'host_state' + ) + ); + $this->subQueries[] = $hosts; + $services = $this->createSubQuery( + 'Servicestatus', + array( + 'handled' => 'service_handled', + 'hostgroup_alias', + 'hostgroup_name', + 'host_problem', + 'host_state' => 'host_hard_state', + 'is_active_checked' => 'service_active_checks_enabled', + 'is_allowed_to_flap' => 'service_flap_detection_enabled', + 'is_flapping' => 'service_is_flapping', + 'is_passive_checked' => 'service_is_passive_checked', + 'is_processing_events' => 'service_event_handler_enabled', + 'is_triggering_notifications' => 'service_notifications_enabled', + 'object_type', + 'severity' => 'service_severity', + 'state_change' => 'service_last_state_change', + 'state' => 'service_state' + ) + ); + $this->subQueries[] = $services; + $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); + $this->select->from(array('statussummary' => $this->summaryQuery), array()); + $this->joinedVirtualTables['hoststatussummary'] = true; + $this->joinedVirtualTables['servicestatussummary'] = true; + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + if (! $this->hasAliasName($columnOrAlias)) { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; } } From 45d883dcf1a23f119bb4530a4463d3340a4e20b5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 12:42:55 +0200 Subject: [PATCH 083/237] monitoring: Add restrictable filter columns to the status summary refs #9009 --- Reftest.php | 23 ++++++++++++++++ .../Monitoring/DataView/StatusSummary.php | 27 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Reftest.php diff --git a/Reftest.php b/Reftest.php new file mode 100644 index 000000000..511f3452d --- /dev/null +++ b/Reftest.php @@ -0,0 +1,23 @@ +getFilters() as $key => &$value) { + $value = 1; + } + } + + public function &getFilters() + { + return $this->filters; + } +} + +$x = new Test(); +$b =& $x->getFilters(); +$b[1] = 0; +var_dump($b, $x->getFilters());die; diff --git a/modules/monitoring/library/Monitoring/DataView/StatusSummary.php b/modules/monitoring/library/Monitoring/DataView/StatusSummary.php index 6136ac05c..e725f76d1 100644 --- a/modules/monitoring/library/Monitoring/DataView/StatusSummary.php +++ b/modules/monitoring/library/Monitoring/DataView/StatusSummary.php @@ -96,4 +96,31 @@ class StatusSummary extends DataView 'services_unknown_not_checked_on_problem_hosts' ); } + + /** + * {@inheritdoc} + */ + public function getFilterColumns() + { + return array( + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); + } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return in_array($column, $this->getFilterColumns()); + } + } } From b7afec8f3ced67c5c2d617c7f503d93423e13015 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 12:43:24 +0200 Subject: [PATCH 084/237] monitoring: Restrict the tactical overview refs #9009 --- .../application/controllers/TacticalController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/TacticalController.php b/modules/monitoring/application/controllers/TacticalController.php index d9da6d3d5..95440a309 100644 --- a/modules/monitoring/application/controllers/TacticalController.php +++ b/modules/monitoring/application/controllers/TacticalController.php @@ -20,8 +20,7 @@ class Monitoring_TacticalController extends MonitoringController 'url' => Url::fromRequest() ) )->extend(new DashboardAction())->activate('tactical_overview'); - - $this->view->statusSummary = $this->backend->select()->from( + $stats = $this->backend->select()->from( 'statusSummary', array( 'hosts_up', @@ -79,6 +78,8 @@ class Monitoring_TacticalController extends MonitoringController 'hosts_flapping', 'services_flapping' ) - )->getQuery()->fetchRow(); + ); + $this->applyRestriction('monitoring/filter/objects', $stats); + $this->view->statusSummary = $stats->fetchRow(); } } From f3b84b7ae8d84f7d7b7cfadadd5d7d24b8298588 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:14:22 +0200 Subject: [PATCH 085/237] monitoring: Restrict service summary when viewing a host or service refs #9009 --- .../library/Monitoring/Object/MonitoredObject.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 626b5cd3d..4ff6ae6c9 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -479,12 +479,9 @@ abstract class MonitoredObject implements Filterable */ public function fetchStats() { - $this->stats = $this->backend->select()->from('statusSummary', array( + $this->stats = $this->backend->select()->from('servicestatussummary', array( 'services_total', 'services_ok', - 'services_problem', - 'services_problem_handled', - 'services_problem_unhandled', 'services_critical', 'services_critical_unhandled', 'services_critical_handled', @@ -497,7 +494,7 @@ abstract class MonitoredObject implements Filterable 'services_pending', )) ->where('service_host_name', $this->host_name) - ->getQuery() + ->applyFilter($this->getFilter()) ->fetchRow(); return $this; } From 52a0ad363f2a9e4ce26c64c63ac1327bd5668aec Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:40:17 +0200 Subject: [PATCH 086/237] monitoring: Remove unnecessary group call in the host comment query refs #9009 --- .../Backend/Ido/Query/HostcommentQuery.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index aafd7dbae..fa80ec18f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -31,16 +31,16 @@ class HostcommentQuery extends IdoQuery 'object_type' => '(\'host\')' ), 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' ), 'hosts' => array( 'host_alias' => 'h.alias', 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' ), 'hoststatus' => array( - 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' ), 'servicegroups' => array( 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', @@ -48,9 +48,9 @@ class HostcommentQuery extends IdoQuery 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'services' => array( - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_description' => 'so.name2', - 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', ) ); @@ -154,7 +154,6 @@ class HostcommentQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->group('ho.name1'); } /** From c735ee799c1af3e7d01f36b3bfb5de7b70ef4e57 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:41:25 +0200 Subject: [PATCH 087/237] monitoring: Remove unnecessary group call in the host downtime query refs #9009 --- .../Backend/Ido/Query/HostdowntimeQuery.php | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index 91fe488d3..0e2b503d8 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -37,26 +37,26 @@ class HostdowntimeQuery extends IdoQuery 'object_type' => '(\'host\')' ), 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' ), 'hosts' => array( - 'host_alias' => 'h.alias', - 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' ), 'hoststatus' => array( - 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' + 'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END' ), 'servicegroups' => array( - 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', - 'servicegroup_name' => 'sgo.name1', - 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'services' => array( - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_description' => 'so.name2', - 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', ) ); @@ -160,7 +160,6 @@ class HostdowntimeQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->group('ho.name1'); } /** From bbcd6e3a2b802887202f343562f01356689e9376 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:42:11 +0200 Subject: [PATCH 088/237] monitoring: Support restricting host groups of a host refs #9009 --- .../Backend/Ido/Query/HostgroupQuery.php | 132 ++++++++++++++++-- .../library/Monitoring/DataView/Hostgroup.php | 39 +++--- 2 files changed, 142 insertions(+), 29 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php index d41a9e00b..a9b8ec815 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php @@ -3,21 +3,49 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query for host groups + */ class HostgroupQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( 'hostgroups' => array( - 'hostgroups' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1', - 'hostgroup_alias' => 'hg.alias', - 'hostgroup_id' => 'hg.hostgroup_id' + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hostobjects' => array( + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1' ), 'hosts' => array( - 'host' => 'ho.name1 COLLATE latin1_general_ci', - 'host_name' => 'ho.name1' + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' ) ); + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { $this->select->from( @@ -25,13 +53,23 @@ class HostgroupQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hg.hostgroup_object_id = hgo.' . $this->object_id . ' AND hgo.is_active = 1', + 'hgo.object_id = hg.hostgroup_object_id', array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 ); - $this->joinedVirtualTables = array('hostgroups' => true); + $this->joinedVirtualTables['hostgroups'] = true; } - protected function joinHosts() + /** + * Join host objects + */ + protected function joinHostobjects() { $this->select->join( array('hgm' => $this->prefix . 'hostgroup_members'), @@ -39,8 +77,82 @@ class HostgroupQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'hgm.host_object_id = ho.object_id AND ho.is_active = 1', + 'hgm.host_object_id = ho.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + ) + ->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->group('hgo.name1'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('hostobjects'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', array() ); } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->requireVirtualTable('hosts'); + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = h.host_object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id AND so.is_active = 1', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->group('hgo.name1'); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroup.php b/modules/monitoring/library/Monitoring/DataView/Hostgroup.php index c139d8977..ed4a8bd96 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroup.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroup.php @@ -4,44 +4,45 @@ namespace Icinga\Module\Monitoring\DataView; /** - * View for hostgroups + * Host group data view */ class Hostgroup extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} */ public function getColumns() { return array( - 'hostgroup_name', 'hostgroup_alias', - 'hostgroup_id', - 'host_name' + 'hostgroup_name' ); } /** - * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort - * - * @return array + * {@inheritdoc} */ - public function getSortRules() + public function getFilterColumns() { return array( - 'hostgroup_name' => array( - 'order' => self::SORT_ASC - ), - 'hostgroup_alias' => array( - 'order' => self::SORT_ASC - ) + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } - public function getFilterColumns() + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) { - return array('hostgroup', 'host'); + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return parent::isValidFilterTarget($column); + } } } From 80c80436cfa24308f362bc7747d08d2838f66fbf Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:42:49 +0200 Subject: [PATCH 089/237] monitoring: Support restricting service groups of a service refs #9009 --- .../Backend/Ido/Query/ServicegroupQuery.php | 111 ++++++++++++++++-- .../Monitoring/DataView/Servicegroup.php | 40 ++++--- 2 files changed, 119 insertions(+), 32 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php index 125c07005..731a9994c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php @@ -5,21 +5,43 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; class ServicegroupQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci', + ), 'servicegroups' => array( - 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', - 'servicegroup_name' => 'sgo.name1', - 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1' + ), + 'serviceobjects' => array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2' ), 'services' => array( - 'host' => 'so.name1 COLLATE latin1_general_ci', - 'host_name' => 'so.name1', - 'service' => 'so.name2 COLLATE latin1_general_ci', - 'service_host_name' => 'so.name1', - 'service_description' => 'so.name2' + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', ) ); + /** + * {@inheritdoc} + */ protected function joinBaseTables() { $this->select->from( @@ -27,15 +49,64 @@ class ServicegroupQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sg.servicegroup_object_id = sgo.' . $this->object_id - . ' AND sgo.is_active = 1', + 'sg.servicegroup_object_id = sgo.object_id', array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 ); - $this->joinedVirtualTables = array('servicegroups' => true); } - protected function joinServices() + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service objects + */ + protected function joinServiceobjects() { $this->select->join( array('sgm' => $this->prefix . 'servicegroup_members'), @@ -43,7 +114,21 @@ class ServicegroupQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'sgm.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1', + 'sgm.service_object_id = so.object_id', + array() + ); + $this->group('sgo.name1'); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->requireVirtualTable('serviceobjects'); + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', array() ); } diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroup.php b/modules/monitoring/library/Monitoring/DataView/Servicegroup.php index 82feabd88..a428caded 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroup.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroup.php @@ -3,43 +3,45 @@ namespace Icinga\Module\Monitoring\DataView; +/** + * Service group view */ class Servicegroup extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} */ public function getColumns() { return array( - 'servicegroup_name', 'servicegroup_alias', - 'host_name', - 'service_host_name', - 'service_description' + 'servicegroup_name' ); } /** - * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort - * - * @return array + * {@inheritdoc} */ - public function getSortRules() + public function getFilterColumns() { return array( - 'servicegroup_name' => array( - 'order' => self::SORT_ASC - ), - 'servicegroup_alias' => array( - 'order' => self::SORT_ASC - ) + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup' ); } - public function getFilterColumns() + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) { - return array('servicegroup', 'host', 'service'); + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } else { + return parent::isValidFilterTarget($column); + } } } From d830480655bac65ebb69582d6cea1cf6ddfa04a2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:43:38 +0200 Subject: [PATCH 090/237] monitoring: Add missing restrictable columns to host and service comments and downtimes refs #9009 --- .../Monitoring/DataView/Hostcomment.php | 32 ++++++++++--------- .../Monitoring/DataView/Hostdowntime.php | 32 ++++++++++--------- .../Monitoring/DataView/Servicecomment.php | 32 ++++++++++--------- .../Monitoring/DataView/Servicedowntime.php | 32 ++++++++++--------- 4 files changed, 68 insertions(+), 60 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hostcomment.php b/modules/monitoring/library/Monitoring/DataView/Hostcomment.php index b751a82b9..d1afbdd74 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostcomment.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostcomment.php @@ -8,19 +8,6 @@ namespace Icinga\Module\Monitoring\DataView; */ class Hostcomment extends DataView { - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_(?:host|service)_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - /** * {@inheritdoc} */ @@ -47,8 +34,23 @@ class Hostcomment extends DataView public function getFilterColumns() { return array( - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php b/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php index f95f82da2..3b1c901b5 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostdowntime.php @@ -8,19 +8,6 @@ namespace Icinga\Module\Monitoring\DataView; */ class Hostdowntime extends DataView { - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_(?:host|service)_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - /** * {@inheritdoc} */ @@ -52,8 +39,23 @@ class Hostdowntime extends DataView public function getFilterColumns() { return array( - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Servicecomment.php b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php index 64d193cfa..b3d11ad49 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicecomment.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicecomment.php @@ -8,19 +8,6 @@ namespace Icinga\Module\Monitoring\DataView; */ class Servicecomment extends DataView { - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_(?:host|service)_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - /** * {@inheritdoc} */ @@ -50,8 +37,23 @@ class Servicecomment extends DataView public function getFilterColumns() { return array( - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php b/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php index 1969aec44..0f14857d4 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicedowntime.php @@ -5,19 +5,6 @@ namespace Icinga\Module\Monitoring\DataView; class Servicedowntime extends DataView { - /** - * {@inheritdoc} - */ - public function isValidFilterTarget($column) - { - if ($column[0] === '_' - && preg_match('/^_(?:host|service)_/', $column) - ) { - return true; - } - return parent::isValidFilterTarget($column); - } - /** * {@inheritdoc} */ @@ -52,8 +39,23 @@ class Servicedowntime extends DataView public function getFilterColumns() { return array( - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } + + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } } From 5745790cdd70e5741afba9949ce75e08754c745d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:44:03 +0200 Subject: [PATCH 091/237] monitoring: Use new restriction when viewing a host refs #9009 --- modules/monitoring/application/controllers/HostController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index 464da200c..c006bbe8f 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -26,7 +26,7 @@ class Monitoring_HostController extends MonitoredObjectController { $host = new Host($this->backend, $this->params->getRequired('host')); - $this->applyRestriction('monitoring/hosts/filter', $host); + $this->applyRestriction('monitoring/filter/objects', $host); if ($host->fetch() === false) { $this->httpNotFound($this->translate('Host not found')); From 5bc611f7722ad2595fc52cacaeee011801880002 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:44:35 +0200 Subject: [PATCH 092/237] monitoring: Use new restriction when viewing a service refs #9009 --- .../monitoring/application/controllers/ServiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ServiceController.php b/modules/monitoring/application/controllers/ServiceController.php index 2886650c9..d9ed0d36b 100644 --- a/modules/monitoring/application/controllers/ServiceController.php +++ b/modules/monitoring/application/controllers/ServiceController.php @@ -28,7 +28,7 @@ class Monitoring_ServiceController extends MonitoredObjectController $this->backend, $this->params->getRequired('host'), $this->params->getRequired('service') ); - $this->applyRestriction('monitoring/services/filter', $service); + $this->applyRestriction('monitoring/filter/objects', $service); if ($service->fetch() === false) { $this->httpNotFound($this->translate('Service not found')); From dae35b9106a7cc7cb8e68cb4a8a1a2c8e981b828 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 14:47:01 +0200 Subject: [PATCH 093/237] monitoring: Restrict host and service groups when viewing a host or service refs #9009 --- .../Monitoring/Object/MonitoredObject.php | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 4ff6ae6c9..a569341f6 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -308,12 +308,11 @@ abstract class MonitoredObject implements Filterable */ public function fetchHostgroups() { - $hostGroups = $this->backend->select()->from('hostgroup', array( - 'hostgroup_name', - 'hostgroup_alias' - )) - ->where('host_name', $this->host); - $this->hostgroups = $hostGroups->getQuery()->fetchPairs(); + $this->hostgroups = $this->backend->select() + ->from('hostgroup', array('hostgroup_name', 'hostgroup_alias')) + ->where('host_name', $this->host_name) + ->applyFilter($this->filter) + ->fetchPairs(); return $this; } @@ -407,13 +406,12 @@ abstract class MonitoredObject implements Filterable */ public function fetchServicegroups() { - $serviceGroups = $this->backend->select()->from('servicegroup', array( - 'servicegroup_name', - 'servicegroup_alias' - )) - ->where('service_host_name', $this->host_name) - ->where('service_description', $this->service_description); - $this->servicegroups = $serviceGroups->getQuery()->fetchPairs(); + $this->servicegroups = $this->backend->select() + ->from('servicegroup', array('servicegroup_name', 'servicegroup_alias')) + ->where('host_name', $this->host_name) + ->where('service_description', $this->service_description) + ->applyFilter($this->getFilter()) + ->fetchPairs(); return $this; } From 2e059a9bb7e12d96f7262f12043db52da0f01213 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:00:14 +0200 Subject: [PATCH 094/237] monitoring: Use soft states in the host group summary again refs #9009 --- .../Backend/Ido/Query/HostgroupsummaryQuery.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php index 045682cd6..7688d9292 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php @@ -92,8 +92,8 @@ class HostgroupsummaryQuery extends IdoQuery 'hostgroup_name', 'object_type', 'severity' => 'host_severity', - 'state' => 'host_hard_state', - 'state_change' => 'host_last_hard_state_change' + 'state' => 'host_state', + 'state_change' => 'host_last_state_change' ) ); $this->subQueries[] = $hosts; @@ -106,8 +106,8 @@ class HostgroupsummaryQuery extends IdoQuery 'hostgroup_name', 'object_type', 'severity' => new Zend_Db_Expr('NULL'), - 'state' => 'service_hard_state', - 'state_change' => 'service_last_hard_state_change' + 'state' => 'service_state', + 'state_change' => 'service_last_state_change' ) ); $this->subQueries[] = $services; From 4dc2eb9f4a2a0f1c240b274b379505798df34781 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:01:08 +0200 Subject: [PATCH 095/237] monitoring: Use soft states in the host status summary query again refs #9009 --- .../Backend/Ido/Query/HoststatussummaryQuery.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php index aed8c20ea..da065d184 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatussummaryQuery.php @@ -16,12 +16,12 @@ class HoststatussummaryQuery extends IdoQuery protected $columnMap = array( 'hoststatussummary' => array( 'hosts_down' => 'SUM(CASE WHEN state = 1 THEN 1 ELSE 0 END)', - 'hosts_down_handled' => 'SUM(CASE WHEN state = 1 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_down_handled' => 'SUM(CASE WHEN state = 1 AND handled = 1 THEN 1 ELSE 0 END)', 'hosts_down_unhandled' => 'SUM(CASE WHEN state = 1 AND handled = 0 THEN 1 ELSE 0 END)', 'hosts_pending' => 'SUM(CASE WHEN state = 99 THEN 1 ELSE 0 END)', 'hosts_total' => 'SUM(1)', 'hosts_unreachable' => 'SUM(CASE WHEN state = 2 THEN 1 ELSE 0 END)', - 'hosts_unreachable_handled' => 'SUM(CASE WHEN state = 2 AND handled != 0 THEN 1 ELSE 0 END)', + 'hosts_unreachable_handled' => 'SUM(CASE WHEN state = 2 AND handled = 1 THEN 1 ELSE 0 END)', 'hosts_unreachable_unhandled' => 'SUM(CASE WHEN state = 2 AND handled = 0 THEN 1 ELSE 0 END)', 'hosts_up' => 'SUM(CASE WHEN state = 0 THEN 1 ELSE 0 END)' ) @@ -53,8 +53,8 @@ class HoststatussummaryQuery extends IdoQuery 'Hoststatus', array( 'handled' => 'host_handled', - 'state' => 'host_hard_state', - 'state_change' => 'host_last_hard_state_change' + 'state' => 'host_state', + 'state_change' => 'host_last_state_change' ) ); $this->select->from( From 3425b71b4d6062bb80b0942a6bce76bb8c82f3a7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:01:45 +0200 Subject: [PATCH 096/237] monitoring: Restrict problem badges The code should be placed somewhere else in the future. refs #9009 --- .../Web/Menu/MonitoringMenuItemRenderer.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php index 80ffb3d9c..c32c155af 100644 --- a/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php +++ b/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php @@ -3,7 +3,10 @@ namespace Icinga\Module\Monitoring\Web\Menu; -use Icinga\Web\Menu as Menu; +use Icinga\Authentication\Manager; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filterable; +use Icinga\Web\Menu; use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Web\Menu\MenuItemRenderer; @@ -13,16 +16,36 @@ class MonitoringMenuItemRenderer extends MenuItemRenderer protected $columns = array(); + /** + * Apply a restriction on the given data view + * + * @param string $restriction The name of restriction + * @param Filterable $filterable The filterable to restrict + * + * @return Filterable The filterable + */ + protected static function applyRestriction($restriction, Filterable $filterable) + { + $restrictions = Filter::matchAny(); + foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) { + $restrictions->addFilter(Filter::fromQueryString($filter)); + } + $filterable->applyFilter($restrictions); + return $filterable; + } + protected static function summary($column = null) { if (self::$summary === null) { - self::$summary = MonitoringBackend::instance()->select()->from( + $summary = MonitoringBackend::instance()->select()->from( 'statusSummary', array( 'hosts_down_unhandled', 'services_critical_unhandled' ) - )->getQuery()->fetchRow(); + ); + static::applyRestriction('monitoring/filter/objects', $summary); + self::$summary = $summary->fetchRow(); } if ($column === null) { From 1d775842f9481c183190603e5e03f4624e6c9666 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:06:34 +0200 Subject: [PATCH 097/237] monitoring: Restrict the service grid refs #9009 --- modules/monitoring/application/controllers/ListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 9e5ac6d33..4337b9f61 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -602,6 +602,7 @@ class Monitoring_ListController extends Controller 'service_handled' )); $this->filterQuery($query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->setupSortControl(array( 'host_name' => $this->translate('Hostname'), 'service_description' => $this->translate('Service description') From 66d76e7ad92ce38971763bc650c31de91f0e9a81 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:30:49 +0200 Subject: [PATCH 098/237] monitoring: Add host_notes to the host status query refs #9009 --- .../library/Monitoring/Backend/Ido/Query/HoststatusQuery.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 7b0219f89..72f336075 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -31,6 +31,7 @@ class HoststatusQuery extends IdoQuery 'host_icon_image_alt' => 'h.icon_image_alt', 'host_ipv4' => 'INET_ATON(h.address)', 'host_name' => 'ho.name1', + 'host_notes' => 'h.notes', 'host_notes_url' => 'h.notes_url', 'object_type' => '(\'host\')' ), From 6597e7aba819ec1ca13c1812b0ad979eaa8a2678 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:48:05 +0200 Subject: [PATCH 099/237] monitoring: Add missing restrictable filter columns to the comment data view refs #9009 --- modules/monitoring/library/Monitoring/DataView/Comment.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Comment.php b/modules/monitoring/library/Monitoring/DataView/Comment.php index 9d7aa612e..e1beaabf8 100644 --- a/modules/monitoring/library/Monitoring/DataView/Comment.php +++ b/modules/monitoring/library/Monitoring/DataView/Comment.php @@ -50,8 +50,10 @@ class Comment extends DataView { return array( 'comment_author ', - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } From bb711f447d6e11308cabb65fa9658bd7fe53bc12 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:48:37 +0200 Subject: [PATCH 100/237] monitoring: Fix restrictable filter columns of the downtime view refs #9009 --- modules/monitoring/library/Monitoring/DataView/Downtime.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php index c654716ba..29114180c 100644 --- a/modules/monitoring/library/Monitoring/DataView/Downtime.php +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -55,8 +55,10 @@ class Downtime extends DataView { return array( 'downtime_author', - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } From d4b0841d4c5086e2c32891db3e12c6da25fdf91e Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:48:58 +0200 Subject: [PATCH 101/237] monitoring: Add missing filter column to the host group summary view refs #9009 --- .../monitoring/library/Monitoring/DataView/Hostgroupsummary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php index b576c685b..941f6dfbe 100644 --- a/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Hostgroupsummary.php @@ -50,7 +50,7 @@ class Hostgroupsummary extends DataView 'hosts_severity', 'host', 'host_alias', 'host_display_name', 'host_name', 'hostgroup', - 'service', 'service_description', + 'service', 'service_description', 'service_display_name', 'servicegroup', 'servicegroup_alias', 'servicegroup_name' ); } From 382007a8bd5bc32fb82edab7261c0dee6d60556a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:49:26 +0200 Subject: [PATCH 102/237] monitoring: Add missing filter columns to the service status data view refs #9009 --- .../monitoring/library/Monitoring/DataView/ServiceStatus.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php index 20f61d515..2674bbfb6 100644 --- a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php @@ -166,10 +166,12 @@ class ServiceStatus extends DataView return array( 'host', 'hostgroup', + 'hostgroup_alias', 'hostgroup_name', 'service', 'service_host', 'servicegroup', + 'servicegroup_alias', 'servicegroup_name' ); } From d4a884b233432e7abd0952eba99b1df084fcdda2 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:49:48 +0200 Subject: [PATCH 103/237] monitoring: Fix filter columns of the service group summary refs #9009 --- .../library/Monitoring/DataView/Servicegroupsummary.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php index 290c8f697..795162426 100644 --- a/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Servicegroupsummary.php @@ -43,8 +43,10 @@ class Servicegroupsummary extends DataView { return array( 'services_severity', - 'host', 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', 'servicegroup' + 'host', 'host_alias', 'host_display_name', 'host_name', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup' ); } From 6c07a4842b7d327235de605f2a2f3dd6b9fedb04 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 5 Jun 2015 15:50:11 +0200 Subject: [PATCH 104/237] monitoring: Fix controller function fetchHostStats() refs #9009 --- .../monitoring/application/controllers/ShowController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index 538a75132..cf71c7d32 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -80,12 +80,9 @@ class Monitoring_ShowController extends Controller protected function fetchHostStats() { - $this->view->stats = $this->backend->select()->from('statusSummary', array( + $this->view->stats = $this->backend->select()->from('servicestatussummary', array( 'services_total', 'services_ok', - 'services_problem', - 'services_problem_handled', - 'services_problem_unhandled', 'services_critical', 'services_critical_unhandled', 'services_critical_handled', From c0ffe4d6908c9d31339f46efabdac41f444afbc2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 17:07:34 +0200 Subject: [PATCH 105/237] Introduce class HostnotificationQuery refs #9009 --- .../Ido/Query/HostnotificationQuery.php | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php new file mode 100644 index 000000000..78a6f53af --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -0,0 +1,202 @@ + array( + 'notification_output' => 'hn.output', + 'notification_start_time' => 'UNIX_TIMESTAMP(hn.start_time)', + 'notification_state' => 'hn.state', + 'notification_object_id' => 'hn.object_id', + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'contactnotifications' => array( + 'contact' => 'cno.name1 COLLATE latin1_general_ci', + 'notification_contact_name' => 'cno.name1', + 'contact_object_id' => 'cno.object_id' + ), + 'acknowledgements' => array( + 'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)', + 'acknowledgement_author_name' => 'a.author_name', + 'acknowledgement_comment_data' => 'a.comment_data' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('hn' => $this->prefix . 'notifications'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = hn.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->joinedVirtualTables['notifications'] = true; + } + + /** + * Join contact notifications + */ + protected function joinContactnotifications() + { + $this->select->join( + array('cn' => $this->prefix . 'contactnotifications'), + 'cn.notification_id = hn.notification_id', + array() + ); + $this->select->join( + array('cno' => $this->prefix . 'objects'), + 'cno.object_id = cn.contact_object_id', + array() + ); + } + + /** + * Join acknowledgements + */ + protected function joinAcknowledgements() + { + $this->select->joinLeft( + array('a' => $this->prefix . 'acknowledgements'), + 'a.object_id = hn.object_id', + array() + ); + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->group(array('hn.notification_id', 'ho.name1')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = h.host_object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->group(array('hn.notification_id', 'ho.name1')); + } +} From 70e3434f331d330457919c6258859b623b8eb2e1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 17:07:55 +0200 Subject: [PATCH 106/237] Introduce class ServicenotificationQuery refs #9009 --- .../Ido/Query/ServicenotificationQuery.php | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php new file mode 100644 index 000000000..aaf3d57bc --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -0,0 +1,194 @@ + array( + 'notification_output' => 'sn.output', + 'notification_start_time' => 'UNIX_TIMESTAMP(sn.start_time)', + 'notification_state' => 'sn.state', + 'notification_object_id' => 'sn.object_id', + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'contactnotifications' => array( + 'contact' => 'cno.name1 COLLATE latin1_general_ci', + 'notification_contact_name' => 'cno.name1', + 'contact_object_id' => 'cno.object_id' + ), + 'acknowledgements' => array( + 'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)', + 'acknowledgement_author_name' => 'a.author_name', + 'acknowledgement_comment_data' => 'a.comment_data' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ) + ); + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sn' => $this->prefix . 'notifications'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = sn.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + $this->joinedVirtualTables['notifications'] = true; + } + + /** + * Join contact notifications + */ + protected function joinContactnotifications() + { + $this->select->join( + array('cn' => $this->prefix . 'contactnotifications'), + 'cn.notification_id = sn.notification_id', + array() + ); + $this->select->join( + array('cno' => $this->prefix . 'objects'), + 'cno.object_id = cn.contact_object_id', + array() + ); + } + + /** + * Join acknowledgements + */ + protected function joinAcknowledgements() + { + $this->select->joinLeft( + array('a' => $this->prefix . 'acknowledgements'), + 'a.object_id = sn.object_id', + array() + ); + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } +} From 9229e460d19bcbc19a1ebe07784760344a553889 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 17:09:24 +0200 Subject: [PATCH 107/237] NotificationQuery: Use subqueries to fetch host- and service-notifications refs #9009 --- .../Backend/Ido/Query/NotificationQuery.php | 195 +++++++++--------- .../Monitoring/DataView/Notification.php | 55 ++++- 2 files changed, 143 insertions(+), 107 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index 0133dc637..ed8a1a911 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -3,136 +3,127 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service notifications + */ class NotificationQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( - 'notification' => array( - 'notification_output' => 'n.output', - 'notification_start_time' => 'UNIX_TIMESTAMP(n.start_time)', - 'notification_state' => 'n.state', - 'notification_object_id' => 'n.object_id' - ), - 'objects' => array( - 'host' => 'o.name1 COLLATE latin1_general_ci', - 'host_name' => 'o.name1', - 'service' => 'o.name2 COLLATE latin1_general_ci', - 'service_description' => 'o.name2' - ), - 'contact' => array( - 'contact' => 'c_o.name1 COLLATE latin1_general_ci', - 'notification_contact_name' => 'c_o.name1', - 'contact_object_id' => 'c_o.object_id' - ), - 'command' => array( - 'notification_command' => 'cmd_o.name1' - ), - 'acknowledgement' => array( - 'acknowledgement_entry_time' => 'UNIX_TIMESTAMP(a.entry_time)', - 'acknowledgement_author_name' => 'a.author_name', - 'acknowledgement_comment_data' => 'a.comment_data' + 'notifications' => array( + 'notification_state' => 'n.notification_state', + 'notification_start_time' => 'n.notification_start_time', + 'notification_contact_name' => 'n.notification_contact_name', + 'notification_output' => 'n.notification_output', + 'notification_object_id' => 'n.notification_object_id', + 'contact_object_id' => 'n.contact_object_id', + 'acknowledgement_entry_time' => 'n.acknowledgement_entry_time', + 'acknowledgement_author_name' => 'n.acknowledgement_author_name', + 'acknowledgement_comment_data' => 'n.acknowledgement_comment_data', + 'object_type' => 'n.object_type' ), 'hosts' => array( - 'host_display_name' => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END' + 'host_display_name' => 'n.host_display_name', + 'host_name' => 'n.host_name' ), 'services' => array( - 'service_display_name' => 's.display_name' + 'service_description' => 'n.service_description', + 'service_display_name' => 'n.service_display_name', + 'service_host_name' => 'n.service_host_name' ) ); /** - * Fetch basic information about notifications + * The union + * + * @var Zend_Db_Select + */ + protected $notificationQuery; + + /** + * Subqueries used for the notification query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} */ protected function joinBaseTables() { + $this->notificationQuery = $this->db->select(); $this->select->from( - array('n' => $this->prefix . 'notifications'), + array('n' => $this->notificationQuery), array() ); - $this->joinedVirtualTables = array('notification' => true); + $this->joinedVirtualTables['notifications'] = true; } /** - * Fetch description of each affected host/service + * Join hosts */ - protected function joinObjects() - { - $this->select->join( - array('o' => $this->prefix . 'objects'), - 'n.object_id = o.object_id AND o.is_active = 1 AND o.objecttype_id IN (1, 2)', - array() - ); - } - - /** - * Fetch name of involved contacts and/or contact groups - */ - protected function joinContact() - { - $this->select->join( - array('c' => $this->prefix . 'contactnotifications'), - 'n.notification_id = c.notification_id', - array() - ); - $this->select->join( - array('c_o' => $this->prefix . 'objects'), - 'c.contact_object_id = c_o.object_id', - array() - ); - } - - /** - * Fetch name of the command which was used to send out a notification - */ - protected function joinCommand() - { - $this->select->join( - array('cmd_c' => $this->prefix . 'contactnotifications'), - 'n.notification_id = cmd_c.notification_id', - array() - ); - $this->select->joinLeft( - array('cmd_m' => $this->prefix . 'contactnotificationmethods'), - 'cmd_c.contactnotification_id = cmd_m.contactnotification_id', - array() - ); - $this->select->joinLeft( - array('cmd_o' => $this->prefix . 'objects'), - 'cmd_m.command_object_id = cmd_o.object_id', - array() - ); - } - - protected function joinAcknowledgement() - { - $this->select->joinLeft( - array('a' => $this->prefix . 'acknowledgements'), - 'n.object_id = a.object_id', - array() - ); - } - protected function joinHosts() { - $this->select->joinLeft( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = o.object_id', - array() + $columns = array_keys($this->columnMap['notifications'] + $this->columnMap['hosts']); + foreach (array_keys($this->columnMap['services']) as $column) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + $hosts = $this->createSubQuery('hostnotification', $columns); + $this->subQueries[] = $hosts; + $this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] ); + $services = $this->createSubQuery('servicenotification', $columns); + $this->subQueries[] = $services; + $this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } return $this; } - protected function joinServices() + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) { - $this->select->joinLeft( - array('s' => $this->prefix . 'services'), - 's.service_object_id = o.object_id', - array() - ); - $this->select->joinLeft( - array('sh' => $this->prefix . 'hosts'), - 'sh.host_object_id = s.host_object_id', - array() - ); + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } return $this; } } diff --git a/modules/monitoring/library/Monitoring/DataView/Notification.php b/modules/monitoring/library/Monitoring/DataView/Notification.php index 48d8fd058..9c06fc2ef 100644 --- a/modules/monitoring/library/Monitoring/DataView/Notification.php +++ b/modules/monitoring/library/Monitoring/DataView/Notification.php @@ -5,6 +5,19 @@ namespace Icinga\Module\Monitoring\DataView; class Notification extends DataView { + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' + && preg_match('/^_(?:host|service)_/', $column) + ) { + return true; + } + return parent::isValidFilterTarget($column); + } + /** * Retrieve columns provided by this view * @@ -13,30 +26,62 @@ class Notification extends DataView public function getColumns() { return array( - 'host_name', - 'service_description', 'notification_state', 'notification_start_time', 'notification_contact_name', 'notification_output', - 'notification_command', + 'notification_object_id', + 'contact_object_id', + 'acknowledgement_entry_time', + 'acknowledgement_author_name', + 'acknowledgement_comment_data', 'host_display_name', - 'service_display_name' + 'host_name', + 'object_type', + 'service_description', + 'service_display_name', + 'service_host_name' ); } + /** + * {@inheritdoc} + */ public function getSortRules() { return array( 'notification_start_time' => array( 'order' => self::SORT_DESC, 'title' => 'Notification Start' + ), + 'host_display_name' => array( + 'columns' => array( + 'host_display_name', + 'service_display_name' + ), + 'order' => self::SORT_ASC + ), + 'service_display_name' => array( + 'columns' => array( + 'service_display_name', + 'host_display_name' + ), + 'order' => self::SORT_ASC ) ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { - return array('host', 'service', 'contact'); + return array( + 'contact', + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } } From 2669d0e478e14c12c50176c65edf55de2ab84542 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 17:10:16 +0200 Subject: [PATCH 108/237] monitoring: Restrict the notification overview refs #9009 --- modules/monitoring/application/controllers/ListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 4337b9f61..3254fcc12 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -295,6 +295,7 @@ class Monitoring_ListController extends Controller 'host_display_name', 'service_display_name' )); + $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); $this->view->notifications = $query; From 75c5aab1b965eb4f1d598acdf6f2984f95282e6f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 17:23:36 +0200 Subject: [PATCH 109/237] NotificationQuery: Do not use a placeholder if it's possible to select a real value refs #9009 --- .../Backend/Ido/Query/HostnotificationQuery.php | 3 ++- .../Monitoring/Backend/Ido/Query/NotificationQuery.php | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 78a6f53af..86930e12e 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -53,7 +53,8 @@ class HostnotificationQuery extends IdoQuery 'services' => array( 'service' => 'so.name2 COLLATE latin1_general_ci', 'service_description' => 'so.name2', - 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' ) ); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index ed8a1a911..f898c8699 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -3,7 +3,6 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; -use Zend_Db_Expr; use Zend_Db_Select; use Icinga\Data\Filter\Filter; @@ -71,10 +70,9 @@ class NotificationQuery extends IdoQuery */ protected function joinHosts() { - $columns = array_keys($this->columnMap['notifications'] + $this->columnMap['hosts']); - foreach (array_keys($this->columnMap['services']) as $column) { - $columns[$column] = new Zend_Db_Expr('NULL'); - } + $columns = array_keys( + $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); $hosts = $this->createSubQuery('hostnotification', $columns); $this->subQueries[] = $hosts; $this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); From 83c21f08e311a55ac0fd57772d9624591159354a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 18:00:54 +0200 Subject: [PATCH 110/237] DowntimeQuery: Fix grouping There was only one downtime for each host or service being fetched. refs #9009 --- .../Monitoring/Backend/Ido/Query/HostdowntimeQuery.php | 4 ++-- .../Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index 0e2b503d8..ec9cd569b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -107,7 +107,7 @@ class HostdowntimeQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group('ho.name1'); + $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); } /** @@ -183,6 +183,6 @@ class HostdowntimeQuery extends IdoQuery 'so.objecttype_id = ?', 2 ); - $this->group('ho.name1'); + $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php index 55b8e466c..6d528ba73 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -112,7 +112,7 @@ class ServicedowntimeQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group(array('so.name2', 'so.name1')); + $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } /** @@ -166,7 +166,7 @@ class ServicedowntimeQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->group(array('so.name2', 'so.name1')); + $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } /** From a4ad4e237204923646417b09b65ebac3510ea8a9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 8 Jun 2015 18:01:16 +0200 Subject: [PATCH 111/237] CommentQuery: Fix grouping There was only one comment for each host or service being fetched. refs #9009 --- .../library/Monitoring/Backend/Ido/Query/HostcommentQuery.php | 4 ++-- .../Monitoring/Backend/Ido/Query/ServicecommentQuery.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index fa80ec18f..080fdd905 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -101,7 +101,7 @@ class HostcommentQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group('ho.name1'); + $this->group(array('c.comment_id', 'ho.name1')); } /** @@ -177,6 +177,6 @@ class HostcommentQuery extends IdoQuery 'so.objecttype_id = ?', 2 ); - $this->group('ho.name1'); + $this->group(array('c.comment_id', 'ho.name1')); } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php index 40b6e805f..005ef0184 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -106,7 +106,7 @@ class ServicecommentQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group(array('so.name2', 'so.name1')); + $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } /** @@ -160,7 +160,7 @@ class ServicecommentQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->group(array('so.name2', 'so.name1')); + $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } /** From db816e4a5cbd51fa5e624d0ed36141df0f072216 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 9 Jun 2015 12:48:15 +0200 Subject: [PATCH 112/237] ServicegroupsummaryQuery: Fix that the service severity is not being fetched --- .../Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php index 76b004272..765ca7f7a 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php @@ -83,7 +83,7 @@ class ServicegroupsummaryQuery extends IdoQuery 'servicegroup_alias', 'servicegroup_name', 'object_type', - 'severity' => 'host_severity', + 'severity' => new Zend_Db_Expr('NULL'), 'state' => 'host_state', 'state_change' => 'host_last_state_change' ) @@ -97,7 +97,7 @@ class ServicegroupsummaryQuery extends IdoQuery 'servicegroup_alias', 'servicegroup_name', 'object_type', - 'severity' => new Zend_Db_Expr('NULL'), + 'severity' => 'service_severity', 'state' => 'service_state', 'state_change' => 'service_last_state_change' ) From 41ee39d48ff6c12301b8790b9a4bf812b9e671da Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jun 2015 13:08:57 +0200 Subject: [PATCH 113/237] EventHistoryQuery: Do not fetch columns which only exist in one subquery Uses the same technique as the NotificationhistoryQuery for the output. --- .../application/controllers/ListController.php | 2 -- .../views/scripts/list/eventhistory.phtml | 11 +---------- .../application/views/scripts/show/history.phtml | 15 ++------------- .../Backend/Ido/Query/EventHistoryQuery.php | 9 ++------- .../Backend/Ido/Query/StatehistoryQuery.php | 5 +---- .../library/Monitoring/Object/MonitoredObject.php | 2 -- 6 files changed, 6 insertions(+), 38 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 3254fcc12..9a6f986b1 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -575,8 +575,6 @@ class Monitoring_ListController extends Controller 'object_type', 'timestamp', 'state', - 'attempt', - 'max_attempts', 'output', 'type' )); diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index 491dee8ff..2aedcd59b 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -23,6 +23,7 @@ if (count($history) === 0) { output; $title = $event->type; $stateName = 'invalid'; $isService = isset($event->service_description); @@ -30,54 +31,44 @@ if (count($history) === 0) { case 'notify': $icon = 'bell'; $title = $this->translate('Notification'); - $msg = $event->output; break; case 'comment': $icon = 'comment'; $title = $this->translate('Comment'); - $msg = $event->output; break; case 'ack': $icon = 'ok'; $title = $this->translate('Acknowledgement'); - $msg = $event->output; break; case 'dt_comment': $icon = 'plug'; $title = $this->translate('In Downtime'); - $msg = $event->output; break; case 'flapping': $icon = 'flapping'; $title = $this->translate('Flapping'); - $msg = $event->output; break; case 'flapping_deleted': $icon = 'ok'; $title = $this->translate('Flapping Stopped'); - $msg = $event->output; break; case 'hard_state': $icon = $isService ? 'service' : 'host'; - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output; $stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true); break; case 'soft_state': $icon = 'lightbulb'; - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output; $stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $title = $isService ? Service::getStateText($event->state, true) : Host::getStateText($event->state, true); break; case 'dt_start': $icon = 'starttime'; $title = $this->translate('Downtime Start'); - $msg = $event->output; break; case 'dt_end': $icon = 'endtime'; $title = $this->translate('Downtime End'); - $msg = $event->output; break; } ?> diff --git a/modules/monitoring/application/views/scripts/show/history.phtml b/modules/monitoring/application/views/scripts/show/history.phtml index 3777d0384..0a0205e72 100644 --- a/modules/monitoring/application/views/scripts/show/history.phtml +++ b/modules/monitoring/application/views/scripts/show/history.phtml @@ -49,6 +49,7 @@ function contactsLink($match, $view) { escape($event->output); $isService = isset($event->service_description); switch ($event->type) { case 'notify': @@ -59,70 +60,58 @@ function contactsLink($match, $view) { $msg = preg_replace_callback( '/^\[([^\]]+)\]/', function($match) use ($self) { return contactsLink($match, $self); }, - $this->escape($event->output) + $msg ); break; case 'comment': $icon = 'comment'; $title = $this->translate('Comment'); - $msg = $this->escape($event->output); break; case 'comment_deleted': $icon = 'remove'; $title = $this->translate('Comment deleted'); - $msg = $this->escape($event->output); break; case 'ack': $icon = 'acknowledgement'; $title = $this->translate('Acknowledge'); - $msg = $this->escape($event->output); break; case 'ack_deleted': $icon = 'remove'; $title = $this->translate('Ack removed'); - $msg = $this->escape($event->output); break; case 'dt_comment': $icon = 'in_downtime'; $title = $this->translate('In Downtime'); - $msg = $this->escape($event->output); break; case 'dt_comment_deleted': $icon = 'remove'; $title = $this->translate('Downtime removed'); - $msg = $this->escape($event->output); break; case 'flapping': $icon = 'flapping'; $title = $this->translate('Flapping'); - $msg = $this->escape($event->output); break; case 'flapping_deleted': $icon = 'remove'; $title = $this->translate('Flapping stopped'); - $msg = $this->escape($event->output); break; case 'hard_state': - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $icon = 'attention-alt'; $title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); break; case 'soft_state': $icon = 'spinner'; - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); $title = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); break; case 'dt_start': $icon = 'downtime_start'; $title = $this->translate('Downtime Start'); - $msg = $this->escape($event->output); break; case 'dt_end': $icon = 'downtime_end'; $title = $this->translate('Downtime End'); - $msg = $this->escape($event->output); break; } ?> diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php index 0c77e82a6..01652b070 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php @@ -37,9 +37,7 @@ class EventHistoryQuery extends IdoQuery 'object_type' => 'eh.object_type', 'timestamp' => 'eh.timestamp', 'state' => 'eh.state', - 'attempt' => 'eh.attempt', - 'max_attempts' => 'eh.max_attempts', - 'output' => 'eh.output', // we do not want long_output + 'output' => 'eh.output', 'type' => 'eh.type' ), 'hostgroups' => array( @@ -70,10 +68,7 @@ class EventHistoryQuery extends IdoQuery 'type', 'output', 'state', - 'state_type', - 'object_type', - 'attempt', - 'max_attempts', + 'object_type' ); $this->subQueries = array( $this->createSubQuery('Statehistory', $columns), diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php index ff3c1055a..cf0740315 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php @@ -18,10 +18,7 @@ class StatehistoryQuery extends IdoQuery 'object_id' => 'sho.object_id', 'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)", 'state' => 'sh.state', - 'state_type' => 'sh.state_type', - 'output' => 'sh.output', - 'attempt' => 'sh.current_check_attempt', - 'max_attempts' => 'sh.max_check_attempts', + 'output' => "('[ ' || sh.current_check_attempt || '/' || sh.max_check_attempts || ' ] ' || sh.output)", 'host' => 'sho.name1 COLLATE latin1_general_ci', 'service' => 'sho.name2 COLLATE latin1_general_ci', diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 81fe6c069..fc4ad7e32 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -457,8 +457,6 @@ abstract class MonitoredObject implements Filterable 'service_display_name', 'timestamp', 'state', - 'attempt', - 'max_attempts', 'output', 'type' )) From 51a3213fcaa06d6c1d86c2a68a4769b349282ae0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jun 2015 13:10:28 +0200 Subject: [PATCH 114/237] NotificationQuery: Add support for history related queries refs #9009 --- .../Ido/Query/HostnotificationQuery.php | 54 +++++++++++++++++-- .../Backend/Ido/Query/NotificationQuery.php | 31 +++++++++++ .../Ido/Query/ServicenotificationQuery.php | 52 +++++++++++++++++- 3 files changed, 132 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 86930e12e..631f5974b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -26,6 +26,13 @@ class HostnotificationQuery extends IdoQuery 'host_name' => 'ho.name1', 'object_type' => '(\'host\')' ), + 'history' => array( + 'type' => "('notify')", + 'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)', + 'object_id' => 'hn.object_id', + 'state' => 'hn.state', + 'output' => null + ), 'contactnotifications' => array( 'contact' => 'cno.name1 COLLATE latin1_general_ci', 'notification_contact_name' => 'cno.name1', @@ -63,6 +70,31 @@ class HostnotificationQuery extends IdoQuery */ protected function joinBaseTables() { + switch ($this->ds->getDbType()) { + case 'mysql': + $concattedContacts = "GROUP_CONCAT(" + . "cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . ") COLLATE latin1_general_ci"; + break; + case 'pgsql': + // TODO: Find a way to order the contact alias list: + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(cno.name1), ', ')"; + break; + case 'oracle': + // TODO: This is only valid for Oracle >= 11g Release 2 + $concattedContacts = "LISTAGG(cno.name1, ', ') WITHIN GROUP (ORDER BY cno.name1)"; + // Alternatives: + // + // RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')), + // + // not supported and not documented but works since 10.1, + // however it is NOT always present: + // WM_CONCAT(c.alias) + break; + } + + $this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || hn.output)"; + $this->select->from( array('hn' => $this->prefix . 'notifications'), array() @@ -80,6 +112,15 @@ class HostnotificationQuery extends IdoQuery $this->joinedVirtualTables['notifications'] = true; } + /** + * Join virtual table history + */ + protected function joinHistory() + { + $this->requireVirtualTable('contactnotifications'); + $this->group(array('hn.notification_id', 'ho.name1')); + } + /** * Join contact notifications */ @@ -95,6 +136,7 @@ class HostnotificationQuery extends IdoQuery 'cno.object_id = cn.contact_object_id', array() ); + $this->group(array('cn.contactnotification_id', 'ho.name1')); } /** @@ -134,7 +176,10 @@ class HostnotificationQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group(array('hn.notification_id', 'ho.name1')); + + if (! $this->hasJoinedVirtualTable('contactnotifications')) { + $this->group(array('hn.notification_id', 'ho.name1')); + } } /** @@ -184,7 +229,7 @@ class HostnotificationQuery extends IdoQuery { $this->select->join( array('s' => $this->prefix . 'services'), - 's.host_object_id = h.host_object_id', + 's.host_object_id = ho.object_id', array() )->join( array('so' => $this->prefix . 'objects'), @@ -198,6 +243,9 @@ class HostnotificationQuery extends IdoQuery 'so.objecttype_id = ?', 2 ); - $this->group(array('hn.notification_id', 'ho.name1')); + + if (! $this->hasJoinedVirtualTable('contactnotifications')) { + $this->group(array('hn.notification_id', 'ho.name1')); + } } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index f898c8699..135875d07 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -27,6 +27,13 @@ class NotificationQuery extends IdoQuery 'acknowledgement_comment_data' => 'n.acknowledgement_comment_data', 'object_type' => 'n.object_type' ), + 'history' => array( + 'type' => 'n.type', + 'timestamp' => 'n.timestamp', + 'object_id' => 'n.object_id', + 'state' => 'n.state', + 'output' => 'n.output' + ), 'hosts' => array( 'host_display_name' => 'n.host_display_name', 'host_name' => 'n.host_name' @@ -52,6 +59,13 @@ class NotificationQuery extends IdoQuery */ protected $subQueries = array(); + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + /** * {@inheritdoc} */ @@ -65,6 +79,17 @@ class NotificationQuery extends IdoQuery $this->joinedVirtualTables['notifications'] = true; } + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + /** * Join hosts */ @@ -73,6 +98,9 @@ class NotificationQuery extends IdoQuery $columns = array_keys( $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } $hosts = $this->createSubQuery('hostnotification', $columns); $this->subQueries[] = $hosts; $this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); @@ -86,6 +114,9 @@ class NotificationQuery extends IdoQuery $columns = array_keys( $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } $services = $this->createSubQuery('servicenotification', $columns); $this->subQueries[] = $services; $this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index aaf3d57bc..3341a6e61 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -30,6 +30,13 @@ class ServicenotificationQuery extends IdoQuery 'service_host' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1' ), + 'history' => array( + 'type' => "('notify')", + 'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)', + 'object_id' => 'sn.object_id', + 'state' => 'sn.state', + 'output' => null + ), 'contactnotifications' => array( 'contact' => 'cno.name1 COLLATE latin1_general_ci', 'notification_contact_name' => 'cno.name1', @@ -64,6 +71,31 @@ class ServicenotificationQuery extends IdoQuery */ protected function joinBaseTables() { + switch ($this->ds->getDbType()) { + case 'mysql': + $concattedContacts = "GROUP_CONCAT(" + . "cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . ") COLLATE latin1_general_ci"; + break; + case 'pgsql': + // TODO: Find a way to order the contact alias list: + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(cno.name1), ', ')"; + break; + case 'oracle': + // TODO: This is only valid for Oracle >= 11g Release 2 + $concattedContacts = "LISTAGG(cno.name1, ', ') WITHIN GROUP (ORDER BY cno.name1)"; + // Alternatives: + // + // RTRIM(XMLAGG(XMLELEMENT(e, column_name, ',').EXTRACT('//text()')), + // + // not supported and not documented but works since 10.1, + // however it is NOT always present: + // WM_CONCAT(c.alias) + break; + } + + $this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || sn.output)"; + $this->select->from( array('sn' => $this->prefix . 'notifications'), array() @@ -81,6 +113,15 @@ class ServicenotificationQuery extends IdoQuery $this->joinedVirtualTables['notifications'] = true; } + /** + * Join virtual table history + */ + protected function joinHistory() + { + $this->requireVirtualTable('contactnotifications'); + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } + /** * Join contact notifications */ @@ -96,6 +137,7 @@ class ServicenotificationQuery extends IdoQuery 'cno.object_id = cn.contact_object_id', array() ); + $this->group(array('cn.contactnotification_id', 'so.name2', 'so.name1')); } /** @@ -136,7 +178,6 @@ class ServicenotificationQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); } /** @@ -177,7 +218,10 @@ class ServicenotificationQuery extends IdoQuery 'sgo.objecttype_id = ?', 4 ); - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + + if (! $this->hasJoinedVirtualTable('contactnotifications')) { + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } } /** @@ -190,5 +234,9 @@ class ServicenotificationQuery extends IdoQuery 's.service_object_id = so.object_id', array() ); + + if (! $this->hasJoinedVirtualTable('contactnotifications')) { + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } } } From 0ccb765954265d9b27a98db41c9ba768e9b3601a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jun 2015 17:01:46 +0200 Subject: [PATCH 115/237] HostnotificationQuery: Fix grouping when *all* tables are being joined refs #9009 --- .../Backend/Ido/Query/HostnotificationQuery.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 631f5974b..b47463bcd 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -73,12 +73,12 @@ class HostnotificationQuery extends IdoQuery switch ($this->ds->getDbType()) { case 'mysql': $concattedContacts = "GROUP_CONCAT(" - . "cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '" . ") COLLATE latin1_general_ci"; break; case 'pgsql': // TODO: Find a way to order the contact alias list: - $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(cno.name1), ', ')"; + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')"; break; case 'oracle': // TODO: This is only valid for Oracle >= 11g Release 2 @@ -177,7 +177,7 @@ class HostnotificationQuery extends IdoQuery 3 ); - if (! $this->hasJoinedVirtualTable('contactnotifications')) { + if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { $this->group(array('hn.notification_id', 'ho.name1')); } } @@ -244,7 +244,7 @@ class HostnotificationQuery extends IdoQuery 2 ); - if (! $this->hasJoinedVirtualTable('contactnotifications')) { + if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { $this->group(array('hn.notification_id', 'ho.name1')); } } From 5ad93d138ca14323d4a27a0c1602b935a536833a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jun 2015 17:01:58 +0200 Subject: [PATCH 116/237] ServicenotificationQuery: Fix grouping when *all* tables are being joined refs #9009 --- .../Backend/Ido/Query/ServicenotificationQuery.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 3341a6e61..a6d6a4a26 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -74,12 +74,12 @@ class ServicenotificationQuery extends IdoQuery switch ($this->ds->getDbType()) { case 'mysql': $concattedContacts = "GROUP_CONCAT(" - . "cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '" . ") COLLATE latin1_general_ci"; break; case 'pgsql': // TODO: Find a way to order the contact alias list: - $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(cno.name1), ', ')"; + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')"; break; case 'oracle': // TODO: This is only valid for Oracle >= 11g Release 2 @@ -178,6 +178,10 @@ class ServicenotificationQuery extends IdoQuery 'hgo.objecttype_id = ?', 3 ); + + if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { + $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); + } } /** @@ -219,7 +223,7 @@ class ServicenotificationQuery extends IdoQuery 4 ); - if (! $this->hasJoinedVirtualTable('contactnotifications')) { + if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); } } @@ -234,9 +238,5 @@ class ServicenotificationQuery extends IdoQuery 's.service_object_id = so.object_id', array() ); - - if (! $this->hasJoinedVirtualTable('contactnotifications')) { - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); - } } } From b235bb69823ff435da5a75353029e26352910208 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jun 2015 17:04:00 +0200 Subject: [PATCH 117/237] NotificationQuery: Select placeholder values when joining hosts, again I've missed that our notification list-view detects based on a attribute's value of which type a returned row is... refs #9009 --- .../Monitoring/Backend/Ido/Query/NotificationQuery.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index 135875d07..b13a338b0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; use Zend_Db_Select; use Icinga\Data\Filter\Filter; @@ -96,8 +97,11 @@ class NotificationQuery extends IdoQuery protected function joinHosts() { $columns = array_keys( - $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] + $this->columnMap['notifications'] + $this->columnMap['hosts'] ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } if ($this->fetchHistoryColumns) { $columns = array_merge($columns, array_keys($this->columnMap['history'])); } From f9948f5513ee1588ed6d87cc3ba4dc45e067a4e8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 12:34:40 +0200 Subject: [PATCH 118/237] HostnotificationQuery: Apply query optimization from NotificationhistoryQuery refs #9009 --- .../Backend/Ido/Query/HostnotificationQuery.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index b47463bcd..12b4715c7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -65,6 +65,18 @@ class HostnotificationQuery extends IdoQuery ) ); + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(hn.start_time)') { + return 'hn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + /** * {@inheritdoc} */ From ed66c1f2e410263f56aab347becf6348bc3b7e6b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 12:34:55 +0200 Subject: [PATCH 119/237] ServicenotificationQuery: Apply query optimization from NotificationhistoryQuery refs #9009 --- .../Backend/Ido/Query/ServicenotificationQuery.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index a6d6a4a26..9f4bc51b4 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -66,6 +66,18 @@ class ServicenotificationQuery extends IdoQuery ) ); + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(sn.start_time)') { + return 'sn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + /** * {@inheritdoc} */ From 0ead8d48210046f6588093844035c40955c04344 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 12:35:15 +0200 Subject: [PATCH 120/237] Introduce query HoststatehistoryQuery refs #9009 --- .../Ido/Query/HoststatehistoryQuery.php | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php new file mode 100644 index 000000000..e79acdab1 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -0,0 +1,196 @@ + 0, + 'hard_state' => 1 + ); + + /** + * {@inheritdoc} + */ + protected $columnMap = array( + 'statehistory' => array( + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'history' => array( + 'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)", + 'timestamp' => 'UNIX_TIMESTAMP(hh.state_time)', + 'object_id' => 'hh.object_id', + 'state' => 'hh.state', + 'output' => "('[ ' || hh.current_check_attempt || '/' || hh.max_check_attempts || ' ] ' || hh.output)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(hh.state_time)') { + return 'hh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } elseif ( + $col === $this->columnMap['history']['type'] + && ! is_array($expression) + && array_key_exists($expression, $this->types) + ) { + return 'hh.state_type ' . $sign . ' ' . $this->types[$expression]; + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('hh' => $this->prefix . 'statehistory'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = hh.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->joinedVirtualTables['statehistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('hh.statehistory_id', 'ho.name1')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = ho.object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->select->group(array('hh.statehistory_id', 'ho.name1')); + } +} From 5083301dea3f2f548951e5decd2f95ddd6c1c006 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 12:35:29 +0200 Subject: [PATCH 121/237] Introduce query ServicestatehistoryQuery refs #9009 --- .../Ido/Query/ServicestatehistoryQuery.php | 187 ++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php new file mode 100644 index 000000000..b00ac1653 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -0,0 +1,187 @@ + 0, + 'hard_state' => 1 + ); + + /** + * {@inheritdoc} + */ + protected $columnMap = array( + 'statehistory' => array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'history' => array( + 'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)", + 'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)', + 'object_id' => 'sh.object_id', + 'state' => 'sh.state', + 'output' => "('[ ' || sh.current_check_attempt || '/' || sh.max_check_attempts || ' ] ' || sh.output)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(sh.state_time)') { + return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } elseif ( + $col === $this->columnMap['history']['type'] + && ! is_array($expression) + && array_key_exists($expression, $this->types) + ) { + return 'sh.state_type ' . $sign . ' ' . $this->types[$expression]; + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sh' => $this->prefix . 'statehistory'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = sh.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + $this->joinedVirtualTables['statehistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } +} From f17e9162eb82e0cadc548c4b84a888f1d3f7a8ce Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 12:36:10 +0200 Subject: [PATCH 122/237] StatehistoryQuery: Use subqueries for host and service state records refs #9009 --- .../Backend/Ido/Query/StatehistoryQuery.php | 170 ++++++++++++++---- 1 file changed, 133 insertions(+), 37 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php index cf0740315..41f18572b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php @@ -3,55 +3,151 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service state history records + */ class StatehistoryQuery extends IdoQuery { - protected $types = array( - 'soft_state' => 0, - 'hard_state' => 1 - ); - + /** + * {@inheritdoc} + */ protected $columnMap = array( 'statehistory' => array( - 'state_time' => 'sh.state_time', - 'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)', - 'raw_timestamp' => 'sh.state_time', - 'object_id' => 'sho.object_id', - 'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)", - 'state' => 'sh.state', - 'output' => "('[ ' || sh.current_check_attempt || '/' || sh.max_check_attempts || ' ] ' || sh.output)", - - 'host' => 'sho.name1 COLLATE latin1_general_ci', - 'service' => 'sho.name2 COLLATE latin1_general_ci', - 'host_name' => 'sho.name1', - 'service_description' => 'sho.name2', - 'object_type' => "CASE WHEN sho.objecttype_id = 1 THEN 'host' ELSE 'service' END" + 'object_type' => 'sth.object_type' + ), + 'history' => array( + 'type' => 'sth.type', + 'timestamp' => 'sth.timestamp', + 'object_id' => 'sth.object_id', + 'state' => 'sth.state', + 'output' => 'sth.output' + ), + 'hosts' => array( + 'host_display_name' => 'sth.host_display_name', + 'host_name' => 'sth.host_name' + ), + 'services' => array( + 'service_description' => 'sth.service_description', + 'service_display_name' => 'sth.service_display_name', + 'service_host_name' => 'sth.service_host_name' ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(sh.state_time)') { - return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } elseif ($col === $this->columnMap['statehistory']['type'] - && is_array($expression) === false - && array_key_exists($expression, $this->types) === true - ) { - return 'sh.state_type ' . $sign . ' ' . $this->types[$expression]; - } else { - return parent::whereToSql($col, $sign, $expression); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $stateHistoryQuery; + /** + * Subqueries used for the state history query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { + $this->stateHistoryQuery = $this->db->select(); $this->select->from( - array('sho' => $this->prefix . 'objects'), - array() - )->join( - array('sh' => $this->prefix . 'statehistory'), - 'sho.' . $this->object_id . ' = sh.' . $this->object_id . ' AND sho.is_active = 1', + array('sth' => $this->stateHistoryQuery), array() ); - $this->joinedVirtualTables = array('statehistory' => true); + $this->joinedVirtualTables['statehistory'] = true; + } + + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys( + $this->columnMap['statehistory'] + $this->columnMap['hosts'] + ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $hosts = $this->createSubQuery('Hoststatehistory', $columns); + $this->subQueries[] = $hosts; + $this->stateHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['statehistory'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $services = $this->createSubQuery('Servicestatehistory', $columns); + $this->subQueries[] = $services; + $this->stateHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; } } From 26e895aedb78ec6edd6b32c947663ce270c3ad1d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 15:28:38 +0200 Subject: [PATCH 123/237] Introduce query HostcommenthistoryQuery refs #9009 --- .../Ido/Query/HostcommenthistoryQuery.php | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php new file mode 100644 index 000000000..259fe1c18 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -0,0 +1,180 @@ + array( + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'history' => array( + 'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)", + 'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)', + 'object_id' => 'hch.object_id', + 'state' => '(NULL)', + 'output' => "('[' || hch.author_name || '] ' || hch.comment_data)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(hch.comment_time)') { + return 'hch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('hch' => $this->prefix . 'commenthistory'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = hch.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + $this->joinedVirtualTables['commenthistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('hch.commenthistory_id', 'ho.name1')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = ho.object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->select->group(array('hch.commenthistory_id', 'ho.name1')); + } +} From bf85fd62b5aea4036cd573805e29f19ac22aa186 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 15:28:57 +0200 Subject: [PATCH 124/237] Introduce query ServicecommenthistoryQuery refs #9009 --- .../Ido/Query/ServicecommenthistoryQuery.php | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php new file mode 100644 index 000000000..b0aee8d4b --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -0,0 +1,171 @@ + array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'history' => array( + 'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)", + 'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)', + 'object_id' => 'sch.object_id', + 'state' => '(NULL)', + 'output' => "('[' || sch.author_name || '] ' || sch.comment_data)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(sch.comment_time)') { + return 'sch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sch' => $this->prefix . 'commenthistory'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = sch.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + $this->joinedVirtualTables['commenthistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } +} From 7358eefed88f56806fcba5e37218c6bd9add2295 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 15:29:36 +0200 Subject: [PATCH 125/237] CommenthistoryQuery: Use subqueries to fetch host and service comments refs #9009 --- .../Backend/Ido/Query/CommenthistoryQuery.php | 162 ++++++++++++++---- 1 file changed, 132 insertions(+), 30 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php index 6b2f821e9..b8fdd72a4 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php @@ -3,49 +3,151 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service comment history records + */ class CommenthistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( 'commenthistory' => array( - 'state_time' => 'h.comment_time', - 'timestamp' => 'UNIX_TIMESTAMP(h.comment_time)', - 'raw_timestamp' => 'h.comment_time', - 'object_id' => 'h.object_id', - 'type' => "(CASE h.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)", - 'state' => '(NULL)', - 'state_type' => '(NULL)', - 'output' => "('[' || h.author_name || '] ' || h.comment_data)", - 'attempt' => '(NULL)', - 'max_attempts' => '(NULL)', - - 'host' => 'o.name1 COLLATE latin1_general_ci', - 'service' => 'o.name2 COLLATE latin1_general_ci', - 'host_name' => 'o.name1', - 'service_description' => 'o.name2', - 'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END" + 'object_type' => 'ch.object_type' + ), + 'history' => array( + 'type' => 'ch.type', + 'timestamp' => 'ch.timestamp', + 'object_id' => 'ch.object_id', + 'state' => 'ch.state', + 'output' => 'ch.output' + ), + 'hosts' => array( + 'host_display_name' => 'ch.host_display_name', + 'host_name' => 'ch.host_name' + ), + 'services' => array( + 'service_description' => 'ch.service_description', + 'service_display_name' => 'ch.service_display_name', + 'service_host_name' => 'ch.service_host_name' ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(h.comment_time)') { - return 'h.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $commentHistoryQuery; + /** + * Subqueries used for the comment history query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { + $this->commentHistoryQuery = $this->db->select(); $this->select->from( - array('o' => $this->prefix . 'objects'), - array() - )->join( - array('h' => $this->prefix . 'commenthistory'), - 'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1 AND h.entry_type <> 2', + array('ch' => $this->commentHistoryQuery), array() ); - $this->joinedVirtualTables = array('commenthistory' => true); + $this->joinedVirtualTables['commenthistory'] = true; } + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys( + $this->columnMap['commenthistory'] + $this->columnMap['hosts'] + ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $hosts = $this->createSubQuery('Hostcommenthistory', $columns); + $this->subQueries[] = $hosts; + $this->commentHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['commenthistory'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $services = $this->createSubQuery('Servicecommenthistory', $columns); + $this->subQueries[] = $services; + $this->commentHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } } From 7ea9051d4368cfdf604e6f6697d4ba3062560faa Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 16:15:29 +0200 Subject: [PATCH 126/237] Introduce query HostcommentdeletionQuery refs #9009 --- .../Query/HostcommentdeletionhistoryQuery.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php new file mode 100644 index 000000000..a9c8f5f82 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php @@ -0,0 +1,41 @@ +timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + parent::joinBaseTables(); + $this->select->where("hch.deletion_time > '1970-01-02 00:00:00'"); + $this->columnMap['history']['timestamp'] = str_replace( + 'comment_time', + 'deletion_time', + $this->columnMap['history']['timestamp'] + ); + $this->columnMap['history']['type'] = str_replace( + 'END)', + "END || '_deleted')", + $this->columnMap['history']['type'] + ); + } +} From b7a26c599d20c1937afcc3d319740d747862001e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 16:15:50 +0200 Subject: [PATCH 127/237] Introduce query ServicecommentdeletionhistoryQuery refs #9009 --- .../ServicecommentdeletionhistoryQuery.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php new file mode 100644 index 000000000..69e49e1ea --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php @@ -0,0 +1,41 @@ +timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + parent::joinBaseTables(); + $this->select->where("sch.deletion_time > '1970-01-02 00:00:00'"); + $this->columnMap['history']['timestamp'] = str_replace( + 'comment_time', + 'deletion_time', + $this->columnMap['history']['timestamp'] + ); + $this->columnMap['history']['type'] = str_replace( + 'END)', + "END || '_deleted')", + $this->columnMap['history']['type'] + ); + } +} From 51434c7255079a5c3d1a74bdc39eb1a57fe70ceb Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Jun 2015 16:16:17 +0200 Subject: [PATCH 128/237] CommentdeletionhistoryQuery: Use subqueries to fetch removed host and service comments refs #9009 --- .../Ido/Query/CommentdeletionhistoryQuery.php | 162 ++++++++++++++---- 1 file changed, 132 insertions(+), 30 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentdeletionhistoryQuery.php index 9346ce09a..30be5c400 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentdeletionhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentdeletionhistoryQuery.php @@ -3,49 +3,151 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service comment removal records + */ class CommentdeletionhistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( 'commenthistory' => array( - 'state_time' => 'h.deletion_time', - 'timestamp' => 'UNIX_TIMESTAMP(h.deletion_time)', - 'raw_timestamp' => 'h.deletion_time', - 'object_id' => 'h.object_id', - 'type' => "(CASE h.entry_type WHEN 1 THEN 'comment_deleted' WHEN 2 THEN 'dt_comment_deleted' WHEN 3 THEN 'flapping_deleted' WHEN 4 THEN 'ack_deleted' END)", - 'state' => '(NULL)', - 'state_type' => '(NULL)', - 'output' => "('[' || h.author_name || '] ' || h.comment_data)", - 'attempt' => '(NULL)', - 'max_attempts' => '(NULL)', - - 'host' => 'o.name1 COLLATE latin1_general_ci', - 'service' => 'o.name2 COLLATE latin1_general_ci', - 'host_name' => 'o.name1', - 'service_description' => 'o.name2', - 'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END" + 'object_type' => 'cdh.object_type' + ), + 'history' => array( + 'type' => 'cdh.type', + 'timestamp' => 'cdh.timestamp', + 'object_id' => 'cdh.object_id', + 'state' => 'cdh.state', + 'output' => 'cdh.output' + ), + 'hosts' => array( + 'host_display_name' => 'cdh.host_display_name', + 'host_name' => 'cdh.host_name' + ), + 'services' => array( + 'service_description' => 'cdh.service_description', + 'service_display_name' => 'cdh.service_display_name', + 'service_host_name' => 'cdh.service_host_name' ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(h.deletion_time)') { - return 'h.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $commentDeletionHistoryQuery; + /** + * Subqueries used for the comment history query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { + $this->commentDeletionHistoryQuery = $this->db->select(); $this->select->from( - array('o' => $this->prefix . 'objects'), - array() - )->join( - array('h' => $this->prefix . 'commenthistory'), - 'o.' . $this->object_id . ' = h.' . $this->object_id . " AND o.is_active = 1 AND h.deletion_time > '1970-01-02 00:00:00' AND h.entry_type <> 2", + array('cdh' => $this->commentDeletionHistoryQuery), array() ); - $this->joinedVirtualTables = array('commenthistory' => true); + $this->joinedVirtualTables['commenthistory'] = true; } + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys( + $this->columnMap['commenthistory'] + $this->columnMap['hosts'] + ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $hosts = $this->createSubQuery('Hostcommentdeletionhistory', $columns); + $this->subQueries[] = $hosts; + $this->commentDeletionHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['commenthistory'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $services = $this->createSubQuery('Servicecommentdeletionhistory', $columns); + $this->subQueries[] = $services; + $this->commentDeletionHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } } From 18d3fcbbf7500fdd3ed618ac2bf71d9ebb8c4e9f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:44:25 +0200 Subject: [PATCH 129/237] Introduce query HostdowntimestarthistoryQuery refs #9009 --- .../Query/HostdowntimestarthistoryQuery.php | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php new file mode 100644 index 000000000..05b8307a5 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -0,0 +1,189 @@ + array( + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'object_type' => '(\'host\')' + ), + 'history' => array( + 'type' => "('dt_start')", + 'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)', + 'object_id' => 'hdh.object_id', + 'state' => '(NULL)', + 'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(hdh.actual_start_time)') { + return 'hdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql( + $this->valueToTimestamp($expression) + ); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('hdh' => $this->prefix . 'downtimehistory'), + array() + )->join( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = hdh.object_id', + array() + )->where( + 'ho.is_active = ?', + 1 + )->where( + 'ho.objecttype_id = ?', + 1 + ); + + if (@func_get_arg(0) === false) { + $this->select->where( + "hdh.actual_start_time > '1970-01-02 00:00:00'" + ); + } + + $this->joinedVirtualTables['downtimehistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = ho.object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.host_object_id = ho.object_id', + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id', + array() + )->where( + 'so.is_active = ?', + 1 + ) + ->where( + 'so.objecttype_id = ?', + 2 + ); + $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); + } +} From 7afa4dac9aef5b52a83b955fd473966ffc5a5fb3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:44:35 +0200 Subject: [PATCH 130/237] Introduce query HostdowntimeendhistoryQuery refs #9009 --- .../Ido/Query/HostdowntimeendhistoryQuery.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php new file mode 100644 index 000000000..8ef831f80 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php @@ -0,0 +1,39 @@ +timestampForSql( + $this->valueToTimestamp($expression) + ); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + parent::joinBaseTables(true); + $this->select->where("hdh.actual_end_time > '1970-01-02 00:00:00'"); + $this->columnMap['history']['type'] = "('dt_end')"; + $this->columnMap['history']['timestamp'] = str_replace( + 'actual_start_time', + 'actual_end_time', + $this->columnMap['history']['timestamp'] + ); + } +} From 3ed858269c52da8e41ead4c02d2baa93cef7d1c2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:44:49 +0200 Subject: [PATCH 131/237] Introduce query ServicedowntimestarthistoryQuery refs #9009 --- .../ServicedowntimestarthistoryQuery.php | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php new file mode 100644 index 000000000..7b1f1989a --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -0,0 +1,180 @@ + array( + 'host' => 'so.name1 COLLATE latin1_general_ci', + 'host_name' => 'so.name1', + 'object_type' => '(\'service\')', + 'service' => 'so.name2 COLLATE latin1_general_ci', + 'service_description' => 'so.name2', + 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_host_name' => 'so.name1' + ), + 'history' => array( + 'type' => "('dt_start')", + 'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)', + 'object_id' => 'sdh.object_id', + 'state' => '(NULL)', + 'output' => "('[' || sdh.author_name || '] ' || sdh.comment_data)", + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' + ), + 'services' => array( + 'service_display_name' => 's.display_name COLLATE latin1_general_ci' + ) + ); + + /** + * {@inheritdoc} + */ + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(sdh.actual_start_time)') { + return 'sdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql( + $this->valueToTimestamp($expression) + ); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + $this->select->from( + array('sdh' => $this->prefix . 'downtimehistory'), + array() + )->join( + array('so' => $this->prefix . 'objects'), + 'so.object_id = sdh.object_id', + array() + )->where( + 'so.is_active = ?', + 1 + )->where( + 'so.objecttype_id = ?', + 2 + ); + + if (@func_get_arg(0) === false) { + $this->select->where( + "sdh.actual_start_time > '1970-01-02 00:00:00'" + ); + } + + $this->joinedVirtualTables['downtimehistory'] = true; + $this->joinedVirtualTables['history'] = true; + } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = s.host_object_id', + array() + )->join( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->join( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id', + array() + )->where( + 'hgo.is_active = ?', + 1 + ) + ->where( + 'hgo.objecttype_id = ?', + 3 + ); + $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + $this->select->join( + array('h' => $this->prefix . 'hosts'), + 'h.host_object_id = s.host_object_id', + array() + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->select->join( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = so.object_id', + array() + )->join( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', + array() + )->join( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id', + array() + )->where( + 'sgo.is_active = ?', + 1 + ) + ->where( + 'sgo.objecttype_id = ?', + 4 + ); + $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->join( + array('s' => $this->prefix . 'services'), + 's.service_object_id = so.object_id', + array() + ); + } +} From 95b5bba65c8b2b8ef5329be60c29c5e82d938ed7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:45:02 +0200 Subject: [PATCH 132/237] Introduce query ServicedowntimeendhistoryQuery refs #9009 --- .../Query/ServicedowntimeendhistoryQuery.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php new file mode 100644 index 000000000..44303a9cd --- /dev/null +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php @@ -0,0 +1,39 @@ +timestampForSql( + $this->valueToTimestamp($expression) + ); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + + /** + * {@inheritdoc} + */ + protected function joinBaseTables() + { + parent::joinBaseTables(true); + $this->select->where("sdh.actual_end_time > '1970-01-02 00:00:00'"); + $this->columnMap['history']['type'] = "('dt_end')"; + $this->columnMap['history']['timestamp'] = str_replace( + 'actual_start_time', + 'actual_end_time', + $this->columnMap['history']['timestamp'] + ); + } +} From dadb3853d72b2fa2a2e395eb964b269e17a54932 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:45:49 +0200 Subject: [PATCH 133/237] DowntimestarthistoryQuery: Use subqueries to fetch host and service downtimes refs #9009 --- .../Ido/Query/DowntimestarthistoryQuery.php | 166 ++++++++++++++---- 1 file changed, 134 insertions(+), 32 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php index 6f23fe174..e312480e7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php @@ -3,49 +3,151 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service downtime start history records + */ class DowntimestarthistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( 'downtimehistory' => array( - 'state_time' => 'h.actual_start_time', - 'timestamp' => 'UNIX_TIMESTAMP(h.actual_start_time)', - 'raw_timestamp' => 'h.actual_start_time', - 'object_id' => 'h.object_id', - 'type' => "('dt_start')", - 'state' => '(NULL)', - 'state_type' => '(NULL)', - 'output' => "('[' || h.author_name || '] ' || h.comment_data)", - 'attempt' => '(NULL)', - 'max_attempts' => '(NULL)', - - 'host' => 'o.name1 COLLATE latin1_general_ci', - 'service' => 'o.name2 COLLATE latin1_general_ci', - 'host_name' => 'o.name1', - 'service_description' => 'o.name2', - 'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END" + 'object_type' => 'dsh.object_type' + ), + 'history' => array( + 'type' => 'dsh.type', + 'timestamp' => 'dsh.timestamp', + 'object_id' => 'dsh.object_id', + 'state' => 'dsh.state', + 'output' => 'dsh.output' + ), + 'hosts' => array( + 'host_display_name' => 'dsh.host_display_name', + 'host_name' => 'dsh.host_name' + ), + 'services' => array( + 'service_description' => 'dsh.service_description', + 'service_display_name' => 'dsh.service_display_name', + 'service_host_name' => 'dsh.service_host_name' ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(h.actual_start_time)') { - return 'h.actual_start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $downtimeStartHistoryQuery; + /** + * Subqueries used for the downtime start history query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { + $this->downtimeStartHistoryQuery = $this->db->select(); $this->select->from( - array('o' => $this->prefix . 'objects'), + array('dsh' => $this->downtimeStartHistoryQuery), array() - )->join( - array('h' => $this->prefix . 'downtimehistory'), - 'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1', - array() - )->where('h.actual_start_time > ?', '1970-01-02 00:00:00'); - $this->joinedVirtualTables = array('downtimehistory' => true); + ); + $this->joinedVirtualTables['downtimehistory'] = true; + } + + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys( + $this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $hosts = $this->createSubQuery('Hostdowntimestarthistory', $columns); + $this->subQueries[] = $hosts; + $this->downtimeStartHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $services = $this->createSubQuery('Servicedowntimestarthistory', $columns); + $this->subQueries[] = $services; + $this->downtimeStartHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; } } - From c35be4023b39882c8276ea281b9c70f8016b8f26 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:45:59 +0200 Subject: [PATCH 134/237] DowntimeendhistoryQuery: Use subqueries to fetch host and service downtimes refs #9009 --- .../Ido/Query/DowntimeendhistoryQuery.php | 166 ++++++++++++++---- 1 file changed, 134 insertions(+), 32 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php index 42d23ce05..08b6cec01 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php @@ -3,49 +3,151 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; +use Zend_Db_Select; +use Icinga\Data\Filter\Filter; + +/** + * Query for host and service downtime end history records + */ class DowntimeendhistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ protected $columnMap = array( 'downtimehistory' => array( - 'state_time' => 'h.actual_end_time', - 'timestamp' => 'UNIX_TIMESTAMP(h.actual_end_time)', - 'raw_timestamp' => 'h.actual_end_time', - 'object_id' => 'h.object_id', - 'type' => "('dt_end')", - 'state' => '(NULL)', - 'state_type' => '(NULL)', - 'output' => "('[' || h.author_name || '] ' || h.comment_data)", - 'attempt' => '(NULL)', - 'max_attempts' => '(NULL)', - - 'host' => 'o.name1 COLLATE latin1_general_ci', - 'service' => 'o.name2 COLLATE latin1_general_ci', - 'host_name' => 'o.name1', - 'service_description' => 'o.name2', - 'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END" + 'object_type' => 'deh.object_type' + ), + 'history' => array( + 'type' => 'deh.type', + 'timestamp' => 'deh.timestamp', + 'object_id' => 'deh.object_id', + 'state' => 'deh.state', + 'output' => 'deh.output' + ), + 'hosts' => array( + 'host_display_name' => 'deh.host_display_name', + 'host_name' => 'deh.host_name' + ), + 'services' => array( + 'service_description' => 'deh.service_description', + 'service_display_name' => 'deh.service_display_name', + 'service_host_name' => 'deh.service_host_name' ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(h.actual_end_time)') { - return 'h.actual_end_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $downtimeEndHistoryQuery; + /** + * Subqueries used for the downtime end history query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * Whether to additionally select all history columns + * + * @var bool + */ + protected $fetchHistoryColumns = false; + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { + $this->downtimeEndHistoryQuery = $this->db->select(); $this->select->from( - array('o' => $this->prefix . 'objects'), + array('deh' => $this->downtimeEndHistoryQuery), array() - )->join( - array('h' => $this->prefix . 'downtimehistory'), - 'o.' . $this->object_id . ' = h.' . $this->object_id . ' AND o.is_active = 1', - array() - )->where('h.actual_end_time > ?', '1970-01-02 00:00:00'); - $this->joinedVirtualTables = array('downtimehistory' => true); + ); + $this->joinedVirtualTables['downtimehistory'] = true; + } + + /** + * Join history related columns and tables + */ + protected function joinHistory() + { + // TODO: Ensure that one is selecting the history columns first... + $this->fetchHistoryColumns = true; + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = array_keys( + $this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + ); + foreach ($this->columnMap['services'] as $column => $_) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $hosts = $this->createSubQuery('Hostdowntimeendhistory', $columns); + $this->subQueries[] = $hosts; + $this->downtimeEndHistoryQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * Join services + */ + protected function joinServices() + { + $columns = array_keys( + $this->columnMap['downtimehistory'] + $this->columnMap['hosts'] + $this->columnMap['services'] + ); + if ($this->fetchHistoryColumns) { + $columns = array_merge($columns, array_keys($this->columnMap['history'])); + } + $services = $this->createSubQuery('Servicedowntimeendhistory', $columns); + $this->subQueries[] = $services; + $this->downtimeEndHistoryQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) + { + foreach ($this->subQueries as $sub) { + $sub->requireColumn($columnOrAlias); + } + return parent::order($columnOrAlias, $dir); + } + + /** + * {@inheritdoc} + */ + public function where($condition, $value = null) + { + $this->requireColumn($condition); + foreach ($this->subQueries as $sub) { + $sub->where($condition, $value); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; } } - From 528df1b26a47509b0ca50b15176b5ff2cf74f991 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:52:07 +0200 Subject: [PATCH 135/237] EventHistory: Add support for object restrictions refs #9009 --- .../Backend/Ido/Query/EventHistoryQuery.php | 126 ++++-------------- .../Monitoring/DataView/EventHistory.php | 16 ++- 2 files changed, 38 insertions(+), 104 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php index 01652b070..e14fc6e86 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php @@ -7,16 +7,19 @@ use Zend_Db_Select; use Icinga\Data\Filter\Filter; /** - * Query for event history + * Query for event history records */ class EventHistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $useSubqueryCount = true; + /** * Subqueries used for the event history query * * @type IdoQuery[] - * - * @see EventHistoryQuery::joinBaseTables() For the used subqueries. */ protected $subQueries = array(); @@ -30,33 +33,18 @@ class EventHistoryQuery extends IdoQuery 'cnt_soft_state' => "SUM(CASE eh.type WHEN 'hard_state' THEN 1 ELSE 0 END)", 'cnt_downtime_start' => "SUM(CASE eh.type WHEN 'dt_start' THEN 1 ELSE 0 END)", 'cnt_downtime_end' => "SUM(CASE eh.type WHEN 'dt_end' THEN 1 ELSE 0 END)", - 'host' => 'eho.name1 COLLATE latin1_general_ci', - 'service' => 'eho.name2 COLLATE latin1_general_ci', - 'host_name' => 'eho.name1', - 'service_description' => 'eho.name2', + 'host_name' => 'eh.host_name', + 'service_description' => 'eh.service_description', 'object_type' => 'eh.object_type', 'timestamp' => 'eh.timestamp', 'state' => 'eh.state', 'output' => 'eh.output', - 'type' => 'eh.type' - ), - 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' - ), - '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' + 'type' => 'eh.type', + 'host_display_name' => 'eh.host_display_name', + 'service_display_name' => 'eh.service_display_name' ) ); - /** - * {@inheritdoc} - */ - protected $useSubqueryCount = true; - /** * {@inheritdoc} */ @@ -64,11 +52,15 @@ class EventHistoryQuery extends IdoQuery { $columns = array( 'timestamp', - 'object_id', - 'type', 'output', + 'type', 'state', - 'object_type' + 'object_type', + 'object_id', + 'host_name', + 'service_description', + 'host_display_name', + 'service_display_name' ); $this->subQueries = array( $this->createSubQuery('Statehistory', $columns), @@ -76,19 +68,11 @@ class EventHistoryQuery extends IdoQuery $this->createSubQuery('Downtimeendhistory', $columns), $this->createSubQuery('Commenthistory', $columns), $this->createSubQuery('Commentdeletionhistory', $columns), - $this->createSubQuery('Notificationhistory', $columns) + $this->createSubQuery('Notification', $columns) ); $sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL); - - $this->select->from( - array('eho' => $this->prefix . 'objects'), - '*' - )->join( - array('eh' => $sub), - 'eho.' . $this->object_id . ' = eh.' . $this->object_id . ' AND eho.is_active = 1', - array() - ); - $this->joinedVirtualTables = array('eventhistory' => true); + $this->select->from(array('eh' => $sub), array()); + $this->joinedVirtualTables['eventhistory'] = true; } /** @@ -102,17 +86,6 @@ class EventHistoryQuery extends IdoQuery return parent::order($columnOrAlias, $dir); } - /** - * {@inheritdoc} - */ - public function addFilter(Filter $filter) - { - foreach ($this->subQueries as $sub) { - $sub->applyFilter(clone $filter); - } - return $this; - } - /** * {@inheritdoc} */ @@ -126,60 +99,13 @@ class EventHistoryQuery extends IdoQuery } /** - * Join host groups - * - * @return $this + * {@inheritdoc} */ - protected function joinHostgroups() + public function addFilter(Filter $filter) { - $this->select->join( - array('hgm' => $this->prefix . 'hostgroup_members'), - 'hgm.host_object_id = eho.object_id', - array() - )->join( - array('hg' => $this->prefix . 'hostgroups'), - 'hgm.hostgroup_id = hg.' . $this->hostgroup_id, - array() - )->join( - array('hgo' => $this->prefix . 'objects'), - 'hgo.' . $this->object_id. ' = hg.hostgroup_object_id' . ' AND hgo.is_active = 1', - array() - ); - return $this; - } - - /** - * Join hosts - * - * @return $this - */ - protected function joinHosts() - { - $this->select->joinLeft( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = eho.object_id', - array() - ); - return $this; - } - - /** - * Join services - * - * @return $this - */ - protected function joinServices() - { - $this->select->joinLeft( - array('s' => $this->prefix . 'services'), - 's.service_object_id = eho.object_id', - array() - ); - $this->select->joinLeft( - array('sh' => $this->prefix . 'hosts'), - 'sh.host_object_id = s.host_object_id', - array() - ); + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } return $this; } } diff --git a/modules/monitoring/library/Monitoring/DataView/EventHistory.php b/modules/monitoring/library/Monitoring/DataView/EventHistory.php index c19a4a376..b826b535c 100644 --- a/modules/monitoring/library/Monitoring/DataView/EventHistory.php +++ b/modules/monitoring/library/Monitoring/DataView/EventHistory.php @@ -22,17 +22,17 @@ class EventHistory extends DataView 'host_display_name', 'service_description', 'service_display_name', - 'hostgroup_name', 'object_type', 'timestamp', 'state', - 'attempt', - 'max_attempts', 'output', 'type' ); } + /** + * {@inheritdoc} + */ public function getSortRules() { return array( @@ -43,8 +43,16 @@ class EventHistory extends DataView ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { - return array('host', 'service', 'hostgroup'); + return array( + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } } From 76b17462f9826e0ea228166a273831ccfdf04125 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 12:52:29 +0200 Subject: [PATCH 136/237] ListController: Restrict eventhistoryAction refs 9009 --- modules/monitoring/application/controllers/ListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 9a6f986b1..25f184308 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -579,6 +579,7 @@ class Monitoring_ListController extends Controller 'type' )); + $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); $this->view->history = $query; From 4996f569fe26b53eab12e76d9b1ea5413b73a810 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 14:42:49 +0200 Subject: [PATCH 137/237] monitoring: Ensure that views and queries are all named using the same scheme That's "SomesuperQuery" and not "SomeSuperQuery", according to most of the existing queries. --- modules/monitoring/application/clicommands/ListCommand.php | 2 +- .../application/controllers/AlertsummaryController.php | 2 +- .../monitoring/application/controllers/ListController.php | 6 +++--- .../monitoring/application/controllers/ShowController.php | 2 +- .../application/controllers/TacticalController.php | 2 +- .../application/controllers/TimelineController.php | 2 +- .../Query/{EventHistoryQuery.php => EventhistoryQuery.php} | 0 .../{StatusSummaryQuery.php => StatussummaryQuery.php} | 0 .../DataView/{EventHistory.php => Eventhistory.php} | 0 .../Monitoring/DataView/{HostStatus.php => Hoststatus.php} | 0 .../DataView/{ServiceStatus.php => Servicestatus.php} | 0 .../DataView/{StatusSummary.php => Statussummary.php} | 0 modules/monitoring/library/Monitoring/Object/Host.php | 4 ++-- modules/monitoring/library/Monitoring/Object/HostList.php | 2 +- .../library/Monitoring/Object/MonitoredObject.php | 2 +- modules/monitoring/library/Monitoring/Object/Service.php | 2 +- .../monitoring/library/Monitoring/Object/ServiceList.php | 2 +- .../Monitoring/Web/Controller/MonitoredObjectController.php | 2 +- .../Monitoring/Web/Menu/MonitoringMenuItemRenderer.php | 2 +- 19 files changed, 16 insertions(+), 16 deletions(-) rename modules/monitoring/library/Monitoring/Backend/Ido/Query/{EventHistoryQuery.php => EventhistoryQuery.php} (100%) rename modules/monitoring/library/Monitoring/Backend/Ido/Query/{StatusSummaryQuery.php => StatussummaryQuery.php} (100%) rename modules/monitoring/library/Monitoring/DataView/{EventHistory.php => Eventhistory.php} (100%) rename modules/monitoring/library/Monitoring/DataView/{HostStatus.php => Hoststatus.php} (100%) rename modules/monitoring/library/Monitoring/DataView/{ServiceStatus.php => Servicestatus.php} (100%) rename modules/monitoring/library/Monitoring/DataView/{StatusSummary.php => Statussummary.php} (100%) diff --git a/modules/monitoring/application/clicommands/ListCommand.php b/modules/monitoring/application/clicommands/ListCommand.php index 9fd892652..c3f4ab951 100644 --- a/modules/monitoring/application/clicommands/ListCommand.php +++ b/modules/monitoring/application/clicommands/ListCommand.php @@ -156,7 +156,7 @@ class ListCommand extends Command 'service_perfdata', 'service_last_state_change' ); - $query = $this->getQuery('serviceStatus', $columns) + $query = $this->getQuery('servicestatus', $columns) ->order('host_name'); echo $this->renderStatusQuery($query); } diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index 1dc3b137b..41bbca96b 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -251,7 +251,7 @@ class Monitoring_AlertsummaryController extends Controller $interval = $this->getInterval(); $query = $this->backend->select()->from( - 'eventHistory', + 'eventhistory', array( 'timestamp' ) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 25f184308..fa8781006 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -180,7 +180,7 @@ class Monitoring_ListController extends Controller 'current_check_attempt' => 'service_current_check_attempt', 'max_check_attempts' => 'service_max_check_attempts' ), $this->addColumns()); - $query = $this->backend->select()->from('serviceStatus', $columns); + $query = $this->backend->select()->from('servicestatus', $columns); $this->filterQuery($query); $this->applyRestriction('monitoring/filter/objects', $query); $this->view->services = $query; @@ -567,7 +567,7 @@ class Monitoring_ListController extends Controller $this->translate('List event records') ); - $query = $this->backend->select()->from('eventHistory', array( + $query = $this->backend->select()->from('eventhistory', array( 'host_name', 'host_display_name', 'service_description', @@ -594,7 +594,7 @@ class Monitoring_ListController extends Controller { $this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid')); $this->setAutorefreshInterval(15); - $query = $this->backend->select()->from('serviceStatus', array( + $query = $this->backend->select()->from('servicestatus', array( 'host_name', 'service_description', 'service_state', diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index cf71c7d32..6c2c03c18 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -211,7 +211,7 @@ class Monitoring_ShowController extends Controller ) ); } - if ($this->backend->hasQuery('eventHistory')) { + if ($this->backend->hasQuery('eventhistory')) { $tabs->add( 'history', array( diff --git a/modules/monitoring/application/controllers/TacticalController.php b/modules/monitoring/application/controllers/TacticalController.php index 95440a309..fa2e7deec 100644 --- a/modules/monitoring/application/controllers/TacticalController.php +++ b/modules/monitoring/application/controllers/TacticalController.php @@ -21,7 +21,7 @@ class Monitoring_TacticalController extends MonitoringController ) )->extend(new DashboardAction())->activate('tactical_overview'); $stats = $this->backend->select()->from( - 'statusSummary', + 'statussummary', array( 'hosts_up', 'hosts_pending', diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 6d313083f..24bc71f30 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -30,7 +30,7 @@ class Monitoring_TimelineController extends Controller $detailUrl = Url::fromPath('monitoring/list/eventhistory'); $timeline = new TimeLine( - $this->backend->select()->from('eventHistory', + $this->backend->select()->from('eventhistory', array( 'name' => 'type', 'time' => 'timestamp' diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php similarity index 100% rename from modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php rename to modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatussummaryQuery.php similarity index 100% rename from modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php rename to modules/monitoring/library/Monitoring/Backend/Ido/Query/StatussummaryQuery.php diff --git a/modules/monitoring/library/Monitoring/DataView/EventHistory.php b/modules/monitoring/library/Monitoring/DataView/Eventhistory.php similarity index 100% rename from modules/monitoring/library/Monitoring/DataView/EventHistory.php rename to modules/monitoring/library/Monitoring/DataView/Eventhistory.php diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/Hoststatus.php similarity index 100% rename from modules/monitoring/library/Monitoring/DataView/HostStatus.php rename to modules/monitoring/library/Monitoring/DataView/Hoststatus.php diff --git a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php b/modules/monitoring/library/Monitoring/DataView/Servicestatus.php similarity index 100% rename from modules/monitoring/library/Monitoring/DataView/ServiceStatus.php rename to modules/monitoring/library/Monitoring/DataView/Servicestatus.php diff --git a/modules/monitoring/library/Monitoring/DataView/StatusSummary.php b/modules/monitoring/library/Monitoring/DataView/Statussummary.php similarity index 100% rename from modules/monitoring/library/Monitoring/DataView/StatusSummary.php rename to modules/monitoring/library/Monitoring/DataView/Statussummary.php diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index dd9b4c0c1..4940ffdf1 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -137,7 +137,7 @@ class Host extends MonitoredObject if ($this->backend->getType() === 'livestatus') { $columns[] = 'host_contacts'; } - return $this->backend->select()->from('hostStatus', $columns) + return $this->backend->select()->from('hoststatus', $columns) ->where('host_name', $this->host); } @@ -149,7 +149,7 @@ class Host extends MonitoredObject public function fetchServices() { $services = array(); - foreach ($this->backend->select()->from('serviceStatus', array('service_description')) + foreach ($this->backend->select()->from('servicestatus', array('service_description')) ->where('host_name', $this->host) ->getQuery() ->fetchAll() as $service) { diff --git a/modules/monitoring/library/Monitoring/Object/HostList.php b/modules/monitoring/library/Monitoring/Object/HostList.php index e48fcc415..76b37dc7c 100644 --- a/modules/monitoring/library/Monitoring/Object/HostList.php +++ b/modules/monitoring/library/Monitoring/Object/HostList.php @@ -12,7 +12,7 @@ use Icinga\Util\String; */ class HostList extends ObjectList { - protected $dataViewName = 'hostStatus'; + protected $dataViewName = 'hoststatus'; protected $columns = array('host_name'); diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index fc4ad7e32..08b348988 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -449,7 +449,7 @@ abstract class MonitoredObject implements Filterable */ public function fetchEventhistory() { - $eventHistory = $this->backend->select()->from('eventHistory', array( + $eventHistory = $this->backend->select()->from('eventhistory', array( 'object_type', 'host_name', 'host_display_name', diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index cb5615df1..855e62882 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -105,7 +105,7 @@ class Service extends MonitoredObject */ protected function getDataView() { - return $this->backend->select()->from('serviceStatus', array( + return $this->backend->select()->from('servicestatus', array( 'host_icon_image', 'host_icon_image_alt', 'host_acknowledged', diff --git a/modules/monitoring/library/Monitoring/Object/ServiceList.php b/modules/monitoring/library/Monitoring/Object/ServiceList.php index f96876666..8336a35a1 100644 --- a/modules/monitoring/library/Monitoring/Object/ServiceList.php +++ b/modules/monitoring/library/Monitoring/Object/ServiceList.php @@ -16,7 +16,7 @@ class ServiceList extends ObjectList protected $serviceStateSummary; - protected $dataViewName = 'serviceStatus'; + protected $dataViewName = 'servicestatus'; protected $columns = array('host_name', 'service_description'); diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php index 7ac509d7b..997a2b782 100644 --- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php +++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php @@ -181,7 +181,7 @@ abstract class MonitoredObjectController extends Controller ) ); } - if ($this->backend->hasQuery('eventHistory')) { + if ($this->backend->hasQuery('eventhistory')) { $tabs->add( 'history', array( diff --git a/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php index c32c155af..132012ba9 100644 --- a/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php +++ b/modules/monitoring/library/Monitoring/Web/Menu/MonitoringMenuItemRenderer.php @@ -38,7 +38,7 @@ class MonitoringMenuItemRenderer extends MenuItemRenderer { if (self::$summary === null) { $summary = MonitoringBackend::instance()->select()->from( - 'statusSummary', + 'statussummary', array( 'hosts_down_unhandled', 'services_critical_unhandled' From b6a7b43dd06738b1e191e708e6d87fe5d0b88423 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 14:46:46 +0200 Subject: [PATCH 138/237] MonitoringBackend: Enforce that views and queries are of a particular naming scheme I'm adding this mainly to not to break support with modules which are utilizing our queries. --- .../Monitoring/Backend/MonitoringBackend.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php index df29a6b50..012b7c110 100644 --- a/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php +++ b/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php @@ -263,21 +263,21 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface /** * View name to class name resolution * - * @param string $viewName + * @param string $view * * @return string - * @throws ProgrammingError When the view does not exist + * + * @throws ProgrammingError In case the view does not exist */ protected function buildViewClassName($view) { - $class = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($view); - if (!class_exists($class)) { - throw new ProgrammingError( - 'DataView %s does not exist', - ucfirst($view) - ); + $class = ucfirst(strtolower($view)); + $classPath = '\\Icinga\\Module\\Monitoring\\DataView\\' . $class; + if (! class_exists($classPath)) { + throw new ProgrammingError('DataView %s does not exist', $class); } - return $class; + + return $classPath; } /** @@ -287,6 +287,8 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface * @param array $columns Optional column list * * @return Icinga\Data\QueryInterface + * + * @throws ProgrammingError When the query does not exist for this backend */ public function query($name, $columns = null) { @@ -318,16 +320,15 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface /** * Query name to class name resolution * - * @param string $query + * @param string $query * * @return string - * @throws ProgrammingError When the query does not exist for this backend */ protected function buildQueryClassName($query) { $parts = preg_split('~\\\~', get_class($this)); array_pop($parts); - array_push($parts, 'Query', ucfirst($query) . 'Query'); + array_push($parts, 'Query', ucfirst(strtolower($query)) . 'Query'); return implode('\\', $parts); } } From eb93886cc7e4903bf200792adac8a45d00e460af Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 14:58:20 +0200 Subject: [PATCH 139/237] ListController: Do not apply restrictions before the filter editor is being set up Might cause the restrictions being shown to the user.. refs #9009 --- modules/monitoring/application/controllers/ListController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index fa8781006..e8760e02b 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -295,8 +295,8 @@ class Monitoring_ListController extends Controller 'host_display_name', 'service_display_name' )); - $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->notifications = $query; $this->setupLimitControl(); From 470c4a54a344931131122ac2e396a05b7ad30d08 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 16:27:13 +0200 Subject: [PATCH 140/237] Eventgrid: Add support for object restrictions refs #9009 --- .../Backend/Ido/Query/EventgridQuery.php | 116 +++++++----------- .../library/Monitoring/DataView/Eventgrid.php | 21 +++- 2 files changed, 56 insertions(+), 81 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventgridQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventgridQuery.php index 2dac92e3d..cae57b8e0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventgridQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventgridQuery.php @@ -3,89 +3,55 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; -class EventgridQuery extends IdoQuery +class EventgridQuery extends StatehistoryQuery { - protected $columnMap = array( - 'statehistory' => array( - 'day' => 'DATE(sh.state_time)', - 'cnt_events' => 'COUNT(*)', - 'objecttype_id' => 'sho.objecttype_id', - 'cnt_up' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 0 THEN 1 ELSE 0 END)', - 'cnt_down_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_down' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 THEN 1 ELSE 0 END)', - 'cnt_unreachable_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_unreachable' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 THEN 1 ELSE 0 END)', - 'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_unknown' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 THEN 1 ELSE 0 END)', - 'cnt_unknown_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_critical' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 THEN 1 ELSE 0 END)', - 'cnt_critical_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 2 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_warning' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 THEN 1 ELSE 0 END)', - 'cnt_warning_hard' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)', - 'cnt_ok' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 0 THEN 1 ELSE 0 END)', - 'host' => 'sho.name1 COLLATE latin1_general_ci', - 'service' => 'sho.name2 COLLATE latin1_general_ci', - 'host_name' => 'sho.name1', - 'service_description' => 'sho.name2', - 'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)' - ), - - 'servicegroups' => array( - 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', - 'servicegroup_name' => 'sgo.name1' - ), - - 'hostgroups' => array( - 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', - 'hostgroup_name' => 'hgo.name1' - ) + /** + * The columns additionally provided by this query + * + * @var array + */ + protected $additionalColumns = array( + 'day' => 'DATE(FROM_UNIXTIME(sth.timestamp))', + 'cnt_up' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 0 THEN 1 ELSE 0 END)", + 'cnt_down_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_down' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 THEN 1 ELSE 0 END)", + 'cnt_unreachable_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_unreachable' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 2 THEN 1 ELSE 0 END)", + 'cnt_unknown_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_unknown' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 THEN 1 ELSE 0 END)", + 'cnt_unknown_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_critical' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 THEN 1 ELSE 0 END)", + 'cnt_critical_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_warning' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 THEN 1 ELSE 0 END)", + 'cnt_warning_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)", + 'cnt_ok' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 0 THEN 1 ELSE 0 END)" ); + /** + * {@inheritdoc} + */ protected function joinBaseTables() { - $this->select->from( - array('sh' => $this->prefix . 'statehistory'), - array() - )->join( - array('sho' => $this->prefix . 'objects'), - 'sh.object_id = sho.object_id AND sho.is_active = 1', - array() - ) - ->group('DATE(sh.state_time)'); - $this->joinedVirtualTables = array('statehistory' => true); + parent::joinBaseTables(); + $this->requireVirtualTable('history'); + $this->columnMap['statehistory'] += $this->additionalColumns; + $this->select->group(array('DATE(FROM_UNIXTIME(sth.timestamp))')); } - protected function joinHostgroups() + /** + * {@inheritdoc} + */ + public function order($columnOrAlias, $dir = null) { - $this->select->join( - array('hgm' => $this->prefix . 'hostgroup_members'), - 'hgm.host_object_id = sho.object_id', - array() - )->join( - array('hgs' => $this->prefix . 'hostgroups'), - 'hgm.hostgroup_id = hgs.hostgroup_id', - array() - )->join( - array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hgs.hostgroup_object_id', - array() - ); - } + if (array_key_exists($columnOrAlias, $this->additionalColumns)) { + $subQueries = $this->subQueries; + $this->subQueries = array(); + parent::order($columnOrAlias, $dir); + $this->subQueries = $subQueries; + } else { + parent::order($columnOrAlias, $dir); + } - protected function joinServicegroups() - { - $this->select->join( - array('sgm' => $this->prefix . 'servicegroup_members'), - 'sgm.service_object_id = sho.object_id', - array() - )->join( - array('sgs' => $this->prefix . 'servicegroups'), - 'sgm.servicegroup_id = sgs.servicegroup_id', - array() - )->join( - array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sgs.servicegroup_object_id', - array() - ); + return $this; } } diff --git a/modules/monitoring/library/Monitoring/DataView/Eventgrid.php b/modules/monitoring/library/Monitoring/DataView/Eventgrid.php index b7c7e0b3a..e95ed5cf8 100644 --- a/modules/monitoring/library/Monitoring/DataView/Eventgrid.php +++ b/modules/monitoring/library/Monitoring/DataView/Eventgrid.php @@ -14,8 +14,6 @@ class Eventgrid extends DataView { return array( 'day', - 'cnt_events', - 'objecttype_id', 'cnt_up', 'cnt_down_hard', 'cnt_down', @@ -29,13 +27,16 @@ class Eventgrid extends DataView 'cnt_warning_hard', 'cnt_ok', 'host_name', + 'host_display_name', 'service_description', - 'timestamp', - 'servicegroup_name', - 'hostgroup_name' + 'service_display_name', + 'timestamp' ); } + /** + * {@inheritdoc} + */ public function getSortRules() { return array( @@ -45,8 +46,16 @@ class Eventgrid extends DataView ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { - return array('host', 'service', 'hostgroup', 'servicegroup'); + return array( + 'host', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_host_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } } From d5ade9ae74a49453d81fa819c63fb9aca9b2cac9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 12 Jun 2015 16:27:34 +0200 Subject: [PATCH 141/237] ListController: Restrict the eventgridAction refs #9009 --- modules/monitoring/application/controllers/ListController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index e8760e02b..0576d6e24 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -378,6 +378,7 @@ class Monitoring_ListController extends Controller $this->params->remove(array('objecttype', 'from', 'to', 'state', 'btn_submit')); $this->view->filter = Filter::fromQuerystring((string) $this->params); $query->applyFilter($this->view->filter); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->summary = $query->getQuery()->fetchAll(); $this->view->column = $form->getValue('state'); // $this->view->orientationBox = $orientationBox; From 07ebf11a0751003c8038194472b44a0b869bf959 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 13:47:48 +0200 Subject: [PATCH 142/237] DataView\Contact: Add support for object restrictions refs #9009 --- .../Backend/Ido/Query/ContactQuery.php | 159 +++++++++++++----- .../library/Monitoring/DataView/Contact.php | 47 +++--- 2 files changed, 147 insertions(+), 59 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php index 3d23b8947..f3a74e380 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php @@ -3,8 +3,19 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query for contacts + */ class ContactQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( 'contacts' => array( 'contact_id' => 'c.contact_id', @@ -33,18 +44,33 @@ class ContactQuery extends IdoQuery 'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci', 'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci' ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' + ), 'hosts' => array( - 'host' => 'ho.name1 COLLATE latin1_general_ci', - 'host_name' => 'ho.name1' + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'services' => array( 'service' => 'so.name2 COLLATE latin1_general_ci', 'service_description' => 'so.name2', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', 'service_host_name' => 'so.name1' ) ); + /** + * {@inheritdoc} + */ protected function joinBaseTables() { $this->select->from( @@ -52,46 +78,15 @@ class ContactQuery extends IdoQuery array() )->join( array('co' => $this->prefix . 'objects'), - 'c.contact_object_id = co.' . $this->object_id . ' AND co.is_active = 1', - array() - ); - $this->joinedVirtualTables = array('contacts' => true); - } - - protected function joinHosts() - { - $this->select->join( - array('hc' => $this->prefix . 'host_contacts'), - 'hc.contact_object_id = c.contact_object_id', - array() - )->join( - array('h' => $this->prefix . 'hosts'), - 'hc.host_id = h.host_id', - array() - )->join( - array('ho' => $this->prefix . 'objects'), - 'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1', - array() - ); - } - - protected function joinServices() - { - $this->select->join( - array('sc' => $this->prefix . 'service_contacts'), - 'sc.contact_object_id = c.contact_object_id', - array() - )->join( - array('s' => $this->prefix . 'services'), - 'sc.service_id = s.service_id', - array() - )->join( - array('so' => $this->prefix . 'objects'), - 's.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1', + 'co.object_id = c.contact_object_id AND co.is_active = 1', array() ); + $this->joinedVirtualTables['contacts'] = true; } + /** + * Join timeperiods + */ protected function joinTimeperiods() { $this->select->joinLeft( @@ -105,4 +100,90 @@ class ContactQuery extends IdoQuery array() ); } + + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('hosts'); + $this->select->joinLeft( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->joinLeft( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->joinLeft( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', + array() + ); + } + + /** + * Join hosts + */ + protected function joinHosts() + { + $this->select->joinLeft( + array('hc' => $this->prefix . 'host_contacts'), + 'hc.contact_object_id = c.contact_object_id', + array() + )->joinLeft( + array('h' => $this->prefix . 'hosts'), + 'h.host_id = hc.host_id', + array() + )->joinLeft( + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = h.host_object_id AND ho.is_active = 1', + array() + )->group( + array('c.contact_id') + ); + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->joinLeft( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->joinLeft( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.servicegroup_id = sgm.servicegroup_id', + array() + )->joinLeft( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', + array() + ); + } + + /** + * Join services + */ + protected function joinServices() + { + $this->select->joinLeft( + array('sc' => $this->prefix . 'service_contacts'), + 'sc.contact_object_id = c.contact_object_id', + array() + )->joinLeft( + array('s' => $this->prefix . 'services'), + 's.service_id = sc.service_id', + array() + )->joinLeft( + array('so' => $this->prefix . 'objects'), + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', + array() + )->group( + array('c.contact_id') + ); + } } diff --git a/modules/monitoring/library/Monitoring/DataView/Contact.php b/modules/monitoring/library/Monitoring/DataView/Contact.php index 8116e11a4..af2ef597d 100644 --- a/modules/monitoring/library/Monitoring/DataView/Contact.php +++ b/modules/monitoring/library/Monitoring/DataView/Contact.php @@ -3,26 +3,32 @@ namespace Icinga\Module\Monitoring\DataView; -/** - * Describes the data needed by the 'Contact' DataView - */ class Contact extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) { + return true; + } + + return parent::isValidFilterTarget($column); + } + + /** + * {@inheritdoc} */ public function getColumns() { return array( + 'contact_object_id', 'contact_id', 'contact_name', 'contact_alias', 'contact_email', 'contact_pager', - 'contact_notify_hosts', - 'contact_notify_services', 'contact_has_host_notfications', 'contact_has_service_notfications', 'contact_can_submit_commands', @@ -37,33 +43,34 @@ class Contact extends DataView 'contact_notify_host_unreachable', 'contact_notify_host_flapping', 'contact_notify_host_downtime', - 'contact_object_id', - 'host_object_id', - 'host_name', - 'service_object_id', - 'service_host_name', - 'service_description', 'contact_notify_host_timeperiod', 'contact_notify_service_timeperiod' ); } /** - * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort - * - * @return array + * {@inheritdoc} */ public function getSortRules() { return array( - 'contact_alias' => array( - 'order' => self::SORT_DESC + 'contact_name' => array( + 'order' => self::SORT_ASC ) ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { - return array('contact', 'alias', 'email', 'host', 'service', 'service_host'); + return array( + 'contact', + 'host', 'host_name', 'host_display_name', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } } From aabdfec03ae3bfd0292e14c55c9195885c89dc51 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 13:48:13 +0200 Subject: [PATCH 143/237] ListController: Restrict the contacts view refs #9009 --- .../application/controllers/ListController.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 0576d6e24..e8508cb83 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -312,25 +312,14 @@ class Monitoring_ListController extends Controller $query = $this->backend->select()->from('contact', array( 'contact_name', - 'contact_id', 'contact_alias', 'contact_email', 'contact_pager', 'contact_notify_service_timeperiod', - 'contact_notify_service_recovery', - 'contact_notify_service_warning', - 'contact_notify_service_critical', - 'contact_notify_service_unknown', - 'contact_notify_service_flapping', - 'contact_notify_service_downtime', - 'contact_notify_host_timeperiod', - 'contact_notify_host_recovery', - 'contact_notify_host_down', - 'contact_notify_host_unreachable', - 'contact_notify_host_flapping', - 'contact_notify_host_downtime', + 'contact_notify_host_timeperiod' )); $this->filterQuery($query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->contacts = $query; $this->setupLimitControl(); From b8efe314a00581c0c4f6c92c5e6d65d52ec84d5f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 13:59:46 +0200 Subject: [PATCH 144/237] DbQuery: Ignore wildcard only filters This increases query performance vastly, since LIKE '%' comparisons prevent the dbms from utilizing an index. --- library/Icinga/Data/Db/DbQuery.php | 15 +++++++++++++++ .../Monitoring/Backend/Ido/Query/IdoQuery.php | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index a151babf7..2f82b06b2 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -285,12 +285,27 @@ class DbQuery extends SimpleQuery if ($this->isTimestamp($col)) { $expression = $this->valueToTimestamp($expression); } + if (is_array($expression) && $sign === '=') { // TODO: Should we support this? Doesn't work for blub* return $col . ' IN (' . $this->escapeForSql($expression) . ')'; } elseif ($sign === '=' && strpos($expression, '*') !== false) { + if ($expression === '*') { + // We'll ignore such filters as it prevents index usage and because "*" means anything, anything means + // all whereas all means that whether we use a filter to match anything or no filter at all makes no + // difference, except for performance reasons... + return ''; + } + return $col . ' LIKE ' . $this->escapeForSql($this->escapeWildcards($expression)); } elseif ($sign === '!=' && strpos($expression, '*') !== false) { + if ($expression === '*') { + // We'll ignore such filters as it prevents index usage and because "*" means nothing, so whether we're + // using a real column with a valid comparison here or just an expression which cannot be evaluated to + // true makes no difference, except for performance reasons... + return $this->escapeForSql(0); + } + return $col . ' NOT LIKE ' . $this->escapeForSql($this->escapeWildcards($expression)); } else { return $col . ' ' . $sign . ' ' . $this->escapeForSql($expression); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 1feff0f71..6d0f418da 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -267,6 +267,10 @@ abstract class IdoQuery extends DbQuery protected function requireFilterColumns(Filter $filter) { if ($filter instanceof FilterExpression) { + if ($filter->getExpression() === '*') { + return; // Wildcard only filters are ignored so stop early here to avoid joining a table for nothing + } + $col = $filter->getColumn(); $this->requireColumn($col); @@ -328,6 +332,10 @@ abstract class IdoQuery extends DbQuery public function where($condition, $value = null) { + if ($value === '*') { + return $this; // Wildcard only filters are ignored so stop early here to avoid joining a table for nothing + } + $this->requireColumn($condition); $col = $this->getMappedField($condition); if ($col === null) { From 2fceac977191a9344b3c027b743a9285e26bb33a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 14:15:51 +0200 Subject: [PATCH 145/237] ListController: Fix contactgroup sorting --- .../application/controllers/ListController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index e8508cb83..d43f5395c 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -392,6 +392,11 @@ class Monitoring_ListController extends Controller )); $this->filterQuery($query); + $this->setupSortControl(array( + 'contactgroup_name' => $this->translate('Contactgroup Name'), + 'contactgroup_alias' => $this->translate('Contactgroup Alias') + ), $query); + // Fetch and prepare all contact groups: $contactgroups = $query->getQuery()->fetchAll(); $groupData = array(); @@ -406,11 +411,6 @@ class Monitoring_ListController extends Controller } // TODO: Find a better naming $this->view->groupData = $groupData; - - $this->setupSortControl(array( - 'contactgroup_name' => $this->translate('Contactgroup Name'), - 'contactgroup_alias' => $this->translate('Contactgroup Alias') - ), $query); } public function commentsAction() From 548aec4233c7c233be232d2b8d449dc84bda95f8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:08:04 +0200 Subject: [PATCH 146/237] DataView\Contactgroup: Add support for object restrictions refs #9009 --- .../Backend/Ido/Query/ContactgroupQuery.php | 155 +++++++++++++----- .../Monitoring/DataView/Contactgroup.php | 41 +++-- 2 files changed, 140 insertions(+), 56 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php index 152e964f8..8394668a4 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php @@ -3,8 +3,19 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +/** + * Query for contact groups + */ class ContactgroupQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( 'contactgroups' => array( 'contactgroup' => 'cgo.name1 COLLATE latin1_general_ci', @@ -12,11 +23,13 @@ class ContactgroupQuery extends IdoQuery 'contactgroup_alias' => 'cg.alias COLLATE latin1_general_ci' ), 'contacts' => array( + 'contact_id' => 'c.contact_id', 'contact' => 'co.name1 COLLATE latin1_general_ci', 'contact_name' => 'co.name1', 'contact_alias' => 'c.alias COLLATE latin1_general_ci', 'contact_email' => 'c.email_address COLLATE latin1_general_ci', 'contact_pager' => 'c.pager_address', + 'contact_object_id' => 'c.contact_object_id', 'contact_has_host_notfications' => 'c.host_notifications_enabled', 'contact_has_service_notfications' => 'c.service_notifications_enabled', 'contact_can_submit_commands' => 'c.can_submit_commands', @@ -30,22 +43,35 @@ class ContactgroupQuery extends IdoQuery 'contact_notify_host_down' => 'c.notify_host_down', 'contact_notify_host_unreachable' => 'c.notify_host_unreachable', 'contact_notify_host_flapping' => 'c.notify_host_flapping', - 'contact_notify_host_downtime' => 'c.notify_host_downtime', + 'contact_notify_host_downtime' => 'c.notify_host_downtime' + ), + 'hostgroups' => array( + 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', + 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', + 'hostgroup_name' => 'hgo.name1' ), 'hosts' => array( - 'host' => 'ho.name1 COLLATE latin1_general_ci', - 'host_name' => 'ho.name1' + 'host' => 'ho.name1 COLLATE latin1_general_ci', + 'host_name' => 'ho.name1', + 'host_alias' => 'h.alias', + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'servicegroups' => array( + 'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci', + 'servicegroup_name' => 'sgo.name1', + 'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci' ), 'services' => array( 'service' => 'so.name2 COLLATE latin1_general_ci', 'service_description' => 'so.name2', - 'service_host' => 'so.name1 COLLATE latin1_general_ci', + 'service_display_name' => 's.display_name COLLATE latin1_general_ci', 'service_host_name' => 'so.name1' ) ); - protected $useSubqueryCount = true; - + /** + * {@inheritdoc} + */ protected function joinBaseTables() { $this->select->from( @@ -53,81 +79,124 @@ class ContactgroupQuery extends IdoQuery array() )->join( array('cgo' => $this->prefix . 'objects'), - 'cg.contactgroup_object_id = cgo.' . $this->object_id . ' AND cgo.is_active = 1', + 'cgo.object_id = cg.contactgroup_object_id AND cgo.is_active = 1 AND cgo.objecttype_id = 11', array() ); - - $this->joinedVirtualTables = array('contactgroups' => true); + $this->joinedVirtualTables['contactgroups'] = true; } + /** + * Join contacts + */ protected function joinContacts() { - $this->select->distinct()->join( + $this->select->joinLeft( array('cgm' => $this->prefix . 'contactgroup_members'), 'cgm.contactgroup_id = cg.contactgroup_id', array() - )->join( + )->joinLeft( array('co' => $this->prefix . 'objects'), - 'cgm.contact_object_id = co.object_id AND co.is_active = 1', + 'co.object_id = cgm.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', array() - )->join( + )->joinLeft( array('c' => $this->prefix . 'contacts'), 'c.contact_object_id = co.object_id', array() ); + $this->group(array('cg.contactgroup_id', 'c.contact_id')); } + /** + * Join host groups + */ + protected function joinHostgroups() + { + $this->requireVirtualTable('hosts'); + $this->select->joinLeft( + array('hgm' => $this->prefix . 'hostgroup_members'), + 'hgm.host_object_id = ho.object_id', + array() + )->joinLeft( + array('hg' => $this->prefix . 'hostgroups'), + 'hg.hostgroup_id = hgm.hostgroup_id', + array() + )->joinLeft( + array('hgo' => $this->prefix . 'objects'), + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', + array() + ); + } + + /** + * Join hosts + */ protected function joinHosts() { - $this->select->distinct()->join( + $this->select->joinLeft( array('hcg' => $this->prefix . 'host_contactgroups'), 'hcg.contactgroup_object_id = cg.contactgroup_object_id', array() - )->join( + )->joinLeft( array('h' => $this->prefix . 'hosts'), - 'hcg.host_id = h.host_id', + 'h.host_id = hcg.host_id', array() - )->join( + )->joinLeft( array('ho' => $this->prefix . 'objects'), - 'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1', + 'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', + array() + ); + + if ($this->hasJoinedVirtualTable('contacts')) { + $this->group(array('cg.contactgroup_id', 'c.contact_id')); + } else { + $this->group(array('cg.contactgroup_id')); + } + } + + /** + * Join service groups + */ + protected function joinServicegroups() + { + $this->requireVirtualTable('services'); + $this->select->joinLeft( + array('sgm' => $this->prefix . 'servicegroup_members'), + 'sgm.service_object_id = s.service_object_id', + array() + )->joinLeft( + array('sg' => $this->prefix . 'servicegroups'), + 'sg.servicegroup_id = sgm.servicegroup_id', + array() + )->joinLeft( + array('sgo' => $this->prefix . 'objects'), + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); } + /** + * Join services + */ protected function joinServices() { -// $scgSub = $this->db->select()->distinct()->from( -// $this->prefix . 'service_contactgroups', -// array('contactgroup_object_id', 'service_id') -// ); - - /* - This subselect is a workaround for a fucking stupid bug. Other tables - may be affected too. We absolutely need uniqueness here. - - mysql> SELECT * FROM icinga_service_contactgroups WHERE - contactgroup_object_id = 143 AND service_id = 2079564; - +-------------------------+-------------+------------+------------------------+ - | service_contactgroup_id | instance_id | service_id | contactgroup_object_id | - +-------------------------+-------------+------------+------------------------+ - | 4904240 | 1 | 2079564 | 143 | - | 4904244 | 1 | 2079564 | 143 | - +-------------------------+-------------+------------+------------------------+ - */ - - $this->select->distinct()->join( + $this->select->joinLeft( array('scg' => $this->prefix . 'service_contactgroups'), - // array('scg' => $scgSub), 'scg.contactgroup_object_id = cg.contactgroup_object_id', array() - )->join( + )->joinLeft( array('s' => $this->prefix . 'services'), - 'scg.service_id = s.service_id', + 's.service_id = scg.service_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), - 's.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); + + if ($this->hasJoinedVirtualTable('contacts')) { + $this->group(array('cg.contactgroup_id', 'c.contact_id')); + } else { + $this->group(array('cg.contactgroup_id')); + } } } diff --git a/modules/monitoring/library/Monitoring/DataView/Contactgroup.php b/modules/monitoring/library/Monitoring/DataView/Contactgroup.php index 0c432c2dc..f95c5abd7 100644 --- a/modules/monitoring/library/Monitoring/DataView/Contactgroup.php +++ b/modules/monitoring/library/Monitoring/DataView/Contactgroup.php @@ -3,21 +3,30 @@ namespace Icinga\Module\Monitoring\DataView; -/** - * Describes the data needed by the Contactgroup DataView - */ class Contactgroup extends DataView { /** - * Retrieve columns provided by this view - * - * @return array + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) { + return true; + } + + return parent::isValidFilterTarget($column); + } + + /** + * {@inheritdoc} */ public function getColumns() { return array( 'contactgroup_name', 'contactgroup_alias', + 'contact_object_id', + 'contact_id', 'contact_name', 'contact_alias', 'contact_email', @@ -36,16 +45,13 @@ class Contactgroup extends DataView 'contact_notify_host_unreachable', 'contact_notify_host_flapping', 'contact_notify_host_downtime', - 'host_name', - 'service_description', - 'service_host_name' + 'contact_notify_host_timeperiod', + 'contact_notify_service_timeperiod' ); } /** - * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort - * - * @return array + * {@inheritdoc} */ public function getSortRules() { @@ -59,8 +65,17 @@ class Contactgroup extends DataView ); } + /** + * {@inheritdoc} + */ public function getFilterColumns() { - return array('contactgroup', 'contact', 'host', 'service', 'service_host'); + return array( + 'contactgroup', 'contact', + 'host', 'host_name', 'host_display_name', 'host_alias', + 'hostgroup', 'hostgroup_alias', 'hostgroup_name', + 'service', 'service_description', 'service_display_name', + 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + ); } } From 53e6d4cadc17b343df7a8939b07abdac871ddb74 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:08:25 +0200 Subject: [PATCH 147/237] ListController: Restrict the contactgroups view refs #9009 --- modules/monitoring/application/controllers/ListController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index d43f5395c..230fac50e 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -388,8 +388,9 @@ class Monitoring_ListController extends Controller 'contact_name', 'contact_alias', 'contact_email', - 'contact_pager', + 'contact_pager' )); + $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); $this->setupSortControl(array( @@ -409,6 +410,7 @@ class Monitoring_ListController extends Controller } $groupData[$c->contactgroup_name]['contacts'][] = $c; } + // TODO: Find a better naming $this->view->groupData = $groupData; } From 09d9d0084486ecfc1d7b6bf7faa94897cad60920 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:10:58 +0200 Subject: [PATCH 148/237] ContactgroupQuery: Do not use Zend_Select::group() but self::group() Avoids duplicate GROUP BY expressions. --- .../library/Monitoring/Backend/Ido/Query/ContactQuery.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php index f3a74e380..0c703b008 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php @@ -139,9 +139,8 @@ class ContactQuery extends IdoQuery array('ho' => $this->prefix . 'objects'), 'ho.object_id = h.host_object_id AND ho.is_active = 1', array() - )->group( - array('c.contact_id') ); + $this->group(array('c.contact_id')); } /** @@ -182,8 +181,7 @@ class ContactQuery extends IdoQuery array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->group( - array('c.contact_id') ); + $this->group(array('c.contact_id')); } } From 1a08102531af2648deb4ed551cd04d5e5883ce2e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:14:09 +0200 Subject: [PATCH 149/237] ListController: Apply contactgroup restrictions after the filter editor --- modules/monitoring/application/controllers/ListController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 230fac50e..7399487ea 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -390,8 +390,8 @@ class Monitoring_ListController extends Controller 'contact_email', 'contact_pager' )); - $this->applyRestriction('monitoring/filter/objects', $query); $this->filterQuery($query); + $this->applyRestriction('monitoring/filter/objects', $query); $this->setupSortControl(array( 'contactgroup_name' => $this->translate('Contactgroup Name'), From b83abc4dbc3f5725fa79285db00de6728cdb9bd4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:58:15 +0200 Subject: [PATCH 150/237] CommentController: Restrict display of single comments refs #9009 --- .../application/controllers/CommentController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentController.php b/modules/monitoring/application/controllers/CommentController.php index 7ab331adc..59ad90fc7 100644 --- a/modules/monitoring/application/controllers/CommentController.php +++ b/modules/monitoring/application/controllers/CommentController.php @@ -25,7 +25,7 @@ class Monitoring_CommentController extends Controller { $commentId = $this->params->getRequired('comment_id'); - $this->comment = $this->backend->select()->from('comment', array( + $query = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', 'objecttype' => 'object_type', 'comment' => 'comment_data', @@ -38,8 +38,10 @@ class Monitoring_CommentController extends Controller 'service_description', 'host_display_name', 'service_display_name' - ))->where('comment_internal_id', $commentId)->getQuery()->fetchRow(); + ))->where('comment_internal_id', $commentId); + $this->applyRestriction('monitoring/filter/objects', $query); + $this->comment = $query->getQuery()->fetchRow(); if ($this->comment === false) { $this->httpNotFound($this->translate('Comment not found')); } From 8187135564116718f34393beed1205a2abcab03c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:58:54 +0200 Subject: [PATCH 151/237] CommentsController: Restrict display of comments refs #9009 --- .../application/controllers/CommentsController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index 9b31755cc..a86b30310 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -30,7 +30,7 @@ class Monitoring_CommentsController extends Controller 'comment_internal_id', (string)$this->params )); - $this->comments = $this->backend->select()->from('comment', array( + $query = $this->backend->select()->from('comment', array( 'id' => 'comment_internal_id', 'objecttype' => 'object_type', 'comment' => 'comment_data', @@ -43,8 +43,10 @@ class Monitoring_CommentsController extends Controller 'service_description', 'host_display_name', 'service_display_name' - ))->addFilter($this->filter)->getQuery()->fetchAll(); + ))->addFilter($this->filter); + $this->applyRestriction('monitoring/filter/objects', $query); + $this->comments = $query->getQuery()->fetchAll(); if (false === $this->comments) { throw new Zend_Controller_Action_Exception($this->translate('Comment not found')); } From 9a6e3a7042eeb19b5fc3451b18685613eac531b8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 15:59:50 +0200 Subject: [PATCH 152/237] DowntimeController: Restrict display of single comments refs #9009 --- .../application/controllers/DowntimeController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimeController.php b/modules/monitoring/application/controllers/DowntimeController.php index 49bcd9529..077f7e264 100644 --- a/modules/monitoring/application/controllers/DowntimeController.php +++ b/modules/monitoring/application/controllers/DowntimeController.php @@ -35,7 +35,7 @@ class Monitoring_DowntimeController extends Controller { $downtimeId = $this->params->getRequired('downtime_id'); - $this->downtime = $this->backend->select()->from('downtime', array( + $query = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', @@ -55,8 +55,10 @@ class Monitoring_DowntimeController extends Controller 'service_description', 'host_display_name', 'service_display_name' - ))->where('downtime_internal_id', $downtimeId)->getQuery()->fetchRow(); + ))->where('downtime_internal_id', $downtimeId); + $this->applyRestriction('monitoring/filter/objects', $query); + $this->downtime = $query->getQuery()->fetchRow(); if ($this->downtime === false) { $this->httpNotFound($this->translate('Downtime not found')); } From 8b749521bae833748e34f5bd4feefb7a90ab8876 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:00:19 +0200 Subject: [PATCH 153/237] DowntimesController: Restrict display of downtimes refs #9009 --- .../application/controllers/DowntimesController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/DowntimesController.php b/modules/monitoring/application/controllers/DowntimesController.php index a1d210cc8..35950acfe 100644 --- a/modules/monitoring/application/controllers/DowntimesController.php +++ b/modules/monitoring/application/controllers/DowntimesController.php @@ -39,7 +39,7 @@ class Monitoring_DowntimesController extends Controller 'downtime_internal_id', (string)$this->params )); - $this->downtimes = $this->backend->select()->from('downtime', array( + $query = $this->backend->select()->from('downtime', array( 'id' => 'downtime_internal_id', 'objecttype' => 'object_type', 'comment' => 'downtime_comment', @@ -59,8 +59,10 @@ class Monitoring_DowntimesController extends Controller 'service_description', 'host_display_name', 'service_display_name' - ))->addFilter($this->filter)->getQuery()->fetchAll(); + ))->addFilter($this->filter); + $this->applyRestriction('monitoring/filter/objects', $query); + $this->downtimes = $query->getQuery()->fetchAll(); if (false === $this->downtimes) { throw new Zend_Controller_Action_Exception( $this->translate('Downtime not found') From 32c5d5a1eea5439f1d5ee50e9e0a16a97de960a6 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:03:46 +0200 Subject: [PATCH 154/237] ShowController: Restrict the servicestatus summary I doubt that this is necessary, since showing hosts and services by using this controller is deprecated, but I've added it nonetheless.. refs #9009 --- .../monitoring/application/controllers/ShowController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index 6c2c03c18..a3b748c7b 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -80,7 +80,7 @@ class Monitoring_ShowController extends Controller protected function fetchHostStats() { - $this->view->stats = $this->backend->select()->from('servicestatussummary', array( + $query = $this->backend->select()->from('servicestatussummary', array( 'services_total', 'services_ok', 'services_critical', @@ -93,7 +93,9 @@ class Monitoring_ShowController extends Controller 'services_unknown_unhandled', 'services_unknown_handled', 'services_pending', - ))->where('service_host_name', $this->params->get('host'))->getQuery()->fetchRow(); + ))->where('service_host_name', $this->params->get('host')); + $this->applyRestriction('monitoring/filter/objects', $query); + $this->view->stats = $query->getQuery()->fetchRow(); } public function contactAction() From efc52e334217ad49e44cee60f0559722afee2710 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:04:14 +0200 Subject: [PATCH 155/237] ShowController: Restrict the display of single contacts refs #9009 --- modules/monitoring/application/controllers/ShowController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index a3b748c7b..9475baff6 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -131,6 +131,7 @@ class Monitoring_ShowController extends Controller 'contact_notify_host_downtime', )); $query->where('contact_name', $contactName); + $this->applyRestriction('monitoring/filter/objects', $query); $contact = $query->getQuery()->fetchRow(); if ($contact) { @@ -153,6 +154,7 @@ class Monitoring_ShowController extends Controller )); $notifications->where('contact_object_id', $contact->contact_object_id); + $this->applyRestriction('monitoring/filter/objects', $notifications); $this->view->notifications = $notifications; $this->setupLimitControl(); $this->setupPaginationControl($this->view->notifications); From ede8cc5e83a7a8f47793b17232035b66a9ef1c04 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:04:43 +0200 Subject: [PATCH 156/237] TimelineController: Restrict the displayed entries refs #9009 --- .../application/controllers/TimelineController.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 24bc71f30..aa1e20b95 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -30,10 +30,13 @@ class Monitoring_TimelineController extends Controller $detailUrl = Url::fromPath('monitoring/list/eventhistory'); $timeline = new TimeLine( - $this->backend->select()->from('eventhistory', - array( - 'name' => 'type', - 'time' => 'timestamp' + $this->applyRestriction( + 'monitoring/filter/objects', + $this->backend->select()->from('eventhistory', + array( + 'name' => 'type', + 'time' => 'timestamp' + ) ) ), array( From a1e4e6e92b11c9b57037a65ff19e184c04ca19f4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:05:37 +0200 Subject: [PATCH 157/237] ObjectList: Implement interface Filterable Allows to use instances of it for Controller::applyRestriction(). refs #9009 --- .../library/Monitoring/Object/ObjectList.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Object/ObjectList.php b/modules/monitoring/library/Monitoring/Object/ObjectList.php index c4ecdddb2..f2e51daf2 100644 --- a/modules/monitoring/library/Monitoring/Object/ObjectList.php +++ b/modules/monitoring/library/Monitoring/Object/ObjectList.php @@ -6,10 +6,11 @@ namespace Icinga\Module\Monitoring\Object; use ArrayIterator; use Countable; use Icinga\Data\Filter\Filter; +use Icinga\Data\Filterable; use IteratorAggregate; use Icinga\Module\Monitoring\Backend\MonitoringBackend; -abstract class ObjectList implements Countable, IteratorAggregate +abstract class ObjectList implements Countable, IteratorAggregate, Filterable { /** * @var string @@ -81,9 +82,29 @@ abstract class ObjectList implements Countable, IteratorAggregate */ public function getFilter() { + if ($this->filter === null) { + $this->filter = Filter::matchAny(); + } + return $this->filter; } + public function applyFilter(Filter $filter) + { + $this->getFilter()->addFilter($filter); + return $this; + } + + public function addFilter(Filter $filter) + { + $this->getFilter()->addFilter($filter); + } + + public function where($condition, $value = null) + { + $this->getFilter()->addFilter(Filter::where($condition, $value)); + } + abstract protected function fetchObjects(); /** From ce48f63ac62664cb81d9e658e51107e73d725a56 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:05:56 +0200 Subject: [PATCH 158/237] HostsController: Restrict the display of multiple hosts refs #9009 --- modules/monitoring/application/controllers/HostsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/HostsController.php b/modules/monitoring/application/controllers/HostsController.php index eb9db57eb..5202ab087 100644 --- a/modules/monitoring/application/controllers/HostsController.php +++ b/modules/monitoring/application/controllers/HostsController.php @@ -28,6 +28,7 @@ class Monitoring_HostsController extends Controller { $hostList = new HostList($this->backend); $hostList->setFilter(Filter::fromQueryString((string) $this->params)); + $this->applyRestriction('monitoring/filter/objects', $hostList); $this->hostList = $hostList; $this->getTabs()->add( 'show', From bd41839a19300179ba0ec8a0124052cafb5f24b1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:06:13 +0200 Subject: [PATCH 159/237] ServicesController: Restrict the display of multiple services refs #9009 --- .../monitoring/application/controllers/ServicesController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 1e2bd8912..a8d7bf16b 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -30,6 +30,7 @@ class Monitoring_ServicesController extends Controller $serviceList->setFilter(Filter::fromQueryString( (string) $this->params->without(array('service_problem', 'service_handled', 'view')) )); + $this->applyRestriction('monitoring/filter/objects', $serviceList); $this->serviceList = $serviceList; $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services'); $this->getTabs()->add( From a32f505fddc020d4d478c8b1d41216c1cbca3f2f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:08:04 +0200 Subject: [PATCH 160/237] ObjectList: Fix that setFilter() violates interface Filterable refs #9009 --- modules/monitoring/library/Monitoring/Object/ObjectList.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/ObjectList.php b/modules/monitoring/library/Monitoring/Object/ObjectList.php index f2e51daf2..669e8ff39 100644 --- a/modules/monitoring/library/Monitoring/Object/ObjectList.php +++ b/modules/monitoring/library/Monitoring/Object/ObjectList.php @@ -67,11 +67,11 @@ abstract class ObjectList implements Countable, IteratorAggregate, Filterable } /** - * @param $filter + * @param Filter $filter * * @return $this */ - public function setFilter($filter) + public function setFilter(Filter $filter) { $this->filter = $filter; return $this; From c6cf51b44c87e528b2837d4407d19520b4cff2b3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:24:57 +0200 Subject: [PATCH 161/237] NotificationQuery: Force that the host and service subqueries are instantiated Quick and dirty. I do not have enough time for a more proper version... refs #9009 --- .../Monitoring/Backend/Ido/Query/NotificationQuery.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index b13a338b0..3745179a0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -159,4 +159,14 @@ class NotificationQuery extends IdoQuery } return $this; } + + /** + * {@inheritdoc} + */ + public function columns(array $columns) + { + parent::columns($columns); + $this->requireVirtualTable('hosts'); + $this->requireVirtualTable('services'); + } } From 5545b4a6056013bedd8f0cc9c25076d19f529822 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:25:48 +0200 Subject: [PATCH 162/237] AlertsummaryController: Fix filter columns --- .../application/controllers/AlertsummaryController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index 41bbca96b..e8ae0828c 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -94,7 +94,7 @@ class Monitoring_AlertsummaryController extends Controller $query->setFilter( new Icinga\Data\Filter\FilterExpression( - 'n.start_time', + 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') ) @@ -142,7 +142,7 @@ class Monitoring_AlertsummaryController extends Controller $query->setFilter( new Icinga\Data\Filter\FilterExpression( - 'n.start_time', + 'notification_start_time', '>=', $beginDate->format('Y-m-d H:i:s') ) @@ -209,7 +209,7 @@ class Monitoring_AlertsummaryController extends Controller $query->setFilter( new Icinga\Data\Filter\FilterExpression( - 'n.start_time', + 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') ) @@ -324,7 +324,7 @@ class Monitoring_AlertsummaryController extends Controller $query->setFilter( new Icinga\Data\Filter\FilterExpression( - 'n.start_time', + 'notification_start_time', '>=', $this->getBeginDate($interval)->format('Y-m-d H:i:s') ) From 4db9629268031048f70d2c29e8ee9c01d78a325b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:26:07 +0200 Subject: [PATCH 163/237] AlertsummaryController: Apply object restrictions refs #9009 --- .../controllers/AlertsummaryController.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/application/controllers/AlertsummaryController.php b/modules/monitoring/application/controllers/AlertsummaryController.php index e8ae0828c..23cc17442 100644 --- a/modules/monitoring/application/controllers/AlertsummaryController.php +++ b/modules/monitoring/application/controllers/AlertsummaryController.php @@ -70,6 +70,7 @@ class Monitoring_AlertsummaryController extends Controller 'notification_state' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); $this->view->notifications = $query; $this->setupLimitControl(); @@ -91,8 +92,9 @@ class Monitoring_AlertsummaryController extends Controller 'notification_start_time' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); - $query->setFilter( + $query->addFilter( new Icinga\Data\Filter\FilterExpression( 'notification_start_time', '>=', @@ -139,8 +141,9 @@ class Monitoring_AlertsummaryController extends Controller 'notification_start_time' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); - $query->setFilter( + $query->addFilter( new Icinga\Data\Filter\FilterExpression( 'notification_start_time', '>=', @@ -206,8 +209,9 @@ class Monitoring_AlertsummaryController extends Controller 'notification_start_time' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); - $query->setFilter( + $query->addFilter( new Icinga\Data\Filter\FilterExpression( 'notification_start_time', '>=', @@ -256,6 +260,7 @@ class Monitoring_AlertsummaryController extends Controller 'timestamp' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); $query->addFilter( new Icinga\Data\Filter\FilterExpression( @@ -321,8 +326,9 @@ class Monitoring_AlertsummaryController extends Controller 'acknowledgement_entry_time' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); - $query->setFilter( + $query->addFilter( new Icinga\Data\Filter\FilterExpression( 'notification_start_time', '>=', @@ -490,6 +496,7 @@ class Monitoring_AlertsummaryController extends Controller 'notification_state' ) ); + $this->applyRestriction('monitoring/filter/objects', $query); $query->order('notification_start_time', 'desc'); From 9876a53f8e6c56b475df4c930e95d6c26d5c7b3c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:53:13 +0200 Subject: [PATCH 164/237] DataView\Eventgrid: Allow to filter for custom variables refs #9009 --- .../library/Monitoring/DataView/Eventgrid.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/monitoring/library/Monitoring/DataView/Eventgrid.php b/modules/monitoring/library/Monitoring/DataView/Eventgrid.php index e95ed5cf8..0dafe7405 100644 --- a/modules/monitoring/library/Monitoring/DataView/Eventgrid.php +++ b/modules/monitoring/library/Monitoring/DataView/Eventgrid.php @@ -5,6 +5,18 @@ namespace Icinga\Module\Monitoring\DataView; class Eventgrid extends DataView { + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) { + return true; + } + + return parent::isValidFilterTarget($column); + } + /** * Retrieve columns provided by this view * From 7cbcb91fd7b89a2c3496d482d97187a3dad78fb2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:53:22 +0200 Subject: [PATCH 165/237] DataView\Eventhistory: Allow to filter for custom variables refs #9009 --- .../library/Monitoring/DataView/Eventhistory.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/monitoring/library/Monitoring/DataView/Eventhistory.php b/modules/monitoring/library/Monitoring/DataView/Eventhistory.php index b826b535c..223e1d7d1 100644 --- a/modules/monitoring/library/Monitoring/DataView/Eventhistory.php +++ b/modules/monitoring/library/Monitoring/DataView/Eventhistory.php @@ -5,6 +5,18 @@ namespace Icinga\Module\Monitoring\DataView; class EventHistory extends DataView { + /** + * {@inheritdoc} + */ + public function isValidFilterTarget($column) + { + if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) { + return true; + } + + return parent::isValidFilterTarget($column); + } + /** * Retrieve columns provided by this view * From 988bc2cf4441c608d5f88d1ba6e9900aed886e7a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:09:54 +0200 Subject: [PATCH 166/237] ServicestatusQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index f336ce30d..1beae3917 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -212,14 +212,8 @@ class ServicestatusQuery extends IdoQuery array() )->join( array('s' => $this->prefix . 'services'), - 's.service_object_id = so.object_id', + 's.service_object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); $this->joinedVirtualTables['services'] = true; } @@ -239,14 +233,8 @@ class ServicestatusQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - )->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group(array('so.name2', 'so.name1')); } @@ -290,15 +278,8 @@ class ServicestatusQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->group(array('so.name2', 'so.name1')); } From 1a32d289b8cbf0629b383d7d532f88e3019efbea Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:16 +0200 Subject: [PATCH 167/237] HostcommenthistoryQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/HostcommenthistoryQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index 259fe1c18..60f91cb15 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -73,14 +73,8 @@ class HostcommenthistoryQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'ho.object_id = hch.object_id', + 'ho.object_id = hch.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['commenthistory'] = true; $this->joinedVirtualTables['history'] = true; @@ -101,15 +95,8 @@ class HostcommenthistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('hch.commenthistory_id', 'ho.name1')); } @@ -142,15 +129,8 @@ class HostcommenthistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -165,15 +145,8 @@ class HostcommenthistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->select->group(array('hch.commenthistory_id', 'ho.name1')); } From 41f1d3307b2d56429f4e198ff8ed757623d2ca2a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:24 +0200 Subject: [PATCH 168/237] HostcommentQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/HostcommentQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index 080fdd905..84e9072b9 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -64,14 +64,8 @@ class HostcommentQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'ho.object_id = c.object_id', + 'ho.object_id = c.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['comments'] = true; } @@ -91,15 +85,8 @@ class HostcommentQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group(array('c.comment_id', 'ho.name1')); } @@ -144,15 +131,8 @@ class HostcommentQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -167,15 +147,8 @@ class HostcommentQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id AND so.is_active = 1', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->group(array('c.comment_id', 'ho.name1')); } From e73409eb6d440634204cf62f7cbcf33a42a376ca Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:32 +0200 Subject: [PATCH 169/237] HostdowntimeQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/HostdowntimeQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index ec9cd569b..5b7bf667c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -70,14 +70,8 @@ class HostdowntimeQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'sd.object_id = ho.object_id', + 'sd.object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['downtimes'] = true; } @@ -97,15 +91,8 @@ class HostdowntimeQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); } @@ -150,15 +137,8 @@ class HostdowntimeQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -173,15 +153,8 @@ class HostdowntimeQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id AND so.is_active = 1', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); } From 0a98cb02559ae6e5769b58bfa3000f6e590cd01b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:42 +0200 Subject: [PATCH 170/237] HostdowntimestarthistoryQuery: Improve JOIN performance refs #9009 --- .../Query/HostdowntimestarthistoryQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index 05b8307a5..94b65c5fb 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -75,14 +75,8 @@ class HostdowntimestarthistoryQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'ho.object_id = hdh.object_id', + 'ho.object_id = hdh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); if (@func_get_arg(0) === false) { @@ -110,15 +104,8 @@ class HostdowntimestarthistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); } @@ -151,15 +138,8 @@ class HostdowntimestarthistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -174,15 +154,8 @@ class HostdowntimestarthistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); } From 55a6b79ee57bb9dbe76c382b89c34a3802e2a479 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:49 +0200 Subject: [PATCH 171/237] HostgroupQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/HostgroupQuery.php | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php index a9b8ec815..45f6a8ae1 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php @@ -53,15 +53,8 @@ class HostgroupQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->joinedVirtualTables['hostgroups'] = true; } @@ -77,15 +70,8 @@ class HostgroupQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'hgm.host_object_id = ho.object_id', + 'hgm.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - ) - ->where( - 'ho.objecttype_id = ?', - 1 ); $this->group('hgo.name1'); } @@ -119,15 +105,8 @@ class HostgroupQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -143,15 +122,8 @@ class HostgroupQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id AND so.is_active = 1', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->group('hgo.name1'); } From 326013428eebd168c6394933b08c7825944958ff Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:10:55 +0200 Subject: [PATCH 172/237] HostnotificationQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/HostnotificationQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 12b4715c7..d4dea4ae1 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -112,14 +112,8 @@ class HostnotificationQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'ho.object_id = hn.object_id', + 'ho.object_id = hn.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['notifications'] = true; } @@ -178,15 +172,8 @@ class HostnotificationQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { @@ -222,15 +209,8 @@ class HostnotificationQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -245,15 +225,8 @@ class HostnotificationQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { From b774b2565fdf9e7a2e42b4a58c8d18631bee8895 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:03 +0200 Subject: [PATCH 173/237] HoststatehistoryQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/HoststatehistoryQuery.php | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php index e79acdab1..c9176d67d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -89,14 +89,8 @@ class HoststatehistoryQuery extends IdoQuery array() )->join( array('ho' => $this->prefix . 'objects'), - 'ho.object_id = hh.object_id', + 'ho.object_id = hh.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['statehistory'] = true; $this->joinedVirtualTables['history'] = true; @@ -117,15 +111,8 @@ class HoststatehistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('hh.statehistory_id', 'ho.name1')); } @@ -158,15 +145,8 @@ class HoststatehistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); } @@ -181,15 +161,8 @@ class HoststatehistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->select->group(array('hh.statehistory_id', 'ho.name1')); } From 4c3592a82e01403270fea726b38cea4095b1509f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:09 +0200 Subject: [PATCH 174/237] HoststatusQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 72f336075..fd2cd77e6 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -194,18 +194,12 @@ SQL; protected function joinBaseTables() { $this->select->from( - array('ho' => $this->prefix . 'objects'), + array('h' => $this->prefix . 'hosts'), array() )->join( - array('h' => $this->prefix . 'hosts'), - 'h.host_object_id = ho.object_id', + array('ho' => $this->prefix . 'objects'), + 'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() - )->where( - 'ho.is_active = ?', - 1 - )->where( - 'ho.objecttype_id = ?', - 1 ); $this->joinedVirtualTables['hosts'] = true; } @@ -225,15 +219,8 @@ SQL; array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group('ho.name1'); } @@ -314,15 +301,8 @@ SQL; array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->group('ho.name1'); } @@ -339,15 +319,8 @@ SQL; array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = s.service_object_id', + 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - ) - ->where( - 'so.objecttype_id = ?', - 2 ); $this->group('ho.name1'); } From a6d1115d0f17a6ba626eda23d3b6d2e891052911 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:18 +0200 Subject: [PATCH 175/237] NotificationhistoryQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/NotificationhistoryQuery.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php index 8bbdc0751..1195161d3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php @@ -26,15 +26,6 @@ class NotificationhistoryQuery extends IdoQuery ) ); - public function whereToSql($col, $sign, $expression) - { - if ($col === 'UNIX_TIMESTAMP(n.start_time)') { - return 'n.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); - } else { - return parent::whereToSql($col, $sign, $expression); - } - } - protected function joinBaseTables() { switch ($this->ds->getDbType()) { From 104c8e7a2b03b09fe8f9cfea10aac7c253772718 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:29 +0200 Subject: [PATCH 176/237] ServicecommenthistoryQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/ServicecommenthistoryQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index b0aee8d4b..5500d0570 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -74,14 +74,8 @@ class ServicecommenthistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = sch.object_id', + 'so.object_id = sch.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); $this->joinedVirtualTables['commenthistory'] = true; $this->joinedVirtualTables['history'] = true; @@ -103,15 +97,8 @@ class ServicecommenthistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); } @@ -144,15 +131,8 @@ class ServicecommenthistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); } From bf7e6b359139a1dd6bb9928983998d002018c7d3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:38 +0200 Subject: [PATCH 177/237] ServicecommentQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/ServicecommentQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php index 005ef0184..e23316377 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -69,14 +69,8 @@ class ServicecommentQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = c.object_id', + 'so.object_id = c.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = 2', - 1 ); $this->joinedVirtualTables['comments'] = true; } @@ -96,15 +90,8 @@ class ServicecommentQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } @@ -150,15 +137,8 @@ class ServicecommentQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } From 39f692e24078755ac04744d4ef57d12e850862b8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:45 +0200 Subject: [PATCH 178/237] ServicedowntimeQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/ServicedowntimeQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php index 6d528ba73..2707101ae 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -75,14 +75,8 @@ class ServicedowntimeQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'sd.object_id = so.object_id', + 'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = 2', - 1 ); $this->joinedVirtualTables['downtimes'] = true; } @@ -102,15 +96,8 @@ class ServicedowntimeQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } @@ -156,15 +143,8 @@ class ServicedowntimeQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } From c0552b092af0318f3dd99e6e1c674a6bc22b5474 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:11:54 +0200 Subject: [PATCH 179/237] ServicedowntimestarthistoryQuery: Improve JOIN performance refs #9009 --- .../ServicedowntimestarthistoryQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index 7b1f1989a..b60d13d5d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -76,14 +76,8 @@ class ServicedowntimestarthistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = sdh.object_id', + 'so.object_id = sdh.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); if (@func_get_arg(0) === false) { @@ -112,15 +106,8 @@ class ServicedowntimestarthistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); } @@ -153,15 +140,8 @@ class ServicedowntimestarthistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); } From 8bf269c2b30ad065478faef218587d183a48964a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:12:00 +0200 Subject: [PATCH 180/237] ServicegroupQuery: Improve JOIN performance refs #9009 --- .../Backend/Ido/Query/ServicegroupQuery.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php index 731a9994c..87cc12618 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php @@ -49,15 +49,8 @@ class ServicegroupQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sg.servicegroup_object_id = sgo.object_id', + 'sg.servicegroup_object_id = sgo.object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->joinedVirtualTables = array('servicegroups' => true); } @@ -78,15 +71,8 @@ class ServicegroupQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); } From 7d9b09fdc810ce6beda9f56a1e4cd901b8bea89d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:12:08 +0200 Subject: [PATCH 181/237] ServicenotificationQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/ServicenotificationQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 9f4bc51b4..a37d06707 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -113,14 +113,8 @@ class ServicenotificationQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = sn.object_id', + 'so.object_id = sn.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); $this->joinedVirtualTables['notifications'] = true; } @@ -180,15 +174,8 @@ class ServicenotificationQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { @@ -224,15 +211,8 @@ class ServicenotificationQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { From 10a65f1e27e3dbce691032a489db96d8e5bbba83 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:12:16 +0200 Subject: [PATCH 182/237] ServicestatehistoryQuery: Improve JOIN performance refs #9009 --- .../Ido/Query/ServicestatehistoryQuery.php | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php index b00ac1653..81e03646d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -90,14 +90,8 @@ class ServicestatehistoryQuery extends IdoQuery array() )->join( array('so' => $this->prefix . 'objects'), - 'so.object_id = sh.object_id', + 'so.object_id = sh.object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() - )->where( - 'so.is_active = ?', - 1 - )->where( - 'so.objecttype_id = ?', - 2 ); $this->joinedVirtualTables['statehistory'] = true; $this->joinedVirtualTables['history'] = true; @@ -119,15 +113,8 @@ class ServicestatehistoryQuery extends IdoQuery array() )->join( array('hgo' => $this->prefix . 'objects'), - 'hgo.object_id = hg.hostgroup_object_id', + 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() - )->where( - 'hgo.is_active = ?', - 1 - ) - ->where( - 'hgo.objecttype_id = ?', - 3 ); $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); } @@ -160,15 +147,8 @@ class ServicestatehistoryQuery extends IdoQuery array() )->join( array('sgo' => $this->prefix . 'objects'), - 'sgo.object_id = sg.servicegroup_object_id', + 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() - )->where( - 'sgo.is_active = ?', - 1 - ) - ->where( - 'sgo.objecttype_id = ?', - 4 ); $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); } From d4f659c5444ed3f92defad7ab98fb60401fe757a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 08:13:28 +0200 Subject: [PATCH 183/237] Revert "NotificationhistoryQuery: Improve JOIN performance" This reverts commit a6d1115d0f17a6ba626eda23d3b6d2e891052911. Accidentally commited.. --- .../Backend/Ido/Query/NotificationhistoryQuery.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php index 1195161d3..8bbdc0751 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php @@ -26,6 +26,15 @@ class NotificationhistoryQuery extends IdoQuery ) ); + public function whereToSql($col, $sign, $expression) + { + if ($col === 'UNIX_TIMESTAMP(n.start_time)') { + return 'n.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression)); + } else { + return parent::whereToSql($col, $sign, $expression); + } + } + protected function joinBaseTables() { switch ($this->ds->getDbType()) { From a70524417e9a4912fe41ed68d12a6888a5e149f7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:39:37 +0200 Subject: [PATCH 184/237] HostcommenthistoryQuery: Fix invalid joins refs #9009 --- .../Ido/Query/HostcommenthistoryQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index 60f91cb15..5202d6f79 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -85,15 +85,15 @@ class HostcommenthistoryQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -119,15 +119,15 @@ class HostcommenthistoryQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -139,11 +139,11 @@ class HostcommenthistoryQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 9a020f0218ff2d5b94b147fbdae7871c7a4a3d02 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:39:47 +0200 Subject: [PATCH 185/237] HostcommentQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HostcommentQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index 84e9072b9..d73d99ece 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -75,15 +75,15 @@ class HostcommentQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -121,15 +121,15 @@ class HostcommentQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -141,11 +141,11 @@ class HostcommentQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = h.host_object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From ba9d4538f936d6547dfa31956d022c18e3e5ba37 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:39:56 +0200 Subject: [PATCH 186/237] HostdowntimeQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HostdowntimeQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index 5b7bf667c..9132d9602 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -81,15 +81,15 @@ class HostdowntimeQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -127,15 +127,15 @@ class HostdowntimeQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -147,11 +147,11 @@ class HostdowntimeQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = h.host_object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From fee6c2f330d7c1a64d78272c2fd5727329e3f673 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:10 +0200 Subject: [PATCH 187/237] HostdowntimestarthistoryQuery: Fix invalid joins refs #9009 --- .../Ido/Query/HostdowntimestarthistoryQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index 94b65c5fb..a3d87023b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -94,15 +94,15 @@ class HostdowntimestarthistoryQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -128,15 +128,15 @@ class HostdowntimestarthistoryQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -148,11 +148,11 @@ class HostdowntimestarthistoryQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 6745b0b67756fddb3e3aef928dfa89dbe26e8bcb Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:20 +0200 Subject: [PATCH 188/237] HostgroupQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HostgroupQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php index 45f6a8ae1..6351a20ef 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php @@ -64,11 +64,11 @@ class HostgroupQuery extends IdoQuery */ protected function joinHostobjects() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.hostgroup_id = hg.hostgroup_id', array() - )->join( + )->joinLeft( array('ho' => $this->prefix . 'objects'), 'hgm.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() @@ -82,7 +82,7 @@ class HostgroupQuery extends IdoQuery protected function joinHosts() { $this->requireVirtualTable('hostobjects'); - $this->select->join( + $this->select->joinLeft( array('h' => $this->prefix . 'hosts'), 'h.host_object_id = ho.object_id', array() @@ -95,15 +95,15 @@ class HostgroupQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -116,11 +116,11 @@ class HostgroupQuery extends IdoQuery protected function joinServices() { $this->requireVirtualTable('hosts'); - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = h.host_object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 379e80b21fc1a80dbc9404e4f4fd21f9b683100b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:30 +0200 Subject: [PATCH 189/237] HostnotificationQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HostnotificationQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index d4dea4ae1..678c4b2fa 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -162,15 +162,15 @@ class HostnotificationQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -199,15 +199,15 @@ class HostnotificationQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -219,11 +219,11 @@ class HostnotificationQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 627e681e7486973a0f7af90b2b72dee71a19b142 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:40 +0200 Subject: [PATCH 190/237] HoststatehistoryQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HoststatehistoryQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php index c9176d67d..227204ed5 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -101,15 +101,15 @@ class HoststatehistoryQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -135,15 +135,15 @@ class HoststatehistoryQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -155,11 +155,11 @@ class HoststatehistoryQuery extends IdoQuery */ protected function joinServices() { - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 72e5c07da1a1fd4a7ce258e347b3808006ad6591 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:49 +0200 Subject: [PATCH 191/237] HoststatusQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index fd2cd77e6..5165897c7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -209,15 +209,15 @@ SQL; */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = ho.object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -291,15 +291,15 @@ SQL; protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() @@ -313,11 +313,11 @@ SQL; protected function joinServices() { $this->requireVirtualTable('hosts'); - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.host_object_id = h.host_object_id', array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() From 13cb52b3cbcaff3ba47e98e015e9a10a5282bd0c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:40:59 +0200 Subject: [PATCH 192/237] ServicecommenthistoryQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicecommenthistoryQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index 5500d0570..fbb5b9a13 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -87,15 +87,15 @@ class ServicecommenthistoryQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -121,15 +121,15 @@ class ServicecommenthistoryQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 1983c499b0547a98a19b0b00ff9aa8b85f29e6db Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:41:11 +0200 Subject: [PATCH 193/237] ServicecommentQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicecommentQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php index e23316377..514e998fb 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -80,15 +80,15 @@ class ServicecommentQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -127,15 +127,15 @@ class ServicecommentQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 0cc693810becd200172e2c06df139786e10b04d5 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:41:26 +0200 Subject: [PATCH 194/237] ServicedowntimeQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicedowntimeQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php index 2707101ae..970d48728 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -86,15 +86,15 @@ class ServicedowntimeQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -133,15 +133,15 @@ class ServicedowntimeQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 755da0c21090df1437245a7d05f0703151b6796b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:41:36 +0200 Subject: [PATCH 195/237] ServicedowntimestarthistoryQuery: Fix invalid joins refs #9009 --- .../Ido/Query/ServicedowntimestarthistoryQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index b60d13d5d..80c08f735 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -96,15 +96,15 @@ class ServicedowntimestarthistoryQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -130,15 +130,15 @@ class ServicedowntimestarthistoryQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 1dd21c2969462a913904e58781cc924fc1222074 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:41:43 +0200 Subject: [PATCH 196/237] ServicegroupQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicegroupQuery.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php index 87cc12618..a0c9d9849 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php @@ -61,15 +61,15 @@ class ServicegroupQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -82,7 +82,7 @@ class ServicegroupQuery extends IdoQuery protected function joinHosts() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('h' => $this->prefix . 'hosts'), 'h.host_object_id = s.host_object_id', array() @@ -94,11 +94,11 @@ class ServicegroupQuery extends IdoQuery */ protected function joinServiceobjects() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.' . $this->servicegroup_id . ' = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('so' => $this->prefix . 'objects'), 'sgm.service_object_id = so.object_id', array() @@ -112,7 +112,7 @@ class ServicegroupQuery extends IdoQuery protected function joinServices() { $this->requireVirtualTable('serviceobjects'); - $this->select->join( + $this->select->joinLeft( array('s' => $this->prefix . 'services'), 's.service_object_id = so.object_id', array() From 7a5156b0ada3b00dd6fe5d1287b0e46d9360a332 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:41:52 +0200 Subject: [PATCH 197/237] ServicenotificationQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicenotificationQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index a37d06707..9a99b6152 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -164,15 +164,15 @@ class ServicenotificationQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -201,15 +201,15 @@ class ServicenotificationQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From c11bd6d7ee644531024b651008aca2456f8e080c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:42:04 +0200 Subject: [PATCH 198/237] ServicestatehistoryQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicestatehistoryQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php index 81e03646d..1a467fc12 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -103,15 +103,15 @@ class ServicestatehistoryQuery extends IdoQuery protected function joinHostgroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -137,15 +137,15 @@ class ServicestatehistoryQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sg.' . $this->servicegroup_id . ' = sgm.servicegroup_id', array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 73e9db3704c217e4db69f078391e57ea6b6b46c3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:42:13 +0200 Subject: [PATCH 199/237] ServicestatusQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 1beae3917..723043b71 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -223,15 +223,15 @@ class ServicestatusQuery extends IdoQuery */ protected function joinHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hg.hostgroup_id = hgm.hostgroup_id', array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() @@ -268,15 +268,15 @@ class ServicestatusQuery extends IdoQuery */ protected function joinServicegroups() { - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = so.object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() From 05e0568ef15d0bb492bdbfd152280fc281804dbd Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 09:42:24 +0200 Subject: [PATCH 200/237] StatusQuery: Fix invalid joins refs #9009 --- .../Backend/Ido/Query/StatusQuery.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index 7181e8b89..5a3bba9e5 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -434,7 +434,7 @@ class StatusQuery extends IdoQuery array('so' => $this->prefix . 'objects'), 'so.' . $this->object_id . ' = s.service_object_id AND so.is_active = 1', array() - )->joinLeft( + )->join( array('ss' => $this->prefix . 'servicestatus'), 'so.' . $this->object_id . ' = ss.service_object_id', array() @@ -452,15 +452,15 @@ class StatusQuery extends IdoQuery protected function joinHostHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = h.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hgm.hostgroup_id = hg.' . $this->hostgroup_id, array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.' . $this->object_id . ' = hg.hostgroup_object_id AND hgo.is_active = 1', array() @@ -477,15 +477,15 @@ class StatusQuery extends IdoQuery protected function joinServiceHostgroups() { - $this->select->join( + $this->select->joinLeft( array('hgm' => $this->prefix . 'hostgroup_members'), 'hgm.host_object_id = s.host_object_id', array() - )->join( + )->joinLeft( array('hg' => $this->prefix . 'hostgroups'), 'hgm.hostgroup_id = hg.' . $this->hostgroup_id, array() - )->join( + )->joinLeft( array('hgo' => $this->prefix . 'objects'), 'hgo.' . $this->object_id . ' = hg.hostgroup_object_id' . ' AND hgo.is_active = 1', @@ -502,15 +502,15 @@ class StatusQuery extends IdoQuery protected function joinServicegroups() { $this->requireVirtualTable('services'); - $this->select->join( + $this->select->joinLeft( array('sgm' => $this->prefix . 'servicegroup_members'), 'sgm.service_object_id = s.service_object_id', array() - )->join( + )->joinLeft( array('sg' => $this->prefix . 'servicegroups'), 'sgm.servicegroup_id = sg.' . $this->servicegroup_id, array() - )->join( + )->joinLeft( array('sgo' => $this->prefix . 'objects'), 'sgo.' . $this->object_id. ' = sg.servicegroup_object_id' . ' AND sgo.is_active = 1', From 3cf7e93a105cf20aa992eda537ae3bc4dc231ca4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 11:39:15 +0200 Subject: [PATCH 201/237] Remove file Reftest.php Looks like an accident. refs #9009 --- Reftest.php | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Reftest.php diff --git a/Reftest.php b/Reftest.php deleted file mode 100644 index 511f3452d..000000000 --- a/Reftest.php +++ /dev/null @@ -1,23 +0,0 @@ -getFilters() as $key => &$value) { - $value = 1; - } - } - - public function &getFilters() - { - return $this->filters; - } -} - -$x = new Test(); -$b =& $x->getFilters(); -$b[1] = 0; -var_dump($b, $x->getFilters());die; From 42a1d8e56daf3b5ee6d92befa6ef366d72cb66e9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 13:29:21 +0200 Subject: [PATCH 202/237] HostnotificationQuery: Ensure that notifications not sent to a contact are fetched refs #9009 --- .../Monitoring/Backend/Ido/Query/HostnotificationQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 678c4b2fa..338680ef4 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -132,12 +132,12 @@ class HostnotificationQuery extends IdoQuery */ protected function joinContactnotifications() { - $this->select->join( + $this->select->joinLeft( array('cn' => $this->prefix . 'contactnotifications'), 'cn.notification_id = hn.notification_id', array() ); - $this->select->join( + $this->select->joinLeft( array('cno' => $this->prefix . 'objects'), 'cno.object_id = cn.contact_object_id', array() From bf70ec280268b231e2aec002ba73aebd53ac6eaa Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 13:29:31 +0200 Subject: [PATCH 203/237] ServicenotificationQuery: Ensure that notifications not sent to a contact are fetched refs #9009 --- .../Monitoring/Backend/Ido/Query/ServicenotificationQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 9a99b6152..bf7e99259 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -133,12 +133,12 @@ class ServicenotificationQuery extends IdoQuery */ protected function joinContactnotifications() { - $this->select->join( + $this->select->joinLeft( array('cn' => $this->prefix . 'contactnotifications'), 'cn.notification_id = sn.notification_id', array() ); - $this->select->join( + $this->select->joinLeft( array('cno' => $this->prefix . 'objects'), 'cno.object_id = cn.contact_object_id', array() From d5f7ee3c561dc82b292902b809de37997532d145 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 13:32:35 +0200 Subject: [PATCH 204/237] Behave nicely when showing notifications not sent out to any contact I noticed that there is no output shown for the history views in case no contact has been notified, but time is short atm... refs #9009 refs #9430 --- .../application/views/scripts/list/eventhistory.phtml | 1 + .../application/views/scripts/list/notifications.phtml | 4 ++++ .../monitoring/application/views/scripts/show/history.phtml | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index 2aedcd59b..538702a64 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -31,6 +31,7 @@ if (count($history) === 0) { case 'notify': $icon = 'bell'; $title = $this->translate('Notification'); + $msg = $msg ?: $this->translate('This notification was not sent out to any contact.'); break; case 'comment': $icon = 'comment'; diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index 3d1598a69..f94266210 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -52,6 +52,7 @@ if (count($notifications) === 0) {
contact): ?> + notification_contact_name): ?> translate('Sent to %s'), $this->qlink( @@ -60,6 +61,9 @@ if (count($notifications) === 0) { array('contact_name' => $notification->notification_contact_name) ) ) ?> + + translate('This notification was not sent out to any contact.'); ?> + diff --git a/modules/monitoring/application/views/scripts/show/history.phtml b/modules/monitoring/application/views/scripts/show/history.phtml index 0a0205e72..5c1a1d27c 100644 --- a/modules/monitoring/application/views/scripts/show/history.phtml +++ b/modules/monitoring/application/views/scripts/show/history.phtml @@ -57,11 +57,11 @@ function contactsLink($match, $view) { $title = $this->translate('Notification'); $stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state); - $msg = preg_replace_callback( + $msg = $msg ? preg_replace_callback( '/^\[([^\]]+)\]/', function($match) use ($self) { return contactsLink($match, $self); }, $msg - ); + ) : $this->translate('This notification was not sent out to any contact.'); break; case 'comment': $icon = 'comment'; From d0a7c481c2bf136257ebb9dba184be0b0c8840e9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 17:16:59 +0200 Subject: [PATCH 205/237] MonitoredObjectController: Restrict the historyAction refs #9009 --- .../Monitoring/Web/Controller/MonitoredObjectController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php index e51609f4a..ac903207e 100644 --- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php +++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php @@ -100,6 +100,7 @@ abstract class MonitoredObjectController extends Controller { $this->getTabs()->activate('history'); $this->view->history = $this->object->fetchEventHistory()->eventhistory; + $this->applyRestriction('monitoring/filter/objects', $this->view->history); $this->setupLimitControl(50); $this->setupPaginationControl($this->view->history, 50); From 670d6e93c76958a3fa83b951c559fe4f6cd5095a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 17:44:29 +0200 Subject: [PATCH 206/237] MonitoredObject: Ensure that the filter is applied to all queries refs #9009 --- .../monitoring/library/Monitoring/Object/Host.php | 4 ++-- .../library/Monitoring/Object/MonitoredObject.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index 4940ffdf1..3bb10d77e 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -151,8 +151,8 @@ class Host extends MonitoredObject $services = array(); foreach ($this->backend->select()->from('servicestatus', array('service_description')) ->where('host_name', $this->host) - ->getQuery() - ->fetchAll() as $service) { + ->applyFilter($this->getFilter()) + ->getQuery() as $service) { $services[] = new Service($this->backend, $this->host, $service->service_description); } $this->services = $services; diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 08b348988..ab7b6cdf9 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -155,7 +155,7 @@ abstract class MonitoredObject implements Filterable public function getFilter() { if ($this->filter === null) { - $this->filter = Filter::matchAny(); + $this->filter = Filter::matchAll(); } return $this->filter; } @@ -261,7 +261,7 @@ abstract class MonitoredObject implements Filterable } else { $comments->where('host_name', $this->host_name); } - $this->comments = $comments->getQuery()->fetchAll(); + $this->comments = $comments->applyFilter($this->getFilter())->getQuery()->fetchAll(); return $this; } @@ -297,7 +297,7 @@ abstract class MonitoredObject implements Filterable $downtimes ->where('host_name', $this->host_name); } - $this->downtimes = $downtimes->getQuery()->fetchAll(); + $this->downtimes = $downtimes->applyFilter($this->getFilter())->getQuery()->fetchAll(); return $this; } @@ -311,7 +311,7 @@ abstract class MonitoredObject implements Filterable $this->hostgroups = $this->backend->select() ->from('hostgroup', array('hostgroup_name', 'hostgroup_alias')) ->where('host_name', $this->host_name) - ->applyFilter($this->filter) + ->applyFilter($this->getFilter()) ->fetchPairs(); return $this; } @@ -395,7 +395,7 @@ abstract class MonitoredObject implements Filterable } else { $contacts->where('host_name', $this->host_name); } - $this->contacts = $contacts->getQuery()->fetchAll(); + $this->contacts = $contacts->applyFilter($this->getFilter())->getQuery()->fetchAll(); return $this; } @@ -438,7 +438,7 @@ abstract class MonitoredObject implements Filterable } else { $contactsGroups->where('host_name', $this->host_name); } - $this->contactgroups = $contactsGroups->getQuery()->fetchAll(); + $this->contactgroups = $contactsGroups->applyFilter($this->getFilter())->getQuery()->fetchAll(); return $this; } @@ -464,7 +464,7 @@ abstract class MonitoredObject implements Filterable if ($this->type === self::TYPE_SERVICE) { $eventHistory->where('service_description', $this->service_description); } - $this->eventhistory = $eventHistory; + $this->eventhistory = $eventHistory->applyFilter($this->getFilter()); return $this; } From 95cb6dea4bef28c2abce4d077e1111cd70dbade0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 16 Jun 2015 18:13:04 +0200 Subject: [PATCH 207/237] Transfer changes from show/history.phtml to service/history.phtml Was not recognised by git as host/history.phtml is the counterpart for show/history.phtml in the tree. refs #9009 --- .../views/scripts/service/history.phtml | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/modules/monitoring/application/views/scripts/service/history.phtml b/modules/monitoring/application/views/scripts/service/history.phtml index dd6a0b3d9..ac443c370 100644 --- a/modules/monitoring/application/views/scripts/service/history.phtml +++ b/modules/monitoring/application/views/scripts/service/history.phtml @@ -43,79 +43,68 @@ function contactsLink($match, $view) { escape($event->output); switch ($event->type) { case 'notify': $icon = 'notification'; $title = $this->translate('Notification'); $stateClass = Service::getStateText($event->state); - $msg = preg_replace_callback( + $msg = $msg ? preg_replace_callback( '/^\[([^\]]+)\]/', function($match) use ($self) { return contactsLink($match, $self); }, - $this->escape($event->output) - ); + $msg + ) : $this->translate('This notification was not sent out to any contact.'); break; case 'comment': $icon = 'comment'; $title = $this->translate('Comment'); - $msg = $this->escape($event->output); break; case 'comment_deleted': $icon = 'remove'; $title = $this->translate('Comment deleted'); - $msg = $this->escape($event->output); break; case 'ack': $icon = 'acknowledgement'; $title = $this->translate('Acknowledge'); - $msg = $this->escape($event->output); break; case 'ack_deleted': $icon = 'remove'; $title = $this->translate('Ack removed'); - $msg = $this->escape($event->output); break; case 'dt_comment': $icon = 'in_downtime'; $title = $this->translate('In Downtime'); - $msg = $this->escape($event->output); break; case 'dt_comment_deleted': $icon = 'remove'; $title = $this->translate('Downtime removed'); - $msg = $this->escape($event->output); break; case 'flapping': $icon = 'flapping'; $title = $this->translate('Flapping'); - $msg = $this->escape($event->output); break; case 'flapping_deleted': $icon = 'remove'; $title = $this->translate('Flapping stopped'); - $msg = $this->escape($event->output); break; case 'hard_state': - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); $stateClass = Service::getStateText($event->state); $icon = 'attention-alt'; $title = Service::getStateText($event->state); break; case 'soft_state': $icon = 'spinner'; - $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output); $stateClass = Service::getStateText($event->state); $title = Service::getStateText($event->state); break; case 'dt_start': $icon = 'downtime_start'; $title = $this->translate('Downtime Start'); - $msg = $this->escape($event->output); break; case 'dt_end': $icon = 'downtime_end'; $title = $this->translate('Downtime End'); - $msg = $this->escape($event->output); break; } ?> From 486fbd599b586dfbfc1826096be342dfe2c3641c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 17 Jun 2015 09:05:32 +0200 Subject: [PATCH 208/237] HoststatusQuery: Respect IDO schema version refs #9009 fixes #9425 --- .../Monitoring/Backend/Ido/Query/HoststatusQuery.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 5165897c7..f3c3bef44 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -193,6 +193,14 @@ SQL; */ protected function joinBaseTables() { + if (version_compare($this->getIdoVersion(), '1.10.0', '<')) { + $this->columnMap['hoststatus']['host_check_source'] = '(NULL)'; + } + + if (version_compare($this->getIdoVersion(), '1.13.0', '<')) { + $this->columnMap['hoststatus']['host_is_reachable'] = '(NULL)'; + } + $this->select->from( array('h' => $this->prefix . 'hosts'), array() From 5c1cdbc1c8f6c26b542c96a924d21aa3e896723e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 17 Jun 2015 10:00:29 +0200 Subject: [PATCH 209/237] IdoQuery: Join hosts and services automatically if required for customvars refs #9009 fixes #9426 --- .../library/Monitoring/Backend/Ido/Query/IdoQuery.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 6d0f418da..3ee32b40b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -634,12 +634,14 @@ abstract class IdoQuery extends DbQuery $this->customVars[$customvar] = $alias; - // TODO: extend if we allow queries with only hosts / only services - // ($leftcol s.host_object_id vs h.host_object_id if ($this->hasJoinedVirtualTable('services')) { $leftcol = 's.' . $type . '_object_id'; + } elseif ($type === 'service') { + $this->requireVirtualTable('services'); + $leftcol = 's.service_object_id'; } else { - $leftcol = 'h.' . $type . '_object_id'; + $this->requireVirtualTable('hosts'); + $leftcol = 'h.host_object_id'; } $joinOn = sprintf( From 4d7283293366d321d7783a9505a7a60d3a16085d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 17 Jun 2015 10:11:59 +0200 Subject: [PATCH 210/237] MonitoredObject: Don't apply restrictions to comments and downtimes They're already filtered by object_type and the object's name. refs #9009 --- .../monitoring/library/Monitoring/Object/MonitoredObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index ab7b6cdf9..c3d2c1da9 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -261,7 +261,7 @@ abstract class MonitoredObject implements Filterable } else { $comments->where('host_name', $this->host_name); } - $this->comments = $comments->applyFilter($this->getFilter())->getQuery()->fetchAll(); + $this->comments = $comments->getQuery()->fetchAll(); return $this; } @@ -297,7 +297,7 @@ abstract class MonitoredObject implements Filterable $downtimes ->where('host_name', $this->host_name); } - $this->downtimes = $downtimes->applyFilter($this->getFilter())->getQuery()->fetchAll(); + $this->downtimes = $downtimes->getQuery()->fetchAll(); return $this; } From 386447b847b909978b54cdb902ca748a24d32e4c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 09:29:58 +0200 Subject: [PATCH 211/237] DbQuery: Add getter for GROUP BY clauses Allows to override this in a child to provide group by clauses not until they are actually required. refs #9009 --- library/Icinga/Data/Db/DbQuery.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 2f82b06b2..28287df99 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -145,8 +145,9 @@ class DbQuery extends SimpleQuery } } - if ($this->group) { - $select->group($this->group); + $group = $this->getGroup(); + if ($group) { + $select->group($group); } $select->columns($this->columns); @@ -321,8 +322,9 @@ class DbQuery extends SimpleQuery { // TODO: there may be situations where we should clone the "select" $count = $this->dbSelect(); - if ($this->group) { - $count->group($this->group); + $group = $this->getGroup(); + if ($group) { + $count->group($group); } $this->applyFilterSql($count); if ($this->useSubqueryCount || $this->group) { @@ -393,6 +395,16 @@ class DbQuery extends SimpleQuery return $this; } + /** + * Return the GROUP BY clause + * + * @return string|array + */ + public function getGroup() + { + return $this->group; + } + /** * Return whether the given table has been joined * From 1169793213fb124b67ff10be1205fb2abfdc8e95 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 09:36:04 +0200 Subject: [PATCH 212/237] IdoQuery: Add prototype for dynamic GROUP BY clauses --- library/Icinga/Data/Db/DbQuery.php | 42 +- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 360 +++++++++++++++++- 2 files changed, 379 insertions(+), 23 deletions(-) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 28287df99..c6809ea61 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -3,13 +3,14 @@ namespace Icinga\Data\Db; -use Icinga\Data\SimpleQuery; -use Icinga\Data\Filter\FilterChain; -use Icinga\Data\Filter\FilterOr; -use Icinga\Data\Filter\FilterAnd; -use Icinga\Data\Filter\FilterNot; -use Icinga\Exception\QueryException; use Zend_Db_Select; +use Icinga\Data\Filter\FilterAnd; +use Icinga\Data\Filter\FilterChain; +use Icinga\Data\Filter\FilterNot; +use Icinga\Data\Filter\FilterOr; +use Icinga\Data\SimpleQuery; +use Icinga\Exception\ProgrammingError; +use Icinga\Exception\QueryException; /** * Database query class @@ -428,6 +429,35 @@ class DbQuery extends SimpleQuery return false; } + /** + * Return the alias used for joining the given table + * + * @param string $table + * + * @return string|null null in case no alias is being used + * + * @throws ProgrammingError In case the given table has not been joined + */ + public function getJoinedTableAlias($table) + { + $fromPart = $this->select->getPart(Zend_Db_Select::FROM); + if (isset($fromPart[$table])) { + if ($fromPart[$table]['joinType'] === Zend_Db_Select::FROM) { + throw new ProgrammingError('Table "%s" has not been joined', $table); + } + + return; // No alias in use + } + + foreach ($fromPart as $alias => $options) { + if ($options['tableName'] === $table && $options['joinType'] !== Zend_Db_Select::FROM) { + return $alias; + } + } + + throw new ProgrammingError('Table "%s" has not been joined', $table); + } + /** * Add an INNER JOIN table and colums to the query * diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 3ee32b40b..5b42ebd58 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -10,6 +10,7 @@ use Icinga\Data\Db\DbQuery; use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\FilterExpression; use Icinga\Exception\IcingaException; +use Icinga\Exception\NotImplementedError; use Icinga\Exception\ProgrammingError; use Icinga\Web\Session; @@ -46,24 +47,31 @@ abstract class IdoQuery extends DbQuery /** * The prefix to use * - * @var String + * @var string */ protected $prefix; /** - * The alias name for the index column + * An array to map aliases to table names * - * @var String + * @var array */ protected $idxAliasColumn; /** - * The table containing the index column alias + * An array to map aliases to column names * - * @var String + * @var array */ protected $idxAliasTable; + /** + * An array to map custom aliases to aliases + * + * @var array + */ + protected $idxCustomAliases; + /** * The column map containing all filterable columns * @@ -111,53 +119,235 @@ abstract class IdoQuery extends DbQuery protected $joinedVirtualTables = array(); /** - * The primary field name for the object table + * The primary key column for the instances table + * + * @var string + */ + protected $instance_id = 'instance_id'; + + /** + * The primary key column for the objects table * * @var string */ protected $object_id = 'object_id'; /** - * The primary field name for the IDO host table + * The primary key column for the acknowledgements table * * @var string */ - protected $host_id = 'host_id'; + protected $acknowledgement_id = 'acknowledgement_id'; /** - * The primary field name for the IDO hostgroup table + * The primary key column for the commenthistory table * * @var string */ - protected $hostgroup_id = 'hostgroup_id'; + protected $commenthistory_id = 'commenthistory_id'; /** - * The primary field name for the IDO service table + * The primary key column for the contactnotifications table * * @var string */ - protected $service_id = 'service_id'; + protected $contactnotification_id = 'contactnotification_id'; /** - * The primary field name for the IDO serviegroup table + * The primary key column for the downtimehistory table + * + * @var string + */ + protected $downtimehistory_id = 'downtimehistory_id'; + + /** + * The primary key column for the flappinghistory table + * + * @var string + */ + protected $flappinghistory_id = 'flappinghistory_id'; + + /** + * The primary key column for the notifications table + * + * @var string + */ + protected $notification_id = 'notification_id'; + + /** + * The primary key column for the statehistory table + * + * @var string + */ + protected $statehistory_id = 'statehistory_id'; + + /** + * The primary key column for the comments table + * + * @var string + */ + protected $comment_id = 'comment_id'; + + /** + * The primary key column for the customvariablestatus table + * + * @var string + */ + protected $customvariablestatus_id = 'customvariablestatus_id'; + + /** + * The primary key column for the hoststatus table + * + * @var string + */ + protected $hoststatus_id = 'hoststatus_id'; + + /** + * The primary key column for the programstatus table + * + * @var string + */ + protected $programstatus_id = 'programstatus_id'; + + /** + * The primary key column for the runtimevariables table + * + * @var string + */ + protected $runtimevariable_id = 'runtimevariable_id'; + + /** + * The primary key column for the scheduleddowntime table + * + * @var string + */ + protected $scheduleddowntime_id = 'scheduleddowntime_id'; + + /** + * The primary key column for the servicestatus table + * + * @var string + */ + protected $servicestatus_id = 'servicestatus_id'; + + /** + * The primary key column for the contactstatus table + * + * @var string + */ + protected $contactstatus_id = 'contactstatus_id'; + + /** + * The primary key column for the commands table + * + * @var string + */ + protected $command_id = 'command_id'; + + /** + * The primary key column for the contactgroup_members table + * + * @var string + */ + protected $contactgroup_member_id = 'contactgroup_member_id'; + + /** + * The primary key column for the contactgroups table + * + * @var string + */ + protected $contactgroup_id = 'contactgroup_id'; + + /** + * The primary key column for the contacts table + * + * @var string + */ + protected $contact_id = 'contact_id'; + + /** + * The primary key column for the customvariables table + * + * @var string + */ + protected $customvariable_id = 'customvariable_id'; + + /** + * The primary key column for the host_contactgroups table + * + * @var string + */ + protected $host_contactgroup_id = 'host_contactgroup_id'; + + /** + * The primary key column for the host_contacts table + * + * @var string + */ + protected $host_contact_id = 'host_contact_id'; + + /** + * The primary key column for the hostgroup_members table + * + * @var string + */ + protected $hostgroup_member_id = 'hostgroup_member_id'; + + /** + * The primary key column for the hostgroups table + * + * @var string + */ + protected $hostgroup_id = 'hostgroup_id'; + + /** + * The primary key column for the hosts table + * + * @var string + */ + protected $host_id = 'host_id'; + + /** + * The primary key column for the service_contactgroup table + * + * @var string + */ + protected $service_contactgroup_id = 'service_contactgroup_id'; + + /** + * The primary key column for the service_contact table + * + * @var string + */ + protected $service_contact_id = 'service_contact_id'; + + /** + * The primary key column for the servicegroup_members table + * + * @var string + */ + protected $servicegroup_member_id = 'servicegroup_member_id'; + + /** + * The primary key column for the servicegroups table * * @var string */ protected $servicegroup_id = 'servicegroup_id'; /** - * The primary field name for the IDO contact table + * The primary key column for the services table * * @var string */ - protected $contact_id = 'contact_id'; + protected $service_id = 'service_id'; /** - * The primary field name for the IDO contactgroup table + * The primary key column for the timeperiods table * * @var string */ - protected $contactgroup_id = 'contactgroup_id'; + protected $timeperiod_id = 'timeperiod_id'; /** * An array containing Column names that cause an aggregation of the query @@ -483,6 +673,8 @@ abstract class IdoQuery extends DbQuery } if (is_int($alias)) { $alias = $col; + } else { + $this->idxCustomAliases[$alias] = $col; } $resolvedColumns[$alias] = preg_replace('|\n|', ' ', $name); @@ -688,6 +880,11 @@ abstract class IdoQuery extends DbQuery return $this->idxAliasColumn[$alias]; } + public function customAliasToAlias($alias) + { + return $this->idxCustomAliases[$alias]; + } + /** * Create a sub query * @@ -714,12 +911,55 @@ abstract class IdoQuery extends DbQuery */ public function columns(array $columns) { + $this->idxCustomAliases = array(); $this->columns = $this->resolveColumns($columns); // TODO: we need to refresh our select! // $this->select->columns($columns); return $this; } + /** + * {@inheritdoc} + */ + public function _getGroup() + { + throw new NotImplementedError('Does not work in its current state but will, probably, in the future'); + + // TODO: order by?? + $group = parent::getGroup(); + if (! empty($group) && $this->ds->getDbType() === 'pgsql') { + $group = is_array($group) ? $group : array($group); + foreach ($this->columns as $alias => $column) { + if ($column instanceof Zend_Db_Expr) { + continue; + } + + // TODO: What if $alias is neither a native nor a custom alias??? + $table = $this->aliasToTableName( + $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias) + ); + + // TODO: We cannot rely on the underlying select here, tables may be joined multiple times with + // different aliases so the only way to get the correct alias here is to register such by ourself + // for each virtual column (We may also inspect $column for the alias but this will probably lead + // to false positives.. AND prevents custom implementations from providing their own "mapping") + if (($tableAlias = $this->getJoinedTableAlias($this->prefix . $table)) === null) { + $tableAlias = $table; + } + + // TODO: Same issue as with identifying table aliases; Our virtual tables are not named exactly how + // they are in the IDO. We definitely need to register aliases explicitly (hint: DbRepository + // is already providing such..) + $aliasedPk = $tableAlias . '.' . $this->getPrimaryKeyColumn($table); + if (! in_array($aliasedPk, $group)) { + $group[] = $aliasedPk; + } + } + } + + return $group; + } + // TODO: Move this away, see note related to $idoVersion var protected function getIdoVersion() { @@ -745,4 +985,90 @@ abstract class IdoQuery extends DbQuery } return self::$idoVersion; } + + /** + * Return the name of the primary key column for the given table name + * + * @param string $table + * + * @return string + * + * @throws ProgrammingError In case $table is unknown + */ + protected function getPrimaryKeyColumn($table) + { + // TODO: For god's sake, make this being a mapping + // (instead of matching a ton of properties using a ridiculous long switch case) + switch ($table) + { + case 'instances': + return $this->instance_id; + case 'objects': + return $this->object_id; + case 'acknowledgements': + return $this->acknowledgement_id; + case 'commenthistory': + return $this->commenthistory_id; + case 'contactnotifiations': + return $this->contactnotification_id; + case 'downtimehistory': + return $this->downtimehistory_id; + case 'flappinghistory': + return $this->flappinghistory_id; + case 'notifications': + return $this->notification_id; + case 'statehistory': + return $this->statehistory_id; + case 'comments': + return $this->comment_id; + case 'customvariablestatus': + return $this->customvariablestatus_id; + case 'hoststatus': + return $this->hoststatus_id; + case 'programstatus': + return $this->programstatus_id; + case 'runtimevariables': + return $this->runtimevariable_id; + case 'scheduleddowntime': + return $this->scheduleddowntime_id; + case 'servicestatus': + return $this->servicestatus_id; + case 'contactstatus': + return $this->contactstatus_id; + case 'commands': + return $this->command_id; + case 'contactgroup_members': + return $this->contactgroup_member_id; + case 'contactgroups': + return $this->contactgroup_id; + case 'contacts': + return $this->contact_id; + case 'customvariables': + return $this->customvariable_id; + case 'host_contactgroups': + return $this->host_contactgroup_id; + case 'host_contacts': + return $this->host_contact_id; + case 'hostgroup_members': + return $this->hostgroup_member_id; + case 'hostgroups': + return $this->hostgroup_id; + case 'hosts': + return $this->host_id; + case 'service_contactgroups': + return $this->service_contactgroup_id; + case 'service_contacts': + return $this->service_contact_id; + case 'servicegroup_members': + return $this->servicegroup_member_id; + case 'servicegroups': + return $this->servicegroup_id; + case 'services': + return $this->service_id; + case 'timeperiods': + return $this->timeperiod_id; + default: + throw new ProgrammingError('Cannot provide a primary key column. Table "%s" is unknown', $table); + } + } } From 9cfca36f46614491b95a2913721c77630e944ff4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 09:39:23 +0200 Subject: [PATCH 213/237] ContactQuery: PostgreSQL grouping.. refs #9009 --- .../Backend/Ido/Query/ContactQuery.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php index 0c703b008..cd72c4782 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php @@ -140,7 +140,6 @@ class ContactQuery extends IdoQuery 'ho.object_id = h.host_object_id AND ho.is_active = 1', array() ); - $this->group(array('c.contact_id')); } /** @@ -182,6 +181,22 @@ class ContactQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->group(array('c.contact_id')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hosts') || $this->hasJoinedVirtualTable('services')) { + $group = array('c.contact_id', 'co.object_id'); + if ($this->hasJoinedVirtualTable('timeperiods')) { + $group[] = 'ht.timeperiod_id'; + $group[] = 'st.timeperiod_id'; + } + } + + return $group; } } From 535b740d0e9216ac37c3f79d66f80a6c9d48cac3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:09:50 +0200 Subject: [PATCH 214/237] ContactgroupQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/ContactgroupQuery.php | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php index 8394668a4..83934d811 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php @@ -103,7 +103,6 @@ class ContactgroupQuery extends IdoQuery 'c.contact_object_id = co.object_id', array() ); - $this->group(array('cg.contactgroup_id', 'c.contact_id')); } /** @@ -145,12 +144,6 @@ class ContactgroupQuery extends IdoQuery 'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() ); - - if ($this->hasJoinedVirtualTable('contacts')) { - $this->group(array('cg.contactgroup_id', 'c.contact_id')); - } else { - $this->group(array('cg.contactgroup_id')); - } } /** @@ -192,11 +185,29 @@ class ContactgroupQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); + } - if ($this->hasJoinedVirtualTable('contacts')) { - $this->group(array('cg.contactgroup_id', 'c.contact_id')); - } else { - $this->group(array('cg.contactgroup_id')); + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hosts') || $this->hasJoinedVirtualTable('services')) { + $group = array('cg.contactgroup_id', 'cgo.object_id'); + if ($this->hasJoinedVirtualTable('contacts')) { + $group[] = 'c.contact_id'; + $group[] = 'co.object_id'; + } + } elseif ($this->hasJoinedVirtualTable('contacts')) { + $group = array( + 'cg.contactgroup_id', + 'cgo.object_id', + 'c.contact_id', + 'co.object_id' + ); } + + return $group; } } From 6e40b79b0d381d85845df1d1101835da21de884b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:37:27 +0200 Subject: [PATCH 215/237] DataView\Downtime: Add missing columns host_ and service_state --- modules/monitoring/library/Monitoring/DataView/Downtime.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php index 29114180c..605aca454 100644 --- a/modules/monitoring/library/Monitoring/DataView/Downtime.php +++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php @@ -41,10 +41,12 @@ class Downtime extends DataView 'downtime_start', 'host_display_name', 'host_name', + 'host_state', 'object_type', 'service_description', 'service_display_name', - 'service_host_name' + 'service_host_name', + 'service_state' ); } From 72de85ab7bd1d2452461f7ba2b6122350863526b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:37:54 +0200 Subject: [PATCH 216/237] HostdowntimeQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/HostdowntimeQuery.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php index 9132d9602..63acc17fc 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeQuery.php @@ -94,7 +94,6 @@ class HostdowntimeQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); } /** @@ -156,6 +155,25 @@ class HostdowntimeQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->group(array('sd.scheduleddowntime_id', 'ho.name1')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups') || $this->hasJoinedVirtualTable('services')) { + $group = array('sd.scheduleddowntime_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + } + + return $group; } } From 068c0b6ed269481038edc194f62b4031205ec6da Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:38:15 +0200 Subject: [PATCH 217/237] ServicedowntimeQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/ServicedowntimeQuery.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php index 970d48728..09162ea35 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeQuery.php @@ -99,7 +99,6 @@ class ServicedowntimeQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } /** @@ -146,7 +145,6 @@ class ServicedowntimeQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->group(array('sd.scheduleddowntime_id', 'so.name2', 'so.name1')); } /** @@ -172,4 +170,33 @@ class ServicedowntimeQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('sd.scheduleddowntime_id', 'so.object_id'); + + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 's.service_id'; + } + + if ($this->hasJoinedVirtualTable('servicestatus')) { + $group[] = 'ss.servicestatus_id'; + } + } + + return $group; + } } From 8ec494c96223b30a8f82e9506f9a8e026cd0029d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:58:59 +0200 Subject: [PATCH 218/237] HostnotificationQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/HostnotificationQuery.php | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 338680ef4..f2bbe5f47 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -124,7 +124,6 @@ class HostnotificationQuery extends IdoQuery protected function joinHistory() { $this->requireVirtualTable('contactnotifications'); - $this->group(array('hn.notification_id', 'ho.name1')); } /** @@ -142,7 +141,6 @@ class HostnotificationQuery extends IdoQuery 'cno.object_id = cn.contact_object_id', array() ); - $this->group(array('cn.contactnotification_id', 'ho.name1')); } /** @@ -175,10 +173,6 @@ class HostnotificationQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - - if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $this->group(array('hn.notification_id', 'ho.name1')); - } } /** @@ -228,9 +222,36 @@ class HostnotificationQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); + } - if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $this->group(array('hn.notification_id', 'ho.name1')); + /** + * {@inheritdoc} + */ + public function getGroup() + { + if ( + $this->hasJoinedVirtualTable('history') + || $this->hasJoinedVirtualTable('services') + || $this->hasJoinedVirtualTable('hostgroups') + ) { + $group = array('hn.notification_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { + $group[] = 'cno.object_id'; + } + } elseif ($this->hasJoinedVirtualTable('contactnotifications')) { + $group = array('hn.notification_id', 'cno.object_id', 'ho.object_id'); } + + if (! empty($group)) { + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('acknowledgements')) { + $group[] = 'a.acknowledgement_id'; + } + } + + return $group; } } From 4f42da49a8aa5649e19d4f9e4f0b2c0c0f27c1ea Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 10:59:52 +0200 Subject: [PATCH 219/237] ServicenotificationQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/ServicenotificationQuery.php | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index bf7e99259..c5f68db85 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -125,7 +125,6 @@ class ServicenotificationQuery extends IdoQuery protected function joinHistory() { $this->requireVirtualTable('contactnotifications'); - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); } /** @@ -143,7 +142,6 @@ class ServicenotificationQuery extends IdoQuery 'cno.object_id = cn.contact_object_id', array() ); - $this->group(array('cn.contactnotification_id', 'so.name2', 'so.name1')); } /** @@ -177,10 +175,6 @@ class ServicenotificationQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - - if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); - } } /** @@ -214,10 +208,6 @@ class ServicenotificationQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - - if (! $this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $this->group(array('sn.notification_id', 'so.name2', 'so.name1')); - } } /** @@ -231,4 +221,40 @@ class ServicenotificationQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ( + $this->hasJoinedVirtualTable('history') + || $this->hasJoinedVirtualTable('hostgroups') + || $this->hasJoinedVirtualTable('servicegroups') + ) { + $group = array('sn.notification_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { + $group[] = 'cno.object_id'; + } + } elseif ($this->hasJoinedVirtualTable('contactnotifications')) { + $group = array('sn.notification_id', 'cno.object_id', 'so.object_id'); + } + + if (! empty($group)) { + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 's.service_id'; + } + + if ($this->hasJoinedVirtualTable('acknowledgements')) { + $group[] = 'a.acknowledgement_id'; + } + } + + return $group; + } } From 99b0d63e941171246a1f215f5f131e4006ee55e8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 11:17:14 +0200 Subject: [PATCH 220/237] HostcommentQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/HostcommentQuery.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php index d73d99ece..63b76fa22 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentQuery.php @@ -88,7 +88,6 @@ class HostcommentQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group(array('c.comment_id', 'ho.name1')); } /** @@ -150,6 +149,25 @@ class HostcommentQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->group(array('c.comment_id', 'ho.name1')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('c.comment_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + } + + return $group; } } From d66b7e85e745159bd49cc02001e16bd77c6fb531 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 11:17:36 +0200 Subject: [PATCH 221/237] ServicecommentQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/ServicecommentQuery.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php index 514e998fb..d4eca1aa8 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentQuery.php @@ -93,7 +93,6 @@ class ServicecommentQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } /** @@ -140,7 +139,6 @@ class ServicecommentQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->group(array('c.comment_id', 'so.name2', 'so.name1')); } /** @@ -166,4 +164,32 @@ class ServicecommentQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('c.comment_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 's.service_id'; + } + + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + + if ($this->hasJoinedVirtualTable('servicestatus')) { + $group[] = 'ss.servicestatus_id'; + } + } + + return $group; + } } From b128bef8f0f9e8c3d821a0f8115ce8b91f6042c4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 11:29:26 +0200 Subject: [PATCH 222/237] HostgroupQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/HostgroupQuery.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php index 6351a20ef..5144953c2 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php @@ -73,7 +73,6 @@ class HostgroupQuery extends IdoQuery 'hgm.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', array() ); - $this->group('hgo.name1'); } /** @@ -125,6 +124,18 @@ class HostgroupQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->group('hgo.name1'); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostobjects')) { + $group = array('hg.hostgroup_id', 'hgo.object_id'); + } + + return $group; } } From b9479e7da45bcf06feea155efd2b38cb2da3de54 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 11:33:09 +0200 Subject: [PATCH 223/237] ServicegroupQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/ServicegroupQuery.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php index a0c9d9849..7c2aafc36 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php @@ -103,7 +103,6 @@ class ServicegroupQuery extends IdoQuery 'sgm.service_object_id = so.object_id', array() ); - $this->group('sgo.name1'); } /** @@ -118,4 +117,17 @@ class ServicegroupQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('serviceobjects')) { + $group = array('sg.servicegroup_id', 'sgo.object_id'); + } + + return $group; + } } From 37103cf72d1674798db51ba254650ef150bfe2ce Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 11:52:58 +0200 Subject: [PATCH 224/237] HoststatusQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index f3c3bef44..30adf696f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -230,7 +230,6 @@ SQL; 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group('ho.name1'); } /** @@ -312,7 +311,6 @@ SQL; 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->group('ho.name1'); } /** @@ -330,7 +328,6 @@ SQL; 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->group('ho.name1'); } /** @@ -371,4 +368,40 @@ SQL; array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) { + $group = array('h.host_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + + if ($this->hasJoinedVirtualTable('serviceproblemsummary')) { + $group[] = 'sps.unhandled_services_count'; + } + + if ($this->hasJoinedVirtualTable('lasthostackcomment')) { + $group[] = 'hlac.last_ack_data'; + } + + if ($this->hasJoinedVirtualTable('lasthostcomment')) { + $group[] = 'hlc.last_comment_data'; + } + + if ($this->hasJoinedVirtualTable('lasthostdowntimecomment')) { + $group[] = 'hldc.last_downtime_data'; + } + + if ($this->hasJoinedVirtualTable('lasthostflappingcomment')) { + $group[] = 'hlfc.last_flapping_data'; + } + } + + return $group; + } } From e181c57a7081b54e15ce5b5ebbeb0dd58daf885c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 12:08:05 +0200 Subject: [PATCH 225/237] ServicestatusQuery: PostgreSQL grouping... refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 723043b71..577ad16af 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -236,7 +236,6 @@ class ServicestatusQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->group(array('so.name2', 'so.name1')); } /** @@ -281,7 +280,6 @@ class ServicestatusQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->group(array('so.name2', 'so.name1')); } /** @@ -296,4 +294,28 @@ class ServicestatusQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('s.service_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + + if ($this->hasJoinedVirtualTable('hoststatus')) { + $group[] = 'hs.hoststatus_id'; + } + + if ($this->hasJoinedVirtualTable('servicestatus')) { + $group[] = 'ss.servicestatus_id'; + } + } + + return $group; + } } From b24b650a94be0b6619912ebef3655a4d40e2f035 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 12:34:30 +0200 Subject: [PATCH 226/237] HoststatusQuery: Group by host- and servicegroup pk's if required refs #9009 --- .../Backend/Ido/Query/HoststatusQuery.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php index 30adf696f..3feb37a9e 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php @@ -400,6 +400,50 @@ SQL; if ($this->hasJoinedVirtualTable('lasthostflappingcomment')) { $group[] = 'hlfc.last_flapping_data'; } + + if ($this->hasJoinedVirtualTable('hostgroups')) { + $selected = false; + foreach ($this->columns as $alias => $column) { + if ($column instanceof Zend_Db_Expr) { + continue; + } + + $table = $this->aliasToTableName( + $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias) + ); + if ($table === 'hostgroups') { + $selected = true; + break; + } + } + + if ($selected) { + $group[] = 'hg.hostgroup_id'; + $group[] = 'hgo.object_id'; + } + } + + if ($this->hasJoinedVirtualTable('servicegroups')) { + $selected = false; + foreach ($this->columns as $alias => $column) { + if ($column instanceof Zend_Db_Expr) { + continue; + } + + $table = $this->aliasToTableName( + $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias) + ); + if ($table === 'servicegroups') { + $selected = true; + break; + } + } + + if ($selected) { + $group[] = 'sg.servicegroup_id'; + $group[] = 'sgo.object_id'; + } + } } return $group; From 5ef56fc9b275994ed145232004a61ca1d2c993db Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 12:34:49 +0200 Subject: [PATCH 227/237] ServicestatusQuery: Group by host- and servicegroup pk's if required refs #9009 --- .../Backend/Ido/Query/ServicestatusQuery.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php index 577ad16af..0a03f273d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatusQuery.php @@ -3,6 +3,8 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Zend_Db_Expr; + /** * Query for service status */ @@ -314,6 +316,50 @@ class ServicestatusQuery extends IdoQuery if ($this->hasJoinedVirtualTable('servicestatus')) { $group[] = 'ss.servicestatus_id'; } + + if ($this->hasJoinedVirtualTable('hostgroups')) { + $selected = false; + foreach ($this->columns as $alias => $column) { + if ($column instanceof Zend_Db_Expr) { + continue; + } + + $table = $this->aliasToTableName( + $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias) + ); + if ($table === 'hostgroups') { + $selected = true; + break; + } + } + + if ($selected) { + $group[] = 'hg.hostgroup_id'; + $group[] = 'hgo.object_id'; + } + } + + if ($this->hasJoinedVirtualTable('servicegroups')) { + $selected = false; + foreach ($this->columns as $alias => $column) { + if ($column instanceof Zend_Db_Expr) { + continue; + } + + $table = $this->aliasToTableName( + $this->hasAliasName($alias) ? $alias : $this->customAliasToAlias($alias) + ); + if ($table === 'servicegroups') { + $selected = true; + break; + } + } + + if ($selected) { + $group[] = 'sg.servicegroup_id'; + $group[] = 'sgo.object_id'; + } + } } return $group; From a43cae9eb8534e529557158e9550489c64e0e61d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 12:35:21 +0200 Subject: [PATCH 228/237] HostgroupsummaryQuery: PostgreSQL grouping... refs #9009 --- .../Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php index 7688d9292..e3524fc58 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupsummaryQuery.php @@ -113,7 +113,7 @@ class HostgroupsummaryQuery extends IdoQuery $this->subQueries[] = $services; $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); $this->select->from(array('statussummary' => $this->summaryQuery), array()); - $this->group('hostgroup_name'); + $this->group(array('hostgroup_name', 'hostgroup_alias')); $this->joinedVirtualTables['hoststatussummary'] = true; } From b25d8e2f3469e3a985675003cd24423479776285 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 12:35:41 +0200 Subject: [PATCH 229/237] ServicegroupsummaryQuery: PostgreSQL grouping... refs #9009 --- .../Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php index 765ca7f7a..f7519edc7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupsummaryQuery.php @@ -105,7 +105,7 @@ class ServicegroupsummaryQuery extends IdoQuery $this->subQueries[] = $services; $this->summaryQuery = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); $this->select->from(array('statussummary' => $this->summaryQuery), array()); - $this->group('servicegroup_name'); + $this->group(array('servicegroup_name', 'servicegroup_alias')); $this->joinedVirtualTables['servicestatussummary'] = true; } From 5c19c05a8ab28a8adbcb51d88a944d97385ffe9b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:18:21 +0200 Subject: [PATCH 230/237] HoststatehistoryQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/HoststatehistoryQuery.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php index 227204ed5..8cb3b0964 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -114,7 +114,6 @@ class HoststatehistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('hh.statehistory_id', 'ho.name1')); } /** @@ -164,6 +163,21 @@ class HoststatehistoryQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->select->group(array('hh.statehistory_id', 'ho.name1')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) { + $group = array('hh.statehistory_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + } + + return $group; } } From b56114c82432786955a4115f8c5343ea7189a707 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:18:40 +0200 Subject: [PATCH 231/237] ServicestatehistoryQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/ServicestatehistoryQuery.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php index 1a467fc12..4c8ce7082 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -116,7 +116,6 @@ class ServicestatehistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); } /** @@ -150,7 +149,6 @@ class ServicestatehistoryQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->select->group(array('sh.statehistory_id', 'so.name1', 'so.name2')); } /** @@ -164,4 +162,21 @@ class ServicestatehistoryQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('sh.statehistory_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 'h.host_id'; + $group[] = 's.service_id'; + } + } + + return $group; + } } From f20193edb914e437055f287f6ee838d6edb2b0fa Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:18:52 +0200 Subject: [PATCH 232/237] HostcommenthistoryQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/HostcommenthistoryQuery.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index 5202d6f79..031c3f795 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -98,7 +98,6 @@ class HostcommenthistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('hch.commenthistory_id', 'ho.name1')); } /** @@ -148,6 +147,21 @@ class HostcommenthistoryQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->select->group(array('hch.commenthistory_id', 'ho.name1')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) { + $group = array('hch.commenthistory_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + } + + return $group; } } From 11ed6d6cfac1cf13363f52dc1b85660ab391f980 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:19:01 +0200 Subject: [PATCH 233/237] ServicecommenthistoryQuery: PostgreSQL grouping... refs #9009 --- .../Ido/Query/ServicecommenthistoryQuery.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index fbb5b9a13..e1388cc0f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -100,7 +100,6 @@ class ServicecommenthistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); } /** @@ -134,7 +133,6 @@ class ServicecommenthistoryQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->select->group(array('sch.commenthistory_id', 'so.name1', 'so.name2')); } /** @@ -148,4 +146,21 @@ class ServicecommenthistoryQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('sch.commenthistory_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 'h.host_id'; + $group[] = 's.service_id'; + } + } + + return $group; + } } From dc66c24a1da418cb08fe360d37fe7a703ccbbfe1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:19:14 +0200 Subject: [PATCH 234/237] HostdowntimestarthistoryQuery: PostgreSQL grouping... refs #9009 --- .../Query/HostdowntimestarthistoryQuery.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index a3d87023b..63c08845c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -107,7 +107,6 @@ class HostdowntimestarthistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); } /** @@ -157,6 +156,21 @@ class HostdowntimestarthistoryQuery extends IdoQuery 'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2', array() ); - $this->select->group(array('hdh.downtimehistory_id', 'ho.name1')); + } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('services')) { + $group = array('hdh.downtimehistory_id', 'ho.object_id'); + if ($this->hasJoinedVirtualTable('hosts')) { + $group[] = 'h.host_id'; + } + } + + return $group; } } From 77fe09487031dd8119610130042c1a9f9cddc49d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 13:19:25 +0200 Subject: [PATCH 235/237] ServicedowntimestarthistoryQuery: PostgreSQL grouping... refs #9009 --- .../ServicedowntimestarthistoryQuery.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index 80c08f735..5cadcc01c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -109,7 +109,6 @@ class ServicedowntimestarthistoryQuery extends IdoQuery 'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3', array() ); - $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); } /** @@ -143,7 +142,6 @@ class ServicedowntimestarthistoryQuery extends IdoQuery 'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4', array() ); - $this->select->group(array('sdh.downtimehistory_id', 'so.name1', 'so.name2')); } /** @@ -157,4 +155,21 @@ class ServicedowntimestarthistoryQuery extends IdoQuery array() ); } + + /** + * {@inheritdoc} + */ + public function getGroup() + { + $group = array(); + if ($this->hasJoinedVirtualTable('hostgroups') || $this->hasJoinedVirtualTable('servicegroups')) { + $group = array('sdh.downtimehistory_id', 'so.object_id'); + if ($this->hasJoinedVirtualTable('services')) { + $group[] = 'h.host_id'; + $group[] = 's.service_id'; + } + } + + return $group; + } } From f2425a97d5f8f5ca4321b27a99824552bfe26508 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 14:33:41 +0200 Subject: [PATCH 236/237] Select -1 as `state' for history queries not providing a valid state PostgreSQL does not seem to be able to union null values with integers... refs #9009 --- .../Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php | 2 +- .../Backend/Ido/Query/HostdowntimestarthistoryQuery.php | 2 +- .../Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php | 2 +- .../Backend/Ido/Query/ServicedowntimestarthistoryQuery.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index 031c3f795..1931b6638 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -26,7 +26,7 @@ class HostcommenthistoryQuery extends IdoQuery 'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)", 'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)', 'object_id' => 'hch.object_id', - 'state' => '(NULL)', + 'state' => '(-1)', 'output' => "('[' || hch.author_name || '] ' || hch.comment_data)", ), 'hostgroups' => array( diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index 63c08845c..118f7e526 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -26,7 +26,7 @@ class HostdowntimestarthistoryQuery extends IdoQuery 'type' => "('dt_start')", 'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)', 'object_id' => 'hdh.object_id', - 'state' => '(NULL)', + 'state' => '(-1)', 'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)", ), 'hostgroups' => array( diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index e1388cc0f..baa3d4d5a 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -30,7 +30,7 @@ class ServicecommenthistoryQuery extends IdoQuery 'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)", 'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)', 'object_id' => 'sch.object_id', - 'state' => '(NULL)', + 'state' => '(-1)', 'output' => "('[' || sch.author_name || '] ' || sch.comment_data)", ), 'hostgroups' => array( diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index 5cadcc01c..deaa4ae9b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -30,7 +30,7 @@ class ServicedowntimestarthistoryQuery extends IdoQuery 'type' => "('dt_start')", 'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)', 'object_id' => 'sdh.object_id', - 'state' => '(NULL)', + 'state' => '(-1)', 'output' => "('[' || sdh.author_name || '] ' || sdh.comment_data)", ), 'hostgroups' => array( From dd81de39fd48df81f38a5e1d026846d3dcc5ed18 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jun 2015 14:34:30 +0200 Subject: [PATCH 237/237] NotificationQuery: Do not fetch non-history related columns for history queries refs #9009 --- .../Backend/Ido/Query/NotificationQuery.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index 3745179a0..e9085de90 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -96,14 +96,15 @@ class NotificationQuery extends IdoQuery */ protected function joinHosts() { - $columns = array_keys( - $this->columnMap['notifications'] + $this->columnMap['hosts'] - ); + $columns = array_keys($this->columnMap['hosts']); foreach ($this->columnMap['services'] as $column => $_) { $columns[$column] = new Zend_Db_Expr('NULL'); } if ($this->fetchHistoryColumns) { $columns = array_merge($columns, array_keys($this->columnMap['history'])); + $columns[] = 'object_type'; + } else { + $columns = array_merge($columns, array_keys($this->columnMap['notifications'])); } $hosts = $this->createSubQuery('hostnotification', $columns); $this->subQueries[] = $hosts; @@ -115,11 +116,12 @@ class NotificationQuery extends IdoQuery */ protected function joinServices() { - $columns = array_keys( - $this->columnMap['notifications'] + $this->columnMap['hosts'] + $this->columnMap['services'] - ); + $columns = array_keys($this->columnMap['hosts'] + $this->columnMap['services']); if ($this->fetchHistoryColumns) { $columns = array_merge($columns, array_keys($this->columnMap['history'])); + $columns[] = 'object_type'; + } else { + $columns = array_merge($columns, array_keys($this->columnMap['notifications'])); } $services = $this->createSubQuery('servicenotification', $columns); $this->subQueries[] = $services;