Allow to filter for contacts

This commit is contained in:
Eric Lippmann 2019-07-08 16:32:53 +02:00
parent 4dcea91775
commit 523a35f4c1
8 changed files with 135 additions and 4 deletions

View File

@ -26,6 +26,9 @@ class HostgroupQuery extends IdoQuery
); );
protected $columnMap = array( protected $columnMap = array(
'contacts' => [
'host_contact' => 'hco.name1'
],
'hostgroups' => array( 'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
@ -125,6 +128,24 @@ class HostgroupQuery extends IdoQuery
$this->joinedVirtualTables['hostgroups'] = true; $this->joinedVirtualTables['hostgroups'] = true;
} }
/**
* Join contacts
*/
protected function joinContacts()
{
$this->requireVirtualTable('hosts');
$this->select->joinLeft(
['hc' => 'icinga_host_contacts'],
'hc.host_id = h.host_id',
[]
)->joinLeft(
['hco' => 'icinga_objects'],
'hco.object_id = hc.contact_object_id AND hco.is_active = 1 AND hco.objecttype_id = 10',
[]
);
}
/** /**
* Join hosts * Join hosts
*/ */

View File

@ -32,6 +32,9 @@ class HoststatusQuery extends IdoQuery
'checktimeperiods' => array( 'checktimeperiods' => array(
'host_check_timeperiod' => 'ctp.alias COLLATE latin1_general_ci' 'host_check_timeperiod' => 'ctp.alias COLLATE latin1_general_ci'
), ),
'contacts' => [
'host_contact' => 'hco.name1'
],
'hostgroups' => array( 'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
@ -201,6 +204,22 @@ class HoststatusQuery extends IdoQuery
); );
} }
/**
* Join contacts
*/
protected function joinContacts()
{
$this->select->joinLeft(
['hc' => 'icinga_host_contacts'],
'hc.host_id = h.host_id',
[]
)->joinLeft(
['hco' => 'icinga_objects'],
'hco.object_id = hc.contact_object_id AND hco.is_active = 1 AND hco.objecttype_id = 10',
[]
);
}
/** /**
* Join host groups * Join host groups
*/ */

View File

@ -22,6 +22,12 @@ class ServicegroupQuery extends IdoQuery
); );
protected $columnMap = array( protected $columnMap = array(
'contacts' => [
'service_contact' => 'sco.name1'
],
'hostcontacts' => [
'host_contact' => 'hco.name1'
],
'hostgroups' => array( 'hostgroups' => array(
'hostgroup_name' => 'hgo.name1' 'hostgroup_name' => 'hgo.name1'
), ),
@ -96,6 +102,46 @@ class ServicegroupQuery extends IdoQuery
$this->joinedVirtualTables = array('servicegroups' => true); $this->joinedVirtualTables = array('servicegroups' => true);
} }
/**
* Join contacts
*/
protected function joinContacts()
{
$this->requireVirtualTable('services');
$this->select->joinLeft(
['sc' => 'icinga_service_contacts'],
'sc.service_id = s.service_id',
[]
)->joinLeft(
['sco' => 'icinga_objects'],
'sco.object_id = sc.contact_object_id AND sco.is_active = 1 AND sco.objecttype_id = 10',
[]
);
}
/**
* Join host contacts
*/
protected function joinHostcontacts()
{
$this->requireVirtualTable('services');
$this->select->joinLeft(
['h' => 'icinga_hosts'],
'h.host_object_id = s.host_object_id',
[]
)->joinLeft(
['hc' => 'icinga_host_contacts'],
'hc.host_id = h.host_id',
[]
)->joinLeft(
['hco' => 'icinga_objects'],
'hco.object_id = hc.contact_object_id AND hco.is_active = 1 AND hco.objecttype_id = 10',
[]
);
}
/** /**
* Join host groups * Join host groups
*/ */
@ -125,6 +171,9 @@ class ServicegroupQuery extends IdoQuery
protected function joinHosts() protected function joinHosts()
{ {
$this->requireVirtualTable('services'); $this->requireVirtualTable('services');
// Host custom var filters work w/o any host related table. If a host table join is necessary here some day,
// please adjust `joinHostcontacts()` where we explicitly do this already
} }
/** /**

View File

@ -35,6 +35,12 @@ class ServicestatusQuery extends IdoQuery
'checktimeperiods' => array( 'checktimeperiods' => array(
'service_check_timeperiod' => 'ctp.alias COLLATE latin1_general_ci' 'service_check_timeperiod' => 'ctp.alias COLLATE latin1_general_ci'
), ),
'contacts' => [
'service_contact' => 'sco.name1'
],
'hostcontacts' => [
'host_contact' => 'hco.name1'
],
'hostgroups' => array( 'hostgroups' => array(
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci', 'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci', 'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci',
@ -310,6 +316,40 @@ class ServicestatusQuery extends IdoQuery
); );
} }
/**
* Join contacts
*/
protected function joinContacts()
{
$this->select->joinLeft(
['sc' => 'icinga_service_contacts'],
'sc.service_id = s.service_id',
[]
)->joinLeft(
['sco' => 'icinga_objects'],
'sco.object_id = sc.contact_object_id AND sco.is_active = 1 AND sco.objecttype_id = 10',
[]
);
}
/**
* Join host contacts
*/
protected function joinHostcontacts()
{
$this->requireVirtualTable('hosts');
$this->select->joinLeft(
['hc' => 'icinga_host_contacts'],
'hc.host_id = h.host_id',
[]
)->joinLeft(
['hco' => 'icinga_objects'],
'hco.object_id = hc.contact_object_id AND hco.is_active = 1 AND hco.objecttype_id = 10',
[]
);
}
/** /**
* Join host groups * Join host groups
*/ */

