Skip to content

Commit

Permalink
Icingadb/CustomVarRenderer: Identify custom properties for services c…
Browse files Browse the repository at this point in the history
…reated for host templates
  • Loading branch information
raviks789 committed Aug 29, 2024
1 parent cb7955c commit 8171fd3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion library/Director/ProvidedHook/Icingadb/CustomVarRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaTemplateResolver;
use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader;
use Icinga\Module\Icingadb\Hook\CustomVarRendererHook;
use Icinga\Module\Icingadb\Model\Host;
Expand Down Expand Up @@ -73,10 +74,32 @@ public function prefetchForObject(Model $object): bool
try {
$directorHostObj = IcingaHost::load($host->name, $db);
if ($service !== null) {
$directorServiceObj = IcingaService::load([
$directorServiceObj = IcingaService::loadOptional([
'host_id' => $directorHostObj->get('id'),
'object_name' => $service->name
], $db);

if ($directorServiceObj === null) {
$templateResolver = new IcingaTemplateResolver($directorHostObj);

$parents = $templateResolver->listParentIds();

$query = $db->getDbAdapter()->select()->from('icinga_service')
->where('object_name = ?', $service->name)
->where('host_id IN (?)', $parents);

$directorServices = IcingaService::loadAll(
$db,
$query,
'object_name'
);

$directorServiceObj = current($directorServices);

if (! $directorServiceObj) {
return false;
}
}
}
} catch (NotFoundError $_) {
return false;
Expand Down

0 comments on commit 8171fd3

Please sign in to comment.