MonitoredObject: Add method matches()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-17 10:40:00 +02:00
parent ade0c605a9
commit f4032988bf

View File

@ -5,9 +5,11 @@ namespace Icinga\Module\Monitoring\Object;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filterable;
use Icinga\Exception\InvalidPropertyException;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\UrlParams;
@ -208,6 +210,40 @@ abstract class MonitoredObject implements Filterable
// Left out on purpose. Interface is deprecated.
}
/**
* Return whether this object matches the given filter
*
* @param Filter $filter
*
* @return bool
*
* @throws ProgrammingError In case the object cannot be found
*/
public function matches(Filter $filter)
{
if ($this->properties === null && $this->fetch() === false) {
throw new ProgrammingError(
'Unable to apply filter. Object %s of type %s not found.',
$this->getName(),
$this->getType()
);
}
$row = clone $this->properties;
if ($this->customvars === null) {
$this->fetchCustomvars();
}
foreach ($this->customvars as $name => $value) {
if (! is_object($value)) {
$row->{'_' . $this->getType() . '_' . strtolower(str_replace(' ', '_', $name))} = $value;
}
}
return $filter->matches($row);
}
/**
* Require the object's type to be one of the given types
*