Macro: Resolve prefixed custom vars and object attributes

refs #10304
This commit is contained in:
Johannes Meyer 2015-10-05 13:18:10 +02:00
parent 0ed6e08175
commit 499a7d628f
1 changed files with 10 additions and 4 deletions

View File

@ -3,6 +3,9 @@
namespace Icinga\Module\Monitoring\Object;
use Exception;
use Icinga\Application\Logger;
/**
* Expand macros in string in the context of MonitoredObjects
*/
@ -60,11 +63,14 @@ class Macro
if (isset(self::$icingaMacros[$macro]) && isset($object->{self::$icingaMacros[$macro]})) {
return $object->{self::$icingaMacros[$macro]};
}
$customVar = strtolower($macro);
if (isset($object->customvars[$customVar])) {
return $object->customvars[$customVar];
try {
$value = $object->$macro;
} catch (Exception $e) {
$value = null;
Logger::debug('Unable to resolve macro "%s". An error occured: %s', $macro, $e);
}
return $macro;
return $value !== null ? $value : $macro;
}
}