[icinga-checkins] icinga.org: icingaweb2-module-director/feature/assign-for-11976: Use `config` variable in apply for rules

git at icinga.org git at icinga.org
Fri Oct 21 23:17:19 CEST 2016


Module: icingaweb2-module-director
Branch: feature/assign-for-11976
Commit: 32e4787fbfe76fd81862c2aa40f976c3eae40c77
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=32e4787fbfe76fd81862c2aa40f976c3eae40c77

Author: Corentin Ardeois <cardeois at internap.com>
Date:   Thu Sep  8 18:37:23 2016 -0400

Use `config` variable in apply for rules

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

refs #11976

---

 application/forms/IcingaServiceForm.php                        |    4 ++--
 doc/15-Service-apply-for-example.md                            |    6 ++++--
 .../director/15_apply-for-services/155_configure_apply_for.png |  Bin 35848 -> 35789 bytes
 .../director/15_apply-for-services/156_config_preview.png      |  Bin 30190 -> 34882 bytes
 library/Director/Objects/IcingaService.php                     |    2 +-
 test/php/library/Director/Objects/IcingaServiceTest.php        |    2 +-
 .../Director/Objects/rendered/{service3.out => service5.out}   |    8 +++++---
 7 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php
index 6bafe9d..99d9c8a 100644
--- a/application/forms/IcingaServiceForm.php
+++ b/application/forms/IcingaServiceForm.php
@@ -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.'
                 )
             ));
diff --git a/doc/15-Service-apply-for-example.md b/doc/15-Service-apply-for-example.md
index d6c0bf8..ae1fbf1 100644
--- a/doc/15-Service-apply-for-example.md
+++ b/doc/15-Service-apply-for-example.md
@@ -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)
 
diff --git a/doc/screenshot/director/15_apply-for-services/155_configure_apply_for.png b/doc/screenshot/director/15_apply-for-services/155_configure_apply_for.png
index 8d6c6e3..b17ce9e 100644
Binary files a/doc/screenshot/director/15_apply-for-services/155_configure_apply_for.png and b/doc/screenshot/director/15_apply-for-services/155_configure_apply_for.png differ
diff --git a/doc/screenshot/director/15_apply-for-services/156_config_preview.png b/doc/screenshot/director/15_apply-for-services/156_config_preview.png
index f4c0392..c9b20f8 100644
Binary files a/doc/screenshot/director/15_apply-for-services/156_config_preview.png and b/doc/screenshot/director/15_apply-for-services/156_config_preview.png differ
diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php
index c405975..6a237e0 100644
--- a/library/Director/Objects/IcingaService.php
+++ b/library/Director/Objects/IcingaService.php
@@ -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()),
diff --git a/test/php/library/Director/Objects/IcingaServiceTest.php b/test/php/library/Director/Objects/IcingaServiceTest.php
index 6c5b41a..0bbb91c 100644
--- a/test/php/library/Director/Objects/IcingaServiceTest.php
+++ b/test/php/library/Director/Objects/IcingaServiceTest.php
@@ -251,7 +251,7 @@ class IcingaServiceTest extends BaseTestCase
 
         $service = IcingaService::loadWithAutoIncId($service->id, $db);
         $this->assertEquals(
-            $this->loadRendered('service3'),
+            $this->loadRendered('service5'),
             (string) $service
         );
     }
diff --git a/test/php/library/Director/Objects/rendered/service3.out b/test/php/library/Director/Objects/rendered/service5.out
similarity index 52%
rename from test/php/library/Director/Objects/rendered/service3.out
rename to test/php/library/Director/Objects/rendered/service5.out
index c161edb..d1b0573 100644
--- a/test/php/library/Director/Objects/rendered/service3.out
+++ b/test/php/library/Director/Objects/rendered/service5.out
@@ -1,13 +1,15 @@
-apply Service "___TEST___service" for (key => value in host.vars.test1) {
+apply Service "___TEST___service" for (config in host.vars.test1) {
     display_name = "Whatever service"
     vars.test1 = "string"
     vars.test2 = 17
     vars.test3 = false
     vars.test4 = {
-        "a" = [ "dict", "ionary" ]
-        "this" = "is"
+        a = [ "dict", "ionary" ]
+        @this = "is"
     }
 
     assign where host.vars.env == "test"
+
+    import DirectorOverrideTemplate
 }
 



More information about the icinga-checkins mailing list