Use config variable in apply for rules

* use `config` instead of `value` in apply for rules
* update documentation

refs #11976
This commit is contained in:
Corentin Ardeois 2016-09-08 18:37:23 -04:00 committed by Thomas Gelf
parent b5e984e0e5
commit 3e30d34098
7 changed files with 8 additions and 22 deletions

View File

@ -288,8 +288,8 @@ class IcingaServiceForm extends DirectorObjectForm
'description' => $this->translate(
'Evaluates the apply for rule for ' .
'all objects with the custom attribute specified. ' .
'E.g selecting "host.vars.custom_attr" will generate "for (value in ' .
'host.vars.array_var)" where "value" will be accessible through "$$value$$". ' .
'E.g selecting "host.vars.custom_attr" will generate "for (config in ' .
'host.vars.array_var)" where "config" will be accessible through "$config$". ' .
'NOTE: only custom variables of type "Array" are eligible.'
)
));

View File

@ -25,8 +25,10 @@ Then create a new `apply-rule` for the `Service template`:
![Define apply rule](screenshot/director/15_apply-for-services/154_create_apply_rule.png)
Now define the `Apply For` property, select the previously defined field `tcp_ports` associated to
the host template. `Apply For` rule define a variable `value` that can be used as `$$value$$`, it
corresponds to the item of the array it will iterate on. Set the `Tcp port` property to `$$value$$`:
the host template. `Apply For` rule define a variable `config` that can be used as `$config$`, it
corresponds to the item of the array it will iterate on.
Set the `Tcp port` property to `$config$`:
![Add field to template](screenshot/director/15_apply-for-services/155_configure_apply_for.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -159,7 +159,7 @@ class IcingaService extends IcingaObject
&& $this->get('apply_for') !== null) {
return sprintf(
"%s %s %s for (value in %s) {\n",
"%s %s %s for (config in %s) {\n",
$this->getObjectTypeName(),
$this->getType(),
c::renderString($this->getObjectName()),

View File

@ -254,7 +254,7 @@ class IcingaServiceTest extends BaseTestCase
$service = IcingaService::loadWithAutoIncId($service->id, $db);
$this->assertEquals(
$this->loadRendered('service3'),
$this->loadRendered('service5'),
(string) $service
);
}

View File

@ -1,16 +0,0 @@
apply Service "___TEST___service_$not_replaced$" {
display_name = "Service: " + host.vars.replaced
vars.custom_var = host.vars.replaced
vars.test1 = "string"
vars.test2 = 17
vars.test3 = false
vars.test4 = {
a = [ "dict", "ionary" ]
@this = "is"
}
assign where match("127.*", host.address)
import DirectorOverrideTemplate
}