mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 23:04:51 +02:00
parent
c35be4023b
commit
528df1b26a
@ -7,16 +7,19 @@ use Zend_Db_Select;
|
|||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for event history
|
* Query for event history records
|
||||||
*/
|
*/
|
||||||
class EventHistoryQuery extends IdoQuery
|
class EventHistoryQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $useSubqueryCount = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subqueries used for the event history query
|
* Subqueries used for the event history query
|
||||||
*
|
*
|
||||||
* @type IdoQuery[]
|
* @type IdoQuery[]
|
||||||
*
|
|
||||||
* @see EventHistoryQuery::joinBaseTables() For the used subqueries.
|
|
||||||
*/
|
*/
|
||||||
protected $subQueries = array();
|
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_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_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)",
|
'cnt_downtime_end' => "SUM(CASE eh.type WHEN 'dt_end' THEN 1 ELSE 0 END)",
|
||||||
'host' => 'eho.name1 COLLATE latin1_general_ci',
|
'host_name' => 'eh.host_name',
|
||||||
'service' => 'eho.name2 COLLATE latin1_general_ci',
|
'service_description' => 'eh.service_description',
|
||||||
'host_name' => 'eho.name1',
|
|
||||||
'service_description' => 'eho.name2',
|
|
||||||
'object_type' => 'eh.object_type',
|
'object_type' => 'eh.object_type',
|
||||||
'timestamp' => 'eh.timestamp',
|
'timestamp' => 'eh.timestamp',
|
||||||
'state' => 'eh.state',
|
'state' => 'eh.state',
|
||||||
'output' => 'eh.output',
|
'output' => 'eh.output',
|
||||||
'type' => 'eh.type'
|
'type' => 'eh.type',
|
||||||
),
|
'host_display_name' => 'eh.host_display_name',
|
||||||
'hostgroups' => array(
|
'service_display_name' => 'eh.service_display_name'
|
||||||
'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'
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $useSubqueryCount = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -64,11 +52,15 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
{
|
{
|
||||||
$columns = array(
|
$columns = array(
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'object_id',
|
|
||||||
'type',
|
|
||||||
'output',
|
'output',
|
||||||
|
'type',
|
||||||
'state',
|
'state',
|
||||||
'object_type'
|
'object_type',
|
||||||
|
'object_id',
|
||||||
|
'host_name',
|
||||||
|
'service_description',
|
||||||
|
'host_display_name',
|
||||||
|
'service_display_name'
|
||||||
);
|
);
|
||||||
$this->subQueries = array(
|
$this->subQueries = array(
|
||||||
$this->createSubQuery('Statehistory', $columns),
|
$this->createSubQuery('Statehistory', $columns),
|
||||||
@ -76,19 +68,11 @@ 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('Notificationhistory', $columns)
|
$this->createSubQuery('Notification', $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(
|
$this->joinedVirtualTables['eventhistory'] = true;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,17 +86,6 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
return parent::order($columnOrAlias, $dir);
|
return parent::order($columnOrAlias, $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function addFilter(Filter $filter)
|
|
||||||
{
|
|
||||||
foreach ($this->subQueries as $sub) {
|
|
||||||
$sub->applyFilter(clone $filter);
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -126,60 +99,13 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join host groups
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
protected function joinHostgroups()
|
public function addFilter(Filter $filter)
|
||||||
{
|
{
|
||||||
$this->select->join(
|
foreach ($this->subQueries as $sub) {
|
||||||
array('hgm' => $this->prefix . 'hostgroup_members'),
|
$sub->applyFilter(clone $filter);
|
||||||
'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()
|
|
||||||
);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,17 @@ class EventHistory extends DataView
|
|||||||
'host_display_name',
|
'host_display_name',
|
||||||
'service_description',
|
'service_description',
|
||||||
'service_display_name',
|
'service_display_name',
|
||||||
'hostgroup_name',
|
|
||||||
'object_type',
|
'object_type',
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'state',
|
'state',
|
||||||
'attempt',
|
|
||||||
'max_attempts',
|
|
||||||
'output',
|
'output',
|
||||||
'type'
|
'type'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getSortRules()
|
public function getSortRules()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -43,8 +43,16 @@ class EventHistory extends DataView
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getFilterColumns()
|
public function getFilterColumns()
|
||||||
{
|
{
|
||||||
return array('host', 'service', 'hostgroup');
|
return array(
|
||||||
|
'host', 'host_alias',
|
||||||
|
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||||
|
'service',
|
||||||
|
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user