diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 61a2c2e9..7fc0b7db 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -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) diff --git a/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php b/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php index bd3587e2..44f40018 100644 --- a/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/AppliedServiceSetServiceInfo.php @@ -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) { diff --git a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php index ac913efe..8e0ee613 100644 --- a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php @@ -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);