mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-24 18:37:54 +02:00
CustomVarRenderer: Fix custom var renderer for apply-for-rules
This commit is contained in:
parent
2196de252d
commit
778b25873c
@ -5,6 +5,7 @@ namespace Icinga\Module\Director\ProvidedHook\Icingadb;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\CustomVariable\CustomVariableArray;
|
||||
use Icinga\Module\Director\Daemon\Logger;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
||||
@ -113,22 +114,42 @@ class CustomVarRenderer extends CustomVarRendererHook
|
||||
$appliedFilterQuery = IcingaHostAppliedServicesTable::load($directorHostObj)->getQuery();
|
||||
|
||||
foreach ($appliedFilterQuery->fetchAll() as $appliedService) {
|
||||
if ($appliedService->name === $serviceName) {
|
||||
$query = $db->getDbAdapter()->select()->from('icinga_service')
|
||||
->where('object_name = ?', $serviceName)
|
||||
->where("object_type = 'apply'")
|
||||
->where('assign_filter = ?', $appliedService->assign_filter);
|
||||
if ($appliedService->apply_for === null) {
|
||||
$isAppliedService = $appliedService->name === $serviceName;
|
||||
} else {
|
||||
/** @var ?CustomVariableArray $hostVar */
|
||||
$hostVar = $directorHostObj->vars()->get((substr($appliedService->apply_for, 10)));
|
||||
if ($hostVar) {
|
||||
$appliedServiceName = $appliedService->name;
|
||||
$appliedForServiceLookup = [];
|
||||
foreach ($hostVar->getValue() as $val) {
|
||||
$appliedForServiceLookup[$appliedServiceName . $val] = true;
|
||||
}
|
||||
|
||||
$directorAppliedServices = IcingaService::loadAll(
|
||||
$db,
|
||||
$query,
|
||||
'object_name'
|
||||
);
|
||||
|
||||
$directorServiceObj = current($directorAppliedServices);
|
||||
|
||||
break;
|
||||
$isAppliedService = isset($appliedForServiceLookup[$serviceName]);
|
||||
} else {
|
||||
$isAppliedService = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $isAppliedService) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = $db->getDbAdapter()->select()->from('icinga_service')
|
||||
->where('object_name = ?', $appliedService->name)
|
||||
->where("object_type = 'apply'")
|
||||
->where('assign_filter = ?', $appliedService->assign_filter);
|
||||
|
||||
$directorAppliedServices = IcingaService::loadAll(
|
||||
$db,
|
||||
$query,
|
||||
'object_name'
|
||||
);
|
||||
|
||||
$directorServiceObj = current($directorAppliedServices);
|
||||
|
||||
break;
|
||||
}
|
||||
} elseif ($serviceOrigin[$i] === 'service-set') {
|
||||
$templateResolver = new IcingaTemplateResolver($directorHostObj);
|
||||
|
@ -5,6 +5,7 @@ namespace Icinga\Module\Director\ProvidedHook\Monitoring;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\CustomVariable\CustomVariableArray;
|
||||
use Icinga\Module\Director\Daemon\Logger;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
||||
@ -114,22 +115,42 @@ class CustomVarRenderer extends CustomVarRendererHook
|
||||
$appliedFilterQuery = IcingaHostAppliedServicesTable::load($directorHostObj)->getQuery();
|
||||
|
||||
foreach ($appliedFilterQuery->fetchAll() as $appliedService) {
|
||||
if ($appliedService->name === $serviceName) {
|
||||
$query = $db->getDbAdapter()->select()->from('icinga_service')
|
||||
->where('object_name = ?', $serviceName)
|
||||
->where("object_type = 'apply'")
|
||||
->where('assign_filter = ?', $appliedService->assign_filter);
|
||||
if ($appliedService->apply_for === null) {
|
||||
$isAppliedService = $appliedService->name === $serviceName;
|
||||
} else {
|
||||
/** @var ?CustomVariableArray $hostVar */
|
||||
$hostVar = $directorHostObj->vars()->get((substr($appliedService->apply_for, 10)));
|
||||
if ($hostVar) {
|
||||
$appliedServiceName = $appliedService->name;
|
||||
$appliedForServiceLookup = [];
|
||||
foreach ($hostVar->getValue() as $val) {
|
||||
$appliedForServiceLookup[$appliedServiceName . $val] = true;
|
||||
}
|
||||
|
||||
$directorAppliedServices = IcingaService::loadAll(
|
||||
$db,
|
||||
$query,
|
||||
'object_name'
|
||||
);
|
||||
|
||||
$directorServiceObj = current($directorAppliedServices);
|
||||
|
||||
break;
|
||||
$isAppliedService = isset($appliedForServiceLookup[$serviceName]);
|
||||
} else {
|
||||
$isAppliedService = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $isAppliedService) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = $db->getDbAdapter()->select()->from('icinga_service')
|
||||
->where('object_name = ?', $appliedService->name)
|
||||
->where("object_type = 'apply'")
|
||||
->where('assign_filter = ?', $appliedService->assign_filter);
|
||||
|
||||
$directorAppliedServices = IcingaService::loadAll(
|
||||
$db,
|
||||
$query,
|
||||
'object_name'
|
||||
);
|
||||
|
||||
$directorServiceObj = current($directorAppliedServices);
|
||||
|
||||
break;
|
||||
}
|
||||
} elseif ($serviceOrigin[$i] === 'service-set') {
|
||||
$templateResolver = new IcingaTemplateResolver($directorHostObj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user