mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
IDO: Improve notification view performance
This commit is contained in:
parent
e0d59ded2d
commit
fd6ae75803
@ -277,13 +277,13 @@ class ListController extends Controller
|
|||||||
$this->setAutorefreshInterval(15);
|
$this->setAutorefreshInterval(15);
|
||||||
|
|
||||||
$notifications = $this->backend->select()->from('notification', array(
|
$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_display_name',
|
||||||
|
'host_name',
|
||||||
|
'notification_contact_name',
|
||||||
|
'notification_output',
|
||||||
|
'notification_state',
|
||||||
|
'notification_timestamp',
|
||||||
|
'service_description',
|
||||||
'service_display_name'
|
'service_display_name'
|
||||||
));
|
));
|
||||||
$this->applyRestriction('monitoring/filter/objects', $notifications);
|
$this->applyRestriction('monitoring/filter/objects', $notifications);
|
||||||
|
@ -35,7 +35,7 @@ if (! $this->compact): ?>
|
|||||||
<td class="state-col state-<?= $stateName ?>">
|
<td class="state-col state-<?= $stateName ?>">
|
||||||
<div class="state-label"><?= $stateLabel ?></div>
|
<div class="state-label"><?= $stateLabel ?></div>
|
||||||
<div class="state-meta">
|
<div class="state-meta">
|
||||||
<?= $this->timeAgo($notification->notification_start_time, $this->compact) ?>
|
<?= $this->timeAgo($notification->notification_timestamp, $this->compact) ?>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -223,7 +223,7 @@ $section->add(N_('Event Overview'), array(
|
|||||||
));
|
));
|
||||||
$section->add(N_('Notifications'), array(
|
$section->add(N_('Notifications'), array(
|
||||||
'priority' => 30,
|
'priority' => 30,
|
||||||
'url' => 'monitoring/list/notifications',
|
'url' => 'monitoring/list/notifications?notification_timestamp>=-7%20days',
|
||||||
));
|
));
|
||||||
$section->add(N_('Timeline'), array(
|
$section->add(N_('Timeline'), array(
|
||||||
'priority' => 40,
|
'priority' => 40,
|
||||||
|
@ -56,7 +56,6 @@ class EventhistoryQuery extends IdoQuery
|
|||||||
'type',
|
'type',
|
||||||
'state',
|
'state',
|
||||||
'object_type',
|
'object_type',
|
||||||
'object_id',
|
|
||||||
'host_name',
|
'host_name',
|
||||||
'service_description',
|
'service_description',
|
||||||
'host_display_name',
|
'host_display_name',
|
||||||
@ -68,7 +67,7 @@ class EventhistoryQuery extends IdoQuery
|
|||||||
$this->createSubQuery('Downtimeendhistory', $columns),
|
$this->createSubQuery('Downtimeendhistory', $columns),
|
||||||
$this->createSubQuery('Commenthistory', $columns),
|
$this->createSubQuery('Commenthistory', $columns),
|
||||||
$this->createSubQuery('Commentdeletionhistory', $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);
|
$sub = $this->db->select()->union($this->subQueries, Zend_Db_Select::SQL_UNION_ALL);
|
||||||
$this->select->from(array('eh' => $sub), array());
|
$this->select->from(array('eh' => $sub), array());
|
||||||
|
@ -17,51 +17,34 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $columnMap = array(
|
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(
|
'instances' => array(
|
||||||
'instance_name' => 'i.instance_name'
|
'instance_name' => 'i.instance_name'
|
||||||
),
|
),
|
||||||
'notifications' => array(
|
'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',
|
'host_name' => 'ho.name1',
|
||||||
|
'notification_output' => 'hn.output',
|
||||||
|
'notification_state' => 'hn.state',
|
||||||
|
'notification_timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
||||||
'object_type' => '(\'host\')'
|
'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(
|
'servicegroups' => array(
|
||||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
'servicegroup_name' => 'sgo.name1'
|
||||||
'servicegroup_name' => 'sgo.name1',
|
|
||||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
|
||||||
),
|
),
|
||||||
'services' => array(
|
'services' => array(
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
|
||||||
'service_description' => 'so.name2',
|
'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'
|
'service_host_name' => 'so.name1'
|
||||||
@ -88,26 +71,14 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
switch ($this->ds->getDbType()) {
|
switch ($this->ds->getDbType()) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
$concattedContacts = "GROUP_CONCAT("
|
$concattedContacts = "GROUP_CONCAT("
|
||||||
. "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '"
|
. "DISTINCT co.name1 ORDER BY co.name1 SEPARATOR ', '"
|
||||||
. ") COLLATE latin1_general_ci";
|
. ") COLLATE latin1_general_ci";
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
// TODO: Find a way to order the contact alias list:
|
// TODO: Find a way to order the contact alias list:
|
||||||
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')";
|
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT co.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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || hn.output)";
|
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || hn.output)";
|
||||||
|
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
@ -140,20 +111,8 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
$this->select->joinLeft(
|
$this->select->joinLeft(
|
||||||
array('cno' => $this->prefix . 'objects'),
|
array('co' => $this->prefix . 'objects'),
|
||||||
'cno.object_id = cn.contact_object_id',
|
'co.object_id = cn.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10',
|
||||||
array()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Join acknowledgements
|
|
||||||
*/
|
|
||||||
protected function joinAcknowledgements()
|
|
||||||
{
|
|
||||||
$this->select->joinLeft(
|
|
||||||
array('a' => $this->prefix . 'acknowledgements'),
|
|
||||||
'a.object_id = hn.object_id',
|
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -244,6 +203,8 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
*/
|
*/
|
||||||
public function getGroup()
|
public function getGroup()
|
||||||
{
|
{
|
||||||
|
$group = array();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$this->hasJoinedVirtualTable('history')
|
$this->hasJoinedVirtualTable('history')
|
||||||
|| $this->hasJoinedVirtualTable('services')
|
|| $this->hasJoinedVirtualTable('services')
|
||||||
@ -251,10 +212,10 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
) {
|
) {
|
||||||
$group = array('hn.notification_id', 'ho.object_id');
|
$group = array('hn.notification_id', 'ho.object_id');
|
||||||
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
||||||
$group[] = 'cno.object_id';
|
$group[] = 'co.object_id';
|
||||||
}
|
}
|
||||||
} elseif ($this->hasJoinedVirtualTable('contactnotifications')) {
|
} 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)) {
|
if (! empty($group)) {
|
||||||
@ -262,10 +223,6 @@ class HostnotificationQuery extends IdoQuery
|
|||||||
$group[] = 'h.host_id';
|
$group[] = 'h.host_id';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasJoinedVirtualTable('acknowledgements')) {
|
|
||||||
$group[] = 'a.acknowledgement_id';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->hasJoinedVirtualTable('instances')) {
|
if ($this->hasJoinedVirtualTable('instances')) {
|
||||||
$group[] = 'i.instance_id';
|
$group[] = 'i.instance_id';
|
||||||
}
|
}
|
||||||
|
@ -12,29 +12,22 @@ use Icinga\Data\Filter\Filter;
|
|||||||
*/
|
*/
|
||||||
class NotificationQuery extends IdoQuery
|
class NotificationQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $allowCustomVars = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'notifications' => array(
|
'notifications' => array(
|
||||||
'notification_state' => 'n.notification_state',
|
'instance_name' => 'n.instance_name',
|
||||||
'notification_start_time' => 'n.notification_start_time',
|
|
||||||
'notification_contact_name' => 'n.notification_contact_name',
|
'notification_contact_name' => 'n.notification_contact_name',
|
||||||
'notification_output' => 'n.notification_output',
|
|
||||||
'notification_object_id' => 'n.notification_object_id',
|
'notification_object_id' => 'n.notification_object_id',
|
||||||
'contact_object_id' => 'n.contact_object_id',
|
'notification_output' => 'n.notification_output',
|
||||||
'acknowledgement_entry_time' => 'n.acknowledgement_entry_time',
|
'notification_state' => 'n.notification_state',
|
||||||
'acknowledgement_author_name' => 'n.acknowledgement_author_name',
|
'notification_timestamp' => 'n.notification_timestamp'
|
||||||
'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'
|
|
||||||
),
|
),
|
||||||
'hosts' => array(
|
'hosts' => array(
|
||||||
'host_display_name' => 'n.host_display_name',
|
'host_display_name' => 'n.host_display_name',
|
||||||
@ -61,13 +54,6 @@ class NotificationQuery extends IdoQuery
|
|||||||
*/
|
*/
|
||||||
protected $subQueries = array();
|
protected $subQueries = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether to additionally select all history columns
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $fetchHistoryColumns = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -81,33 +67,20 @@ class NotificationQuery extends IdoQuery
|
|||||||
$this->joinedVirtualTables['notifications'] = true;
|
$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
|
* Join hosts
|
||||||
*/
|
*/
|
||||||
protected function joinHosts()
|
protected function joinHosts()
|
||||||
{
|
{
|
||||||
$columns = array_keys($this->columnMap['hosts']);
|
$columns = $this->desiredColumns;
|
||||||
|
$columns = array_combine($columns, $columns);
|
||||||
foreach ($this->columnMap['services'] as $column => $_) {
|
foreach ($this->columnMap['services'] as $column => $_) {
|
||||||
$columns[$column] = new Zend_Db_Expr('NULL');
|
if (isset($columns[$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);
|
$hosts = $this->createSubQuery('hostnotification', $columns);
|
||||||
|
$hosts->setIsSubQuery(true);
|
||||||
$this->subQueries[] = $hosts;
|
$this->subQueries[] = $hosts;
|
||||||
$this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
$this->notificationQuery->union(array($hosts), Zend_Db_Select::SQL_UNION_ALL);
|
||||||
}
|
}
|
||||||
@ -117,14 +90,8 @@ class NotificationQuery extends IdoQuery
|
|||||||
*/
|
*/
|
||||||
protected function joinServices()
|
protected function joinServices()
|
||||||
{
|
{
|
||||||
$columns = array_keys($this->columnMap['hosts'] + $this->columnMap['services']);
|
$services = $this->createSubQuery('servicenotification', $this->desiredColumns);
|
||||||
if ($this->fetchHistoryColumns) {
|
$services->setIsSubQuery(true);
|
||||||
$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;
|
$this->subQueries[] = $services;
|
||||||
$this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
$this->notificationQuery->union(array($services), Zend_Db_Select::SQL_UNION_ALL);
|
||||||
}
|
}
|
||||||
@ -132,15 +99,12 @@ class NotificationQuery extends IdoQuery
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function allowsCustomVars()
|
public function addFilter(Filter $filter)
|
||||||
{
|
{
|
||||||
foreach ($this->subQueries as $query) {
|
foreach ($this->subQueries as $sub) {
|
||||||
if (! $query->allowsCustomVars()) {
|
$sub->applyFilter(clone $filter);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,25 +129,4 @@ class NotificationQuery extends IdoQuery
|
|||||||
}
|
}
|
||||||
return $this;
|
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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,94 +3,134 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
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
|
class NotificationhistoryQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $allowCustomVars = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'history' => array(
|
'history' => array(
|
||||||
'state_time' => 'n.start_time',
|
'object_type' => 'n.object_type',
|
||||||
'timestamp' => 'UNIX_TIMESTAMP(n.start_time)',
|
'output' => 'n.output',
|
||||||
'raw_timestamp' => 'n.start_time',
|
'state' => 'n.state',
|
||||||
'object_id' => 'n.object_id',
|
'timestamp' => 'n.timestamp',
|
||||||
'type' => "('notify')",
|
'type' => "('notify')"
|
||||||
'state' => 'n.state',
|
),
|
||||||
'state_type' => '(NULL)',
|
'hosts' => array(
|
||||||
'output' => null,
|
'host_display_name' => 'n.host_display_name',
|
||||||
'attempt' => '(NULL)',
|
'host_name' => 'n.host_name'
|
||||||
'max_attempts' => '(NULL)',
|
),
|
||||||
|
'services' => array(
|
||||||
'host' => 'o.name1 COLLATE latin1_general_ci',
|
'service_description' => 'n.service_description',
|
||||||
'service' => 'o.name2 COLLATE latin1_general_ci',
|
'service_display_name' => 'n.service_display_name',
|
||||||
'host_name' => 'o.name1',
|
'service_host_name' => 'n.service_host_name'
|
||||||
'service_description' => 'o.name2',
|
|
||||||
'object_type' => "CASE WHEN o.objecttype_id = 1 THEN 'host' ELSE 'service' END"
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
/**
|
||||||
{
|
* The union
|
||||||
if ($col === 'UNIX_TIMESTAMP(n.start_time)') {
|
*
|
||||||
return 'n.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
* @var Zend_Db_Select
|
||||||
} else {
|
*/
|
||||||
return parent::whereToSql($col, $sign, $expression);
|
protected $notificationQuery;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subqueries used for the notification query
|
||||||
|
*
|
||||||
|
* @var IdoQuery[]
|
||||||
|
*/
|
||||||
|
protected $subQueries = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
switch ($this->ds->getDbType()) {
|
$this->notificationQuery = $this->db->select();
|
||||||
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->select->from(
|
$this->select->from(
|
||||||
array('o' => $this->prefix . 'objects'),
|
array('n' => $this->notificationQuery),
|
||||||
array()
|
array()
|
||||||
)->join(
|
);
|
||||||
array('n' => $this->prefix . 'notifications'),
|
$this->joinedVirtualTables['history'] = true;
|
||||||
'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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,52 +17,34 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $columnMap = array(
|
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(
|
'instances' => array(
|
||||||
'instance_name' => 'i.instance_name'
|
'instance_name' => 'i.instance_name'
|
||||||
),
|
),
|
||||||
'notifications' => array(
|
'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',
|
'host_name' => 'so.name1',
|
||||||
|
'notification_output' => 'sn.output',
|
||||||
|
'notification_state' => 'sn.state',
|
||||||
|
'notification_timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
||||||
'object_type' => '(\'service\')',
|
'object_type' => '(\'service\')',
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
|
||||||
'service_description' => 'so.name2',
|
'service_description' => 'so.name2',
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
|
||||||
'service_host_name' => 'so.name1'
|
'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(
|
'servicegroups' => array(
|
||||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
'servicegroup_name' => 'sgo.name1'
|
||||||
'servicegroup_name' => 'sgo.name1',
|
|
||||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
|
||||||
),
|
),
|
||||||
'services' => array(
|
'services' => array(
|
||||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
'service_display_name' => 's.display_name COLLATE latin1_general_ci'
|
||||||
@ -89,26 +71,14 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
switch ($this->ds->getDbType()) {
|
switch ($this->ds->getDbType()) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
$concattedContacts = "GROUP_CONCAT("
|
$concattedContacts = "GROUP_CONCAT("
|
||||||
. "DISTINCT cno.name1 ORDER BY cno.name1 SEPARATOR ', '"
|
. "DISTINCT co.name1 ORDER BY co.name1 SEPARATOR ', '"
|
||||||
. ") COLLATE latin1_general_ci";
|
. ") COLLATE latin1_general_ci";
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
// TODO: Find a way to order the contact alias list:
|
// TODO: Find a way to order the contact alias list:
|
||||||
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT cno.name1), ', ')";
|
$concattedContacts = "ARRAY_TO_STRING(ARRAY_AGG(DISTINCT co.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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || sn.output)";
|
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || sn.output)";
|
||||||
|
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
@ -141,20 +111,8 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
$this->select->joinLeft(
|
$this->select->joinLeft(
|
||||||
array('cno' => $this->prefix . 'objects'),
|
array('co' => $this->prefix . 'objects'),
|
||||||
'cno.object_id = cn.contact_object_id',
|
'co.object_id = cn.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10',
|
||||||
array()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Join acknowledgements
|
|
||||||
*/
|
|
||||||
protected function joinAcknowledgements()
|
|
||||||
{
|
|
||||||
$this->select->joinLeft(
|
|
||||||
array('a' => $this->prefix . 'acknowledgements'),
|
|
||||||
'a.object_id = sn.object_id',
|
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -243,6 +201,7 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
public function getGroup()
|
public function getGroup()
|
||||||
{
|
{
|
||||||
$group = array();
|
$group = array();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$this->hasJoinedVirtualTable('history')
|
$this->hasJoinedVirtualTable('history')
|
||||||
|| $this->hasJoinedVirtualTable('hostgroups')
|
|| $this->hasJoinedVirtualTable('hostgroups')
|
||||||
@ -250,10 +209,10 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
) {
|
) {
|
||||||
$group = array('sn.notification_id', 'so.object_id');
|
$group = array('sn.notification_id', 'so.object_id');
|
||||||
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
if ($this->hasJoinedVirtualTable('contactnotifications') && !$this->hasJoinedVirtualTable('history')) {
|
||||||
$group[] = 'cno.object_id';
|
$group[] = 'co.object_id';
|
||||||
}
|
}
|
||||||
} elseif ($this->hasJoinedVirtualTable('contactnotifications')) {
|
} 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)) {
|
if (! empty($group)) {
|
||||||
@ -265,10 +224,6 @@ class ServicenotificationQuery extends IdoQuery
|
|||||||
$group[] = 's.service_id';
|
$group[] = 's.service_id';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasJoinedVirtualTable('acknowledgements')) {
|
|
||||||
$group[] = 'a.acknowledgement_id';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->hasJoinedVirtualTable('instances')) {
|
if ($this->hasJoinedVirtualTable('instances')) {
|
||||||
$group[] = 'i.instance_id';
|
$group[] = 'i.instance_id';
|
||||||
}
|
}
|
||||||
|
@ -11,18 +11,12 @@ class Notification extends DataView
|
|||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
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_display_name',
|
||||||
'host_name',
|
'host_name',
|
||||||
|
'notification_contact_name',
|
||||||
|
'notification_output',
|
||||||
|
'notification_state',
|
||||||
|
'notification_timestamp',
|
||||||
'object_type',
|
'object_type',
|
||||||
'service_description',
|
'service_description',
|
||||||
'service_display_name',
|
'service_display_name',
|
||||||
@ -36,23 +30,8 @@ class Notification extends DataView
|
|||||||
public function getSortRules()
|
public function getSortRules()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'notification_start_time' => array(
|
'notification_timestamp' => array(
|
||||||
'order' => self::SORT_DESC,
|
'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
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -63,11 +42,9 @@ class Notification extends DataView
|
|||||||
public function getStaticFilterColumns()
|
public function getStaticFilterColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'contact',
|
'hostgroup_name',
|
||||||
'host', 'host_alias',
|
'instance_name',
|
||||||
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
'servicegroup_name'
|
||||||
'service',
|
|
||||||
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user