From 07e5664fbeed503e0f0cf1a4be4d28a66261b42f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 5 Oct 2015 13:59:57 +0200 Subject: [PATCH] MonitoredObject: Allow to access a set-value by name $object->contact|contactgroup|hostgroup|servicegroup + _name is now allowed and returns an array of strings refs #10304 --- .../Monitoring/Object/MonitoredObject.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 81cdb150d..2634ff051 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -848,6 +848,32 @@ abstract class MonitoredObject implements Filterable } return null; // Unknown custom variables MUST NOT throw an error + } elseif (in_array($name, array('contact_name', 'contactgroup_name', 'hostgroup_name', 'servicegroup_name'))) { + if ($name === 'contact_name') { + if ($this->contacts === null) { + $this->fetchContacts(); + } + + return array_map(function ($el) { return $el->contact_name; }, $this->contacts); + } elseif ($name === 'contactgroup_name') { + if ($this->contactgroups === null) { + $this->fetchContactgroups(); + } + + return array_map(function ($el) { return $el->contactgroup_name; }, $this->contactgroups); + } elseif ($name === 'hostgroup_name') { + if ($this->hostgroups === null) { + $this->fetchHostgroups(); + } + + return array_keys($this->hostgroups); + } else { // $name === 'servicegroup_name' + if ($this->servicegroups === null) { + $this->fetchServicegroups(); + } + + return array_keys($this->servicegroups); + } } elseif (strpos($name, $this->prefix) !== 0) { $propertyName = strtolower($name); $prefixedName = $this->prefix . $propertyName;