Eventgrid: Add support for object restrictions

refs #9009
This commit is contained in:
Johannes Meyer 2015-06-12 16:27:13 +02:00
parent eb93886cc7
commit 470c4a54a3
2 changed files with 56 additions and 81 deletions

View File

@ -3,89 +3,55 @@
namespace Icinga\Module\Monitoring\Backend\Ido\Query; namespace Icinga\Module\Monitoring\Backend\Ido\Query;
class EventgridQuery extends IdoQuery class EventgridQuery extends StatehistoryQuery
{ {
protected $columnMap = array( /**
'statehistory' => array( * The columns additionally provided by this query
'day' => 'DATE(sh.state_time)', *
'cnt_events' => 'COUNT(*)', * @var array
'objecttype_id' => 'sho.objecttype_id', */
'cnt_up' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 0 THEN 1 ELSE 0 END)', protected $additionalColumns = array(
'cnt_down_hard' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 AND state_type = 1 THEN 1 ELSE 0 END)', 'day' => 'DATE(FROM_UNIXTIME(sth.timestamp))',
'cnt_down' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 1 THEN 1 ELSE 0 END)', 'cnt_up' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 0 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_down_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_unreachable' => 'SUM(CASE WHEN sho.objecttype_id = 1 AND sh.state = 2 THEN 1 ELSE 0 END)', 'cnt_down' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 1 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_unreachable_hard' => "SUM(CASE WHEN sth.object_type = 'host' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_unknown' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 3 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 sho.objecttype_id = 2 AND sh.state = 3 AND state_type = 1 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 sho.objecttype_id = 2 AND sh.state = 2 THEN 1 ELSE 0 END)', 'cnt_unknown' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 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_unknown_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 3 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_warning' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 1 THEN 1 ELSE 0 END)', 'cnt_critical' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 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_critical_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 2 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'cnt_ok' => 'SUM(CASE WHEN sho.objecttype_id = 2 AND sh.state = 0 THEN 1 ELSE 0 END)', 'cnt_warning' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 THEN 1 ELSE 0 END)",
'host' => 'sho.name1 COLLATE latin1_general_ci', 'cnt_warning_hard' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 1 AND sth.type = 'hard_state' THEN 1 ELSE 0 END)",
'service' => 'sho.name2 COLLATE latin1_general_ci', 'cnt_ok' => "SUM(CASE WHEN sth.object_type = 'service' AND sth.state = 0 THEN 1 ELSE 0 END)"
'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'
)
); );
/**
* {@inheritdoc}
*/
protected function joinBaseTables() protected function joinBaseTables()
{ {
$this->select->from( parent::joinBaseTables();
array('sh' => $this->prefix . 'statehistory'), $this->requireVirtualTable('history');
array() $this->columnMap['statehistory'] += $this->additionalColumns;
)->join( $this->select->group(array('DATE(FROM_UNIXTIME(sth.timestamp))'));
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);
} }
protected function joinHostgroups() /**
* {@inheritdoc}
*/
public function order($columnOrAlias, $dir = null)
{ {
$this->select->join( if (array_key_exists($columnOrAlias, $this->additionalColumns)) {
array('hgm' => $this->prefix . 'hostgroup_members'), $subQueries = $this->subQueries;
'hgm.host_object_id = sho.object_id', $this->subQueries = array();
array() parent::order($columnOrAlias, $dir);
)->join( $this->subQueries = $subQueries;
array('hgs' => $this->prefix . 'hostgroups'), } else {
'hgm.hostgroup_id = hgs.hostgroup_id', parent::order($columnOrAlias, $dir);
array() }
)->join(
array('hgo' => $this->prefix . 'objects'),
'hgo.object_id = hgs.hostgroup_object_id',
array()
);
}
protected function joinServicegroups() return $this;
{
$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()
);
} }
} }

View File

@ -14,8 +14,6 @@ class Eventgrid extends DataView
{ {
return array( return array(
'day', 'day',
'cnt_events',
'objecttype_id',
'cnt_up', 'cnt_up',
'cnt_down_hard', 'cnt_down_hard',
'cnt_down', 'cnt_down',
@ -29,13 +27,16 @@ class Eventgrid extends DataView
'cnt_warning_hard', 'cnt_warning_hard',
'cnt_ok', 'cnt_ok',
'host_name', 'host_name',
'host_display_name',
'service_description', 'service_description',
'timestamp', 'service_display_name',
'servicegroup_name', 'timestamp'
'hostgroup_name'
); );
} }
/**
* {@inheritdoc}
*/
public function getSortRules() public function getSortRules()
{ {
return array( return array(
@ -45,8 +46,16 @@ class Eventgrid extends DataView
); );
} }
/**
* {@inheritdoc}
*/
public function getFilterColumns() 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'
);
} }
} }