]> granicus.if.org Git - icinga2/commitdiff
doc/5-advanced-topics: add example how to use custom functions in attributes
authorSimon Ruderich <simon@ruderich.org>
Fri, 20 Nov 2015 15:22:28 +0000 (16:22 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 23 Feb 2016 08:20:18 +0000 (09:20 +0100)
Signed-off-by: Jean Flach <jean-marcel.flach@netways.de>
fixes #10947

doc/5-advanced-topics.md

index c5a09f19e210528eca6b990a75ee34f765e06f7d..95ae6e4135a135e2e814054c72104cc82c8b1620 100644 (file)
@@ -366,6 +366,32 @@ You can omit the `log()` calls, they only help debugging.
       }
     }
 
+### <a id="custom-functions-as-attribute"></a> Use Custom Functions as Attribute
+
+To use custom functions as attributes, the function must be defined in a
+slightly unexpected way. The following example shows how to assign values
+depending on group membership. All hosts in the `slow-lan` host group use 300
+as value for `ping_wrta`, all other hosts use 100.
+
+    globals.group_specific_value = function(group, group_value, non_group_value) {
+        return function() use (group, group_value, non_group_value) {
+            if (group in host.groups) {
+                return group_value
+            } else {
+                return non_group_value
+            }
+        }
+    }
+    
+    apply Service "ping4" {
+        import "generic-service"
+        check_command = "ping4"
+    
+        vars.ping_wrta = group_specific_value("slow-lan", 300, 100)
+        vars.ping_crta = group_specific_value("slow-lan", 500, 200)
+    
+        assign where true
+    }
 
 
 ## <a id="access-object-attributes-at-runtime"></a> Access Object Attributes at Runtime