From 40c2cb2d12c3013817b48b2d5a8a1e5825c553c0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 23 Sep 2015 13:03:41 +0200 Subject: [PATCH] MonitoredObject: Support host- and servicegroup filters in method matches() refs #5600 --- .../Monitoring/Object/MonitoredObject.php | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index d4823892c..98ada34de 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -229,16 +229,35 @@ abstract class MonitoredObject implements Filterable ); } + $queryString = $filter->toQueryString(); $row = clone $this->properties; - if ($this->customvars === null) { - $this->fetchCustomvars(); + if (strpos($queryString, '_host_') !== false || strpos($queryString, '_service_') !== false) { + if ($this->customvars === null) { + $this->fetchCustomvars(); + } + + foreach ($this->customvars as $name => $value) { + if (! is_object($value)) { + $row->{'_' . $this->getType() . '_' . strtolower(str_replace(' ', '_', $name))} = $value; + } + } } - foreach ($this->customvars as $name => $value) { - if (! is_object($value)) { - $row->{'_' . $this->getType() . '_' . strtolower(str_replace(' ', '_', $name))} = $value; + if (strpos($queryString, 'hostgroup_name') !== false) { + if ($this->hostgroups === null) { + $this->fetchHostgroups(); } + + $row->hostgroup_name = array_keys($this->hostgroups); + } + + if (strpos($queryString, 'servicegroup_name') !== false) { + if ($this->servicegroups === null) { + $this->fetchServicegroups(); + } + + $row->servicegroup_name = array_keys($this->servicegroups); } return $filter->matches($row);