HostGroupMembershipResolver: handle single groups

Formerly this worked only with apply rules, now this also respects single host/
group assignments.

fixes #832
This commit is contained in:
Thomas Gelf 2017-05-16 11:09:25 +02:00
parent 0e759fb2f6
commit aa3a8987ba
1 changed files with 24 additions and 0 deletions

View File

@ -372,6 +372,10 @@ class HostGroupMembershipResolver
} }
} }
foreach ($this->fetchMissingSingleAssignments() as $row) {
$mappings[$row->hostgroup_id][$row->host_id] = $row->host_id;
}
$this->newMappings = $mappings; $this->newMappings = $mappings;
} }
@ -407,6 +411,26 @@ class HostGroupMembershipResolver
return $this->db->fetchPairs($query); return $this->db->fetchPairs($query);
} }
protected function fetchMissingSingleAssignments()
{
$query = $this->db->select()->from(
array('hgh' => 'icinga_hostgroup_host'),
array(
'host_id',
'hostgroup_id',
)
)->joinLeft(
array('hghr' => 'icinga_hostgroup_host_resolved'),
'hgh.host_id = hghr.host_id AND hgh.hostgroup_id = hghr.hostgroup_id',
array()
)->where('hghr.host_id IS NULL');
$this->addMembershipWhere($query, 'hgh.host_id', $this->hosts);
$this->addMembershipWhere($query, 'hgh.hostgroup_id', $this->hostgroups);
return $this->db->fetchAll($query);
}
/** /**
* @return $this * @return $this
*/ */