IcingaServiceForm: allow to define apply rules...

...based on templates.

fixes #1359
This commit is contained in:
Thomas Gelf 2018-05-28 15:50:18 +02:00
parent 193c575e3a
commit 2045f98016
4 changed files with 13 additions and 5 deletions

View File

@ -234,7 +234,11 @@ class SuggestController extends ActionController
protected function getFilterColumns($prefix, $keys)
{
$all = IcingaService::enumProperties($this->db(), $prefix);
if ($prefix === 'host.') {
$all = IcingaHost::enumProperties($this->db(), $prefix);
} else {
$all = IcingaService::enumProperties($this->db(), $prefix);
}
$res = [];
foreach ($keys as $key) {
if (array_key_exists($key, $all)) {

View File

@ -406,14 +406,14 @@ class IcingaServiceForm extends DirectorObjectForm
protected function addAssignmentElements()
{
$this->addAssignFilter(array(
'columns' => IcingaHost::enumProperties($this->db, 'host.'),
$this->addAssignFilter([
'suggestionContext' => 'HostFilterColumns',
'required' => true,
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want'
)
));
]);
return $this;
}

View File

@ -106,7 +106,7 @@ class IcingaHost extends IcingaObject
if ($filter === null) {
$filter = new PropertiesFilter();
}
$realProperties = static::create()->listProperties();
$realProperties = array_merge(['templates'], static::create()->listProperties());
sort($realProperties);
if ($filter->match(PropertiesFilter::$HOST_PROPERTY, 'name')) {

View File

@ -206,6 +206,10 @@ abstract class ObjectApplyMatches
{
$this->object = $object;
$this->flatObject = $object->toPlainObject(true, false);
// Sure, we are flat - but we might still want to match templates.
// TODO: Flatten the whole tree
unset($this->flatObject->imports);
$this->flatObject->templates = $object->imports()->listImportNames();
static::flattenVars($this->flatObject);
}
}