From fd6ae75803bc9b0499415c0889744cb9ff9a2342 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 14 Sep 2016 16:18:08 +0200 Subject: [PATCH] IDO: Improve notification view performance --- .../controllers/ListController.php | 12 +- .../views/scripts/list/notifications.phtml | 2 +- modules/monitoring/configuration.php | 2 +- .../Backend/Ido/Query/EventhistoryQuery.php | 3 +- .../Ido/Query/HostnotificationQuery.php | 95 +++------ .../Backend/Ido/Query/NotificationQuery.php | 99 ++------- .../Ido/Query/NotificationhistoryQuery.php | 192 +++++++++++------- .../Ido/Query/ServicenotificationQuery.php | 95 +++------ .../Monitoring/DataView/Notification.php | 41 +--- 9 files changed, 206 insertions(+), 335 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 5499cfdf9..787a184f5 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -277,13 +277,13 @@ class ListController extends Controller $this->setAutorefreshInterval(15); $notifications = $this->backend->select()->from('notification', array( - 'host_name', - 'service_description', - 'notification_output', - 'notification_contact_name', - 'notification_start_time', - 'notification_state', 'host_display_name', + 'host_name', + 'notification_contact_name', + 'notification_output', + 'notification_state', + 'notification_timestamp', + 'service_description', 'service_display_name' )); $this->applyRestriction('monitoring/filter/objects', $notifications); diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index 8316665d1..dc34a8c88 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -35,7 +35,7 @@ if (! $this->compact): ?>
- timeAgo($notification->notification_start_time, $this->compact) ?> + timeAgo($notification->notification_timestamp, $this->compact) ?>
diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index 01a6380ad..c2b385c35 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -223,7 +223,7 @@ $section->add(N_('Event Overview'), array( )); $section->add(N_('Notifications'), array( 'priority' => 30, - 'url' => 'monitoring/list/notifications', + 'url' => 'monitoring/list/notifications?notification_timestamp>=-7%20days', )); $section->add(N_('Timeline'), array( 'priority' => 40, diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php index 542a45b9d..c8ee0b8a3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventhistoryQuery.php @@ -56,7 +56,6 @@ class EventhistoryQuery extends IdoQuery 'type', 'state', 'object_type', - 'object_id', 'host_name', 'service_description', 'host_display_name', @@ -68,7 +67,7 @@ class EventhistoryQuery extends IdoQuery $this->createSubQuery('Downtimeendhistory', $columns), $this->createSubQuery('Commenthistory', $columns), $this->createSubQuery('Commentdeletionhistory', $columns), - $this->createSubQuery('Notification', $columns) + $this->createSubQuery('Notificationhistory', $columns) ); $sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL); $this->select->from(array('eh' => $sub), array()); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 0ee815df8..de4d37807 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -17,51 +17,34 @@ class HostnotificationQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( + 'contactnotifications' => array( + 'notification_contact_name' => 'co.name1' + ), + 'hostgroups' => array( + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), + 'history' => array( + 'output' => null, + 'state' => 'hn.state', + 'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)', + ), 'instances' => array( 'instance_name' => 'i.instance_name' ), 'notifications' => 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', + 'notification_output' => 'hn.output', + 'notification_state' => 'hn.state', + 'notification_timestamp' => 'UNIX_TIMESTAMP(hn.start_time)', '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', - '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' + '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', 'service_host_name' => 'so.name1' @@ -88,26 +71,14 @@ class HostnotificationQuery extends IdoQuery switch ($this->ds->getDbType()) { case 'mysql': $concattedContacts = "GROUP_CONCAT(" - . "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . "DISTINCT co.name1 ORDER BY co.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(DISTINCT 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) + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT co.name1), ', ')"; break; } - $this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || hn.output)"; $this->select->from( @@ -140,20 +111,8 @@ class HostnotificationQuery extends IdoQuery array() ); $this->select->joinLeft( - 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('co' => $this->prefix . 'objects'), + 'co.object_id = cn.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', array() ); } @@ -244,6 +203,8 @@ class HostnotificationQuery extends IdoQuery */ public function getGroup() { + $group = array(); + if ( $this->hasJoinedVirtualTable('history') || $this->hasJoinedVirtualTable('services') @@ -251,10 +212,10 @@ class HostnotificationQuery extends IdoQuery ) { $group = array('hn.notification_id', 'ho.object_id'); if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $group[] = 'cno.object_id'; + $group[] = 'co.object_id'; } } elseif ($this->hasJoinedVirtualTable('contactnotifications')) { - $group = array('hn.notification_id', 'cno.object_id', 'ho.object_id'); + $group = array('hn.notification_id', 'co.object_id', 'ho.object_id'); } if (! empty($group)) { @@ -262,10 +223,6 @@ class HostnotificationQuery extends IdoQuery $group[] = 'h.host_id'; } - if ($this->hasJoinedVirtualTable('acknowledgements')) { - $group[] = 'a.acknowledgement_id'; - } - if ($this->hasJoinedVirtualTable('instances')) { $group[] = 'i.instance_id'; } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php index 9950fdbcd..c9515140b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php @@ -12,29 +12,22 @@ use Icinga\Data\Filter\Filter; */ class NotificationQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + /** * {@inheritdoc} */ protected $columnMap = array( 'notifications' => array( - 'notification_state' => 'n.notification_state', - 'notification_start_time' => 'n.notification_start_time', + 'instance_name' => 'n.instance_name', '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', - 'instance_name' => 'n.instance_name' - ), - 'history' => array( - 'type' => 'n.type', - 'timestamp' => 'n.timestamp', - 'object_id' => 'n.object_id', - 'state' => 'n.state', - 'output' => 'n.output' + 'notification_output' => 'n.notification_output', + 'notification_state' => 'n.notification_state', + 'notification_timestamp' => 'n.notification_timestamp' ), 'hosts' => array( 'host_display_name' => 'n.host_display_name', @@ -61,13 +54,6 @@ class NotificationQuery extends IdoQuery */ protected $subQueries = array(); - /** - * Whether to additionally select all history columns - * - * @var bool - */ - protected $fetchHistoryColumns = false; - /** * {@inheritdoc} */ @@ -81,33 +67,20 @@ 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 */ protected function joinHosts() { - $columns = array_keys($this->columnMap['hosts']); + $columns = $this->desiredColumns; + $columns = array_combine($columns, $columns); 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'])); + if (isset($columns[$column])) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } } $hosts = $this->createSubQuery('hostnotification', $columns); + $hosts->setIsSubQuery(true); $this->subQueries[] = $hosts; $this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL); } @@ -117,14 +90,8 @@ class NotificationQuery extends IdoQuery */ protected function joinServices() { - $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); + $services = $this->createSubQuery('servicenotification', $this->desiredColumns); + $services->setIsSubQuery(true); $this->subQueries[] = $services; $this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); } @@ -132,15 +99,12 @@ class NotificationQuery extends IdoQuery /** * {@inheritdoc} */ - public function allowsCustomVars() + public function addFilter(Filter $filter) { - foreach ($this->subQueries as $query) { - if (! $query->allowsCustomVars()) { - return false; - } + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); } - - return true; + return $this; } /** @@ -165,25 +129,4 @@ class NotificationQuery extends IdoQuery } return $this; } - - /** - * {@inheritdoc} - */ - public function addFilter(Filter $filter) - { - foreach ($this->subQueries as $sub) { - $sub->applyFilter(clone $filter); - } - return $this; - } - - /** - * {@inheritdoc} - */ - public function columns(array $columns) - { - parent::columns($columns); - $this->requireVirtualTable('hosts'); - $this->requireVirtualTable('services'); - } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php index dad75d5e0..fd83e571f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php @@ -3,94 +3,134 @@ 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 notification history + */ class NotificationhistoryQuery extends IdoQuery { + /** + * {@inheritdoc} + */ + protected $allowCustomVars = true; + + /** + * {@inheritdoc} + */ protected $columnMap = array( 'history' => array( - 'state_time' => 'n.start_time', - 'timestamp' => 'UNIX_TIMESTAMP(n.start_time)', - 'raw_timestamp' => 'n.start_time', - 'object_id' => 'n.object_id', - 'type' => "('notify')", - 'state' => 'n.state', - 'state_type' => '(NULL)', - 'output' => null, - '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' => 'n.object_type', + 'output' => 'n.output', + 'state' => 'n.state', + 'timestamp' => 'n.timestamp', + 'type' => "('notify')" + ), + 'hosts' => array( + 'host_display_name' => 'n.host_display_name', + 'host_name' => 'n.host_name' + ), + 'services' => array( + 'service_description' => 'n.service_description', + 'service_display_name' => 'n.service_display_name', + 'service_host_name' => 'n.service_host_name' ) ); - 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); - } - } + /** + * The union + * + * @var Zend_Db_Select + */ + protected $notificationQuery; + /** + * Subqueries used for the notification query + * + * @var IdoQuery[] + */ + protected $subQueries = array(); + + /** + * {@inheritdoc} + */ protected function joinBaseTables() { - switch ($this->ds->getDbType()) { - case 'mysql': - $concattedContacts = "GROUP_CONCAT(co.name1 ORDER BY co.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(co.name1), ', ')"; - break; - case 'oracle': - // TODO: This is only valid for Oracle >= 11g Release 2 - $concattedContacts = "LISTAGG(co.name1, ', ') WITHIN GROUP (ORDER BY co.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 || '] ' || n.output)"; - + $this->notificationQuery = $this->db->select(); $this->select->from( - array('o' => $this->prefix . 'objects'), + array('n' => $this->notificationQuery), array() - )->join( - array('n' => $this->prefix . 'notifications'), - 'o.' . $this->object_id . ' = n.' . $this->object_id . ' AND o.is_active = 1', - array() - )->join( - array('cn' => $this->prefix . 'contactnotifications'), - 'cn.notification_id = n.notification_id', - array() - )->joinLeft( - array('co' => $this->prefix . 'objects'), - 'cn.contact_object_id = co.object_id', - array() - )->joinLeft( - array('c' => $this->prefix . 'contacts'), - 'co.object_id = c.contact_object_id', - array() - )->group('cn.notification_id'); - - // TODO: hmmmm... - if ($this->ds->getDbType() === 'pgsql') { - $this->select->group('n.object_id') - ->group('n.start_time') - ->group('n.output') - ->group('n.state') - ->group('o.objecttype_id'); - } - - $this->joinedVirtualTables = array('history' => true); + ); + $this->joinedVirtualTables['history'] = true; } + /** + * Join hosts + */ + protected function joinHosts() + { + $columns = $this->desiredColumns; + $columns = array_combine($columns, $columns); + foreach ($this->columnMap['services'] as $column => $_) { + if (isset($columns[$column])) { + $columns[$column] = new Zend_Db_Expr('NULL'); + } + } + if (isset($columns['type'])) { + unset($columns['type']); + } + $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_flip($this->desiredColumns); + if (isset($columns['type'])) { + unset($columns['type']); + } + $services = $this->createSubQuery('servicenotification', array_flip($columns)); + $this->subQueries[] = $services; + $this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL); + } + + /** + * {@inheritdoc} + */ + public function addFilter(Filter $filter) + { + foreach ($this->subQueries as $sub) { + $sub->applyFilter(clone $filter); + } + return $this; + } + + /** + * {@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; + } } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 0e7954746..4d7baa7ab 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -17,52 +17,34 @@ class ServicenotificationQuery extends IdoQuery * {@inheritdoc} */ protected $columnMap = array( + 'contactnotifications' => array( + 'notification_contact_name' => 'co.name1' + ), + 'history' => array( + 'output' => null, + 'state' => 'sn.state', + 'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)', + ), + 'hostgroups' => array( + 'hostgroup_name' => 'hgo.name1' + ), + 'hosts' => array( + 'host_display_name' => 'h.display_name COLLATE latin1_general_ci' + ), 'instances' => array( 'instance_name' => 'i.instance_name' ), 'notifications' => 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', + 'notification_output' => 'sn.output', + 'notification_state' => 'sn.state', + 'notification_timestamp' => 'UNIX_TIMESTAMP(sn.start_time)', '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' => "('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', - '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' + 'servicegroup_name' => 'sgo.name1' ), 'services' => array( 'service_display_name' => 's.display_name COLLATE latin1_general_ci' @@ -89,26 +71,14 @@ class ServicenotificationQuery extends IdoQuery switch ($this->ds->getDbType()) { case 'mysql': $concattedContacts = "GROUP_CONCAT(" - . "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '" + . "DISTINCT co.name1 ORDER BY co.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(DISTINCT 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) + $concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT co.name1), ', ')"; break; } - $this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || sn.output)"; $this->select->from( @@ -141,20 +111,8 @@ class ServicenotificationQuery extends IdoQuery array() ); $this->select->joinLeft( - 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('co' => $this->prefix . 'objects'), + 'co.object_id = cn.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', array() ); } @@ -243,6 +201,7 @@ class ServicenotificationQuery extends IdoQuery public function getGroup() { $group = array(); + if ( $this->hasJoinedVirtualTable('history') || $this->hasJoinedVirtualTable('hostgroups') @@ -250,10 +209,10 @@ class ServicenotificationQuery extends IdoQuery ) { $group = array('sn.notification_id', 'so.object_id'); if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) { - $group[] = 'cno.object_id'; + $group[] = 'co.object_id'; } } elseif ($this->hasJoinedVirtualTable('contactnotifications')) { - $group = array('sn.notification_id', 'cno.object_id', 'so.object_id'); + $group = array('sn.notification_id', 'co.object_id', 'so.object_id'); } if (! empty($group)) { @@ -265,10 +224,6 @@ class ServicenotificationQuery extends IdoQuery $group[] = 's.service_id'; } - if ($this->hasJoinedVirtualTable('acknowledgements')) { - $group[] = 'a.acknowledgement_id'; - } - if ($this->hasJoinedVirtualTable('instances')) { $group[] = 'i.instance_id'; } diff --git a/modules/monitoring/library/Monitoring/DataView/Notification.php b/modules/monitoring/library/Monitoring/DataView/Notification.php index febf9e343..b9a85cd2c 100644 --- a/modules/monitoring/library/Monitoring/DataView/Notification.php +++ b/modules/monitoring/library/Monitoring/DataView/Notification.php @@ -11,18 +11,12 @@ class Notification extends DataView public function getColumns() { return array( - 'instance_name', - 'notification_state', - 'notification_start_time', - 'notification_contact_name', - 'notification_output', - 'notification_object_id', - 'contact_object_id', - 'acknowledgement_entry_time', - 'acknowledgement_author_name', - 'acknowledgement_comment_data', 'host_display_name', 'host_name', + 'notification_contact_name', + 'notification_output', + 'notification_state', + 'notification_timestamp', 'object_type', 'service_description', 'service_display_name', @@ -36,23 +30,8 @@ class Notification extends DataView 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 + 'notification_timestamp' => array( + 'order' => self::SORT_DESC ) ); } @@ -63,11 +42,9 @@ class Notification extends DataView public function getStaticFilterColumns() { return array( - 'contact', - 'host', 'host_alias', - 'hostgroup', 'hostgroup_alias', 'hostgroup_name', - 'service', - 'servicegroup', 'servicegroup_alias', 'servicegroup_name' + 'hostgroup_name', + 'instance_name', + 'servicegroup_name' ); }