Ido\Query\*historyQuery: subqueries join objects
Each of our history subqueries should be able to join main object tables on their own for performance reasons.
This commit is contained in:
parent
7cd696b31b
commit
027ef6ede3
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
class CommentdeletionhistoryQuery extends IdoQuery
|
||||
{
|
||||
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 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$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-01 00:00:00' AND h.entry_type <> 2",
|
||||
array()
|
||||
);
|
||||
$this->joinedVirtualTables = array('commenthistory' => true);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,16 +6,37 @@ class CommenthistoryQuery extends IdoQuery
|
|||
{
|
||||
protected $columnMap = array(
|
||||
'commenthistory' => array(
|
||||
'state_time' => 'comment_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(comment_time)',
|
||||
'raw_timestamp' => 'comment_time',
|
||||
'object_id' => 'object_id',
|
||||
'type' => "(CASE entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)",
|
||||
'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' => "('[' || author_name || '] ' || comment_data)",
|
||||
'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 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$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()
|
||||
);
|
||||
$this->joinedVirtualTables = array('commenthistory' => true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,17 +6,37 @@ class DowntimeendhistoryQuery extends IdoQuery
|
|||
{
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'state_time' => 'actual_end_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(actual_end_time)',
|
||||
'raw_timestamp' => 'actual_end_time',
|
||||
'object_id' => 'object_id',
|
||||
'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' => "('[' || author_name || '] ' || comment_data)",
|
||||
'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 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
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-01 00:00:00');
|
||||
$this->joinedVirtualTables = array('downtimehistory' => true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,17 +6,37 @@ class DowntimestarthistoryQuery extends IdoQuery
|
|||
{
|
||||
protected $columnMap = array(
|
||||
'downtimehistory' => array(
|
||||
'state_time' => 'actual_start_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(actual_start_time)',
|
||||
'raw_timestamp' => 'actual_start_time',
|
||||
'object_id' => 'object_id',
|
||||
'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' => "('[' || author_name || '] ' || comment_data)",
|
||||
'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 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
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-01 00:00:00');
|
||||
$this->joinedVirtualTables = array('downtimehistory' => true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,20 @@ class NotificationhistoryQuery extends IdoQuery
|
|||
'timestamp' => 'UNIX_TIMESTAMP(n.start_time)',
|
||||
'raw_timestamp' => 'n.start_time',
|
||||
'state_time' => 'n.start_time',
|
||||
'object_id' => 'object_id',
|
||||
'object_id' => 'n.object_id',
|
||||
'type' => "('notify')",
|
||||
'state' => 'state',
|
||||
'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 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'o.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'o.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -45,7 +52,11 @@ class NotificationhistoryQuery extends IdoQuery
|
|||
$this->columnMap['history']['output'] = "('[' || $concattedContacts || '] ' || n.output)";
|
||||
|
||||
$this->select->from(
|
||||
array('o' => $this->prefix . 'objects'),
|
||||
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'),
|
||||
|
@ -57,6 +68,7 @@ class NotificationhistoryQuery extends IdoQuery
|
|||
array()
|
||||
)->group('cn.notification_id');
|
||||
|
||||
// TODO: hmmmm...
|
||||
if ($this->ds->getDbType() === 'pgsql') {
|
||||
$this->select->group('n.object_id')
|
||||
->group('n.start_time')
|
||||
|
|
|
@ -6,17 +6,37 @@ class StatehistoryQuery extends IdoQuery
|
|||
{
|
||||
protected $columnMap = array(
|
||||
'statehistory' => array(
|
||||
'raw_timestamp' => 'state_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(state_time)',
|
||||
'state_time' => 'state_time',
|
||||
'object_id' => 'object_id',
|
||||
'type' => "(CASE WHEN state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)",
|
||||
'state' => 'state',
|
||||
'state_type' => 'state_type',
|
||||
'output' => 'output',
|
||||
'attempt' => 'current_check_attempt',
|
||||
'max_attempts' => 'max_check_attempts',
|
||||
'raw_timestamp' => 'sh.state_time',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)',
|
||||
'state_time' => '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',
|
||||
'state_type' => 'sh.state_type',
|
||||
'output' => 'sh.output',
|
||||
'attempt' => 'sh.current_check_attempt',
|
||||
'max_attempts' => 'sh.max_check_attempts',
|
||||
|
||||
'host' => 'sho.name1 COLLATE latin1_general_ci',
|
||||
'service' => 'sho.name2 COLLATE latin1_general_ci',
|
||||
'host_name' => 'sho.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'sho.name2 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'sho.name1 COLLATE latin1_general_ci',
|
||||
'service_description' => 'sho.name2 COLLATE latin1_general_ci'
|
||||
)
|
||||
);
|
||||
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$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()
|
||||
);
|
||||
$this->joinedVirtualTables = array('statehistory' => true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue