ServiceSetServiceInfo: respect deactivation

fixes #2323
This commit is contained in:
Thomas Gelf 2021-06-23 18:25:14 +02:00
parent c058359ae3
commit 2538feaf42
3 changed files with 21 additions and 5 deletions

View File

@ -29,6 +29,7 @@ next (will be 1.9.0)
* FIX: show Services applied with Rules involving applied Hostgroups (#2313)
* FIX: Overrides for Services belonging to Sets on root Host Templates (#2333)
* FIX: Service Set preview inline Service Template links (#2334)
* FIX: Links to duplicate services in Sets didn't check for deactivation (#2323)
* FEATURE: show "deprecated" flag on object attribute inspection (#2312)
* FEATURE: Service Template for single Host services provides auto-completion (#1974)

View File

@ -34,9 +34,13 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
{
$matcher = HostApplyMatches::prepare($host);
$connection = $host->getConnection();
foreach (static::fetchServiceSetApplyRulesByServiceName($connection, $serviceName) as $rule) {
foreach (static::fetchServiceSetApplyRulesByServiceName($connection, $host->get('id'), $serviceName) as $rule) {
if ($matcher->matchesFilter($rule->filter)) {
return new static($host->getObjectName(), $serviceName, $rule->service_set_name);
return new static(
$host->getObjectName(),
$serviceName,
$rule->service_set_name
);
}
}
@ -75,7 +79,7 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
return true;
}
protected static function fetchServiceSetApplyRulesByServiceName(Db $connection, $serviceName)
protected static function fetchServiceSetApplyRulesByServiceName(Db $connection, $hostId, $serviceName)
{
$db = $connection->getDbAdapter();
$query = $db->select()
@ -91,7 +95,13 @@ class AppliedServiceSetServiceInfo implements ServiceInfo
[]
)
->where('s.object_name = ?', $serviceName)
->where('ss.assign_filter IS NOT NULL');
->where('ss.assign_filter IS NOT NULL')
->where( // Ignore deactivated Services:
'NOT EXISTS (SELECT 1 FROM icinga_host_service_blacklist hsb'
. ' WHERE hsb.host_id = ? AND hsb.service_id = s.id)',
(int) $hostId
);
;
$allRules = $db->fetchAll($query);
foreach ($allRules as $rule) {

View File

@ -54,7 +54,12 @@ class ServiceSetServiceInfo implements ServiceInfo
'hs.id = hsi.service_set_id',
[]
)->where('hs.host_id IN (?)', $ids)
->where('s.object_name = ?', $serviceName);
->where('s.object_name = ?', $serviceName)
->where( // Ignore deactivated Services:
'NOT EXISTS (SELECT 1 FROM icinga_host_service_blacklist hsb'
. ' WHERE hsb.host_id = ? AND hsb.service_id = s.id)',
(int) $host->get('id')
);
if ($row = $db->fetchRow($query)) {
return new static($host->getObjectName(), $serviceName, $row->service_set_name);