From 305a731e371fcdad1c423e491445d760a5febc45 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 21 Mar 2024 16:15:05 +0100 Subject: [PATCH] Macros: Log the object where a macro is not found fixes #952 --- library/Icingadb/Common/Macros.php | 13 +++++++++---- phpstan.neon | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library/Icingadb/Common/Macros.php b/library/Icingadb/Common/Macros.php index 4842c271..c7f0e154 100644 --- a/library/Icingadb/Common/Macros.php +++ b/library/Icingadb/Common/Macros.php @@ -8,7 +8,7 @@ use Icinga\Application\Logger; use Icinga\Module\Icingadb\Compat\CompatHost; use Icinga\Module\Icingadb\Compat\CompatService; use Icinga\Module\Icingadb\Model\Host; -use ipl\Orm\Model; +use Icinga\Module\Icingadb\Model\Service; use ipl\Orm\Query; use ipl\Orm\ResultSet; @@ -20,7 +20,7 @@ trait Macros * Get the given string with macros being resolved * * @param string $input The string in which to look for macros - * @param Model|CompatService|CompatHost $object The host or service used to resolve the macros + * @param Host|Service|CompatService|CompatHost $object The host or service used to resolve the macros * * @return string */ @@ -42,7 +42,7 @@ trait Macros * Resolve a macro based on the given object * * @param string $macro The macro to resolve - * @param Model|CompatService|CompatHost $object The host or service used to resolve the macros + * @param Host|Service|CompatService|CompatHost $object The host or service used to resolve the macros * * @return string */ @@ -102,8 +102,13 @@ trait Macros $value = $object->$macro; } } catch (\Exception $e) { + $objectName = $object->name; + if ($objectType === 'service' && isset($object->host)) { + $objectName = $object->host->name . '!' . $objectName; + } + $value = null; - Logger::debug('Unable to resolve macro "%s". An error occurred: %s', $macro, $e); + Logger::debug('Unable to resolve macro "%s" on object "%s". An error occured: %s', $macro, $objectName, $e); } if ($value instanceof Query || $value instanceof ResultSet || is_array($value)) { diff --git a/phpstan.neon b/phpstan.neon index 5b8c6e84..a0656a4b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -29,3 +29,4 @@ parameters: - ipl\Orm\Model - Icinga\Web\View - Icinga\Data\ConfigObject + - Icinga\Module\Monitoring\Object\MonitoredObject