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

View File

@ -69,9 +69,17 @@ class Macro
try { try {
$value = $object->$macro; $value = $object->$macro;
} catch (Exception $e) { } catch (Exception $e) {
$objectName = $object->getName(); if ($object instanceof MonitoredObject) {
if ($object instanceof Service) { $objectName = $object instanceof Service
$objectName = $object->getHost()->getName() . '!' . $objectName; ? $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; $value = null;