View File

@ -58,7 +58,7 @@ class Hostgroupsummary extends DataView
{ {
return array( return array(
'instance_name', 'instance_name',
'host', 'host_alias', 'host_display_name', 'host_name', 'host', 'host_alias', 'host_contact', 'host_display_name', 'host_name',
'hostgroup', 'hostgroup',
'service', 'service_description', 'service_display_name', 'service', 'service_description', 'service_display_name',
'servicegroup', 'servicegroup_alias', 'servicegroup_name' 'servicegroup', 'servicegroup_alias', 'servicegroup_name'

View File

@ -71,7 +71,7 @@ class HostStatus extends DataView
public function getStaticFilterColumns() public function getStaticFilterColumns()
{ {
return array( return array(
'host', 'host', 'host_contact',
'hostgroup', 'hostgroup_alias', 'hostgroup_name', 'hostgroup', 'hostgroup_alias', 'hostgroup_name',
'service', 'service_description', 'service_display_name', 'service', 'service_description', 'service_display_name',
'servicegroup', 'servicegroup_alias', 'servicegroup_name' 'servicegroup', 'servicegroup_alias', 'servicegroup_name'

View File

@ -52,9 +52,9 @@ class Servicegroupsummary extends DataView
return array( return array(
'instance_name', 'instance_name',
'services_severity', 'services_severity',
'host', 'host_alias', 'host_display_name', 'host_name', 'host', 'host_alias', 'host_contact', 'host_display_name', 'host_name',
'hostgroup', 'hostgroup_alias', 'hostgroup_name', 'hostgroup', 'hostgroup_alias', 'hostgroup_name',
'service', 'service_description', 'service_display_name', 'service', 'service_contact', 'service_description', 'service_display_name',
'servicegroup' 'servicegroup'
); );
} }

View File

@ -155,10 +155,12 @@ class ServiceStatus extends DataView
{ {
return array( return array(
'host', 'host',
'host_contact',
'hostgroup', 'hostgroup',
'hostgroup_alias', 'hostgroup_alias',
'hostgroup_name', 'hostgroup_name',
'service', 'service',
'service_contact',
'service_host', 'service_host',
'servicegroup', 'servicegroup',
'servicegroup_alias', 'servicegroup_alias',