parent
d5ade9ae74
commit
07ebf11a07
|
@ -3,8 +3,19 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query for contacts
|
||||||
|
*/
|
||||||
class ContactQuery extends IdoQuery
|
class ContactQuery extends IdoQuery
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected $allowCustomVars = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected $columnMap = array(
|
protected $columnMap = array(
|
||||||
'contacts' => array(
|
'contacts' => array(
|
||||||
'contact_id' => 'c.contact_id',
|
'contact_id' => 'c.contact_id',
|
||||||
|
@ -33,18 +44,33 @@ class ContactQuery extends IdoQuery
|
||||||
'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci',
|
'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci',
|
||||||
'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
|
'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
|
||||||
),
|
),
|
||||||
|
'hostgroups' => array(
|
||||||
|
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||||
|
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
|
||||||
|
'hostgroup_name' => 'hgo.name1'
|
||||||
|
),
|
||||||
'hosts' => array(
|
'hosts' => array(
|
||||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||||
'host_name' => 'ho.name1'
|
'host_name' => 'ho.name1',
|
||||||
|
'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'
|
||||||
),
|
),
|
||||||
'services' => array(
|
'services' => array(
|
||||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||||
'service_description' => 'so.name2',
|
'service_description' => 'so.name2',
|
||||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||||
'service_host_name' => 'so.name1'
|
'service_host_name' => 'so.name1'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -52,46 +78,15 @@ class ContactQuery extends IdoQuery
|
||||||
array()
|
array()
|
||||||
)->join(
|
)->join(
|
||||||
array('co' => $this->prefix . 'objects'),
|
array('co' => $this->prefix . 'objects'),
|
||||||
'c.contact_object_id = co.' . $this->object_id . ' AND co.is_active = 1',
|
'co.object_id = c.contact_object_id AND co.is_active = 1',
|
||||||
array()
|
|
||||||
);
|
|
||||||
$this->joinedVirtualTables = array('contacts' => true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function joinHosts()
|
|
||||||
{
|
|
||||||
$this->select->join(
|
|
||||||
array('hc' => $this->prefix . 'host_contacts'),
|
|
||||||
'hc.contact_object_id = c.contact_object_id',
|
|
||||||
array()
|
|
||||||
)->join(
|
|
||||||
array('h' => $this->prefix . 'hosts'),
|
|
||||||
'hc.host_id = h.host_id',
|
|
||||||
array()
|
|
||||||
)->join(
|
|
||||||
array('ho' => $this->prefix . 'objects'),
|
|
||||||
'h.host_object_id = ho.' . $this->object_id . ' AND ho.is_active = 1',
|
|
||||||
array()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function joinServices()
|
|
||||||
{
|
|
||||||
$this->select->join(
|
|
||||||
array('sc' => $this->prefix . 'service_contacts'),
|
|
||||||
'sc.contact_object_id = c.contact_object_id',
|
|
||||||
array()
|
|
||||||
)->join(
|
|
||||||
array('s' => $this->prefix . 'services'),
|
|
||||||
'sc.service_id = s.service_id',
|
|
||||||
array()
|
|
||||||
)->join(
|
|
||||||
array('so' => $this->prefix . 'objects'),
|
|
||||||
's.service_object_id = so.' . $this->object_id . ' AND so.is_active = 1',
|
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
|
$this->joinedVirtualTables['contacts'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join timeperiods
|
||||||
|
*/
|
||||||
protected function joinTimeperiods()
|
protected function joinTimeperiods()
|
||||||
{
|
{
|
||||||
$this->select->joinLeft(
|
$this->select->joinLeft(
|
||||||
|
@ -105,4 +100,90 @@ class ContactQuery extends IdoQuery
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join host groups
|
||||||
|
*/
|
||||||
|
protected function joinHostgroups()
|
||||||
|
{
|
||||||
|
$this->requireVirtualTable('hosts');
|
||||||
|
$this->select->joinLeft(
|
||||||
|
array('hgm' => $this->prefix . 'hostgroup_members'),
|
||||||
|
'hgm.host_object_id = ho.object_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('hg' => $this->prefix . 'hostgroups'),
|
||||||
|
'hg.hostgroup_id = hgm.hostgroup_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('hgo' => $this->prefix . 'objects'),
|
||||||
|
'hgo.object_id = hg.hostgroup_object_id AND hgo.is_active = 1 AND hgo.objecttype_id = 3',
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join hosts
|
||||||
|
*/
|
||||||
|
protected function joinHosts()
|
||||||
|
{
|
||||||
|
$this->select->joinLeft(
|
||||||
|
array('hc' => $this->prefix . 'host_contacts'),
|
||||||
|
'hc.contact_object_id = c.contact_object_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('h' => $this->prefix . 'hosts'),
|
||||||
|
'h.host_id = hc.host_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('ho' => $this->prefix . 'objects'),
|
||||||
|
'ho.object_id = h.host_object_id AND ho.is_active = 1',
|
||||||
|
array()
|
||||||
|
)->group(
|
||||||
|
array('c.contact_id')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join service groups
|
||||||
|
*/
|
||||||
|
protected function joinServicegroups()
|
||||||
|
{
|
||||||
|
$this->requireVirtualTable('services');
|
||||||
|
$this->select->joinLeft(
|
||||||
|
array('sgm' => $this->prefix . 'servicegroup_members'),
|
||||||
|
'sgm.service_object_id = s.service_object_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('sg' => $this->prefix . 'servicegroups'),
|
||||||
|
'sg.servicegroup_id = sgm.servicegroup_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('sgo' => $this->prefix . 'objects'),
|
||||||
|
'sgo.object_id = sg.servicegroup_object_id AND sgo.is_active = 1 AND sgo.objecttype_id = 4',
|
||||||
|
array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join services
|
||||||
|
*/
|
||||||
|
protected function joinServices()
|
||||||
|
{
|
||||||
|
$this->select->joinLeft(
|
||||||
|
array('sc' => $this->prefix . 'service_contacts'),
|
||||||
|
'sc.contact_object_id = c.contact_object_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('s' => $this->prefix . 'services'),
|
||||||
|
's.service_id = sc.service_id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('so' => $this->prefix . 'objects'),
|
||||||
|
'so.object_id = s.service_object_id AND so.is_active = 1 AND so.objecttype_id = 2',
|
||||||
|
array()
|
||||||
|
)->group(
|
||||||
|
array('c.contact_id')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,32 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\DataView;
|
namespace Icinga\Module\Monitoring\DataView;
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes the data needed by the 'Contact' DataView
|
|
||||||
*/
|
|
||||||
class Contact extends DataView
|
class Contact extends DataView
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Retrieve columns provided by this view
|
* {@inheritdoc}
|
||||||
*
|
*/
|
||||||
* @return array
|
public function isValidFilterTarget($column)
|
||||||
|
{
|
||||||
|
if ($column[0] === '_' && preg_match('/^_(?:host|service)_/', $column)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::isValidFilterTarget($column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
'contact_object_id',
|
||||||
'contact_id',
|
'contact_id',
|
||||||
'contact_name',
|
'contact_name',
|
||||||
'contact_alias',
|
'contact_alias',
|
||||||
'contact_email',
|
'contact_email',
|
||||||
'contact_pager',
|
'contact_pager',
|
||||||
'contact_notify_hosts',
|
|
||||||
'contact_notify_services',
|
|
||||||
'contact_has_host_notfications',
|
'contact_has_host_notfications',
|
||||||
'contact_has_service_notfications',
|
'contact_has_service_notfications',
|
||||||
'contact_can_submit_commands',
|
'contact_can_submit_commands',
|
||||||
|
@ -37,33 +43,34 @@ class Contact extends DataView
|
||||||
'contact_notify_host_unreachable',
|
'contact_notify_host_unreachable',
|
||||||
'contact_notify_host_flapping',
|
'contact_notify_host_flapping',
|
||||||
'contact_notify_host_downtime',
|
'contact_notify_host_downtime',
|
||||||
'contact_object_id',
|
|
||||||
'host_object_id',
|
|
||||||
'host_name',
|
|
||||||
'service_object_id',
|
|
||||||
'service_host_name',
|
|
||||||
'service_description',
|
|
||||||
'contact_notify_host_timeperiod',
|
'contact_notify_host_timeperiod',
|
||||||
'contact_notify_service_timeperiod'
|
'contact_notify_service_timeperiod'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getSortRules()
|
public function getSortRules()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'contact_alias' => array(
|
'contact_name' => array(
|
||||||
'order' => self::SORT_DESC
|
'order' => self::SORT_ASC
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getFilterColumns()
|
public function getFilterColumns()
|
||||||
{
|
{
|
||||||
return array('contact', 'alias', 'email', 'host', 'service', 'service_host');
|
return array(
|
||||||
|
'contact',
|
||||||
|
'host', 'host_name', 'host_display_name', 'host_alias',
|
||||||
|
'hostgroup', 'hostgroup_alias', 'hostgroup_name',
|
||||||
|
'service', 'service_description', 'service_display_name',
|
||||||
|
'servicegroup', 'servicegroup_alias', 'servicegroup_name'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue