|
5 | 5 | use Icinga\Application\Config;
|
6 | 6 | use Icinga\Exception\ConfigurationError;
|
7 | 7 | use Icinga\Exception\NotFoundError;
|
| 8 | +use Icinga\Module\Director\CustomVariable\CustomVariableArray; |
8 | 9 | use Icinga\Module\Director\Daemon\Logger;
|
9 | 10 | use Icinga\Module\Director\Db;
|
10 | 11 | use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
@@ -114,22 +115,42 @@ public function prefetchForObject(MonitoredObject $object)
|
114 | 115 | $appliedFilterQuery = IcingaHostAppliedServicesTable::load($directorHostObj)->getQuery();
|
115 | 116 |
|
116 | 117 | foreach ($appliedFilterQuery->fetchAll() as $appliedService) {
|
117 |
| - if ($appliedService->name === $serviceName) { |
118 |
| - $query = $db->getDbAdapter()->select()->from('icinga_service') |
119 |
| - ->where('object_name = ?', $serviceName) |
120 |
| - ->where("object_type = 'apply'") |
121 |
| - ->where('assign_filter = ?', $appliedService->assign_filter); |
| 118 | + if ($appliedService->apply_for === null) { |
| 119 | + $isAppliedService = $appliedService->name === $serviceName; |
| 120 | + } else { |
| 121 | + /** @var ?CustomVariableArray $hostVar */ |
| 122 | + $hostVar = $directorHostObj->vars()->get((substr($appliedService->apply_for, 10))); |
| 123 | + if ($hostVar) { |
| 124 | + $appliedServiceName = $appliedService->name; |
| 125 | + $appliedForServiceLookup = []; |
| 126 | + foreach ($hostVar->getValue() as $val) { |
| 127 | + $appliedForServiceLookup[$appliedServiceName . $val] = true; |
| 128 | + } |
| 129 | + |
| 130 | + $isAppliedService = isset($appliedForServiceLookup[$serviceName]); |
| 131 | + } else { |
| 132 | + $isAppliedService = false; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + if (! $isAppliedService) { |
| 137 | + continue; |
| 138 | + } |
122 | 139 |
|
123 |
| - $directorAppliedServices = IcingaService::loadAll( |
124 |
| - $db, |
125 |
| - $query, |
126 |
| - 'object_name' |
127 |
| - ); |
| 140 | + $query = $db->getDbAdapter()->select()->from('icinga_service') |
| 141 | + ->where('object_name = ?', $appliedService->name) |
| 142 | + ->where("object_type = 'apply'") |
| 143 | + ->where('assign_filter = ?', $appliedService->assign_filter); |
128 | 144 |
|
129 |
| - $directorServiceObj = current($directorAppliedServices); |
| 145 | + $directorAppliedServices = IcingaService::loadAll( |
| 146 | + $db, |
| 147 | + $query, |
| 148 | + 'object_name' |
| 149 | + ); |
130 | 150 |
|
131 |
| - break; |
132 |
| - } |
| 151 | + $directorServiceObj = current($directorAppliedServices); |
| 152 | + |
| 153 | + break; |
133 | 154 | }
|
134 | 155 | } elseif ($serviceOrigin[$i] === 'service-set') {
|
135 | 156 | $templateResolver = new IcingaTemplateResolver($directorHostObj);
|
|
0 commit comments