Macro: Don't break ui if undefined macro given

$object can be an instance of stdClass and cannot call getName(). The name must then be retrieved manually.
This commit is contained in:
Sukhwinder Dhillon 2024-03-25 14:20:04 +01:00 committed by Johannes Meyer
parent b268044efc
commit 41787d91bf
1 changed files with 11 additions and 3 deletions

View File

@ -69,9 +69,17 @@ class Macro
try {
$value = $object->$macro;
} catch (Exception $e) {
$objectName = $object->getName();
if ($object instanceof Service) {
$objectName = $object->getHost()->getName() . '!' . $objectName;
if ($object instanceof MonitoredObject) {
$objectName = $object instanceof Service
? $object->getHost()->getName() . '!' . $object->getName()
: $object->getName();
} else {
$host = 'host_name';
$service = 'service_description';
$objectName = isset($object->$service)
? $object->$service . '!' . $object->$host
: $object->$host;
}
$value = null;