]> granicus.if.org Git - icinga2/blobdiff - doc/19-language-reference.md
Implement the Dictionary#keys method
[icinga2] / doc / 19-language-reference.md
index 7b0a0c4e12b2d7dfbb6fd72dc83b542f0ec2f000..e7f039fbdaa58db010a0c5742c72c8745feec45f 100644 (file)
@@ -368,7 +368,6 @@ ObjectsPath         |**Read-write.** Contains the path of the Icinga 2 objects f
 PidPath             |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to RunDir + "/icinga2/icinga2.pid".
 Vars                |**Read-write.** Contains a dictionary with global custom attributes. Not set by default.
 NodeName            |**Read-write.** Contains the cluster node name. Set to the local hostname by default.
-ApplicationType     |**Read-write.** Contains the name of the Application type. Defaults to "icinga/IcingaApplication".
 EnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.
 EnableEventHandlers |**Read-write.** Whether event handlers are globally enabled. Defaults to true.
 EnableFlapping      |**Read-write.** Whether flap detection is globally enabled. Defaults to true.
@@ -376,6 +375,7 @@ EnableHostChecks    |**Read-write.** Whether active host checks are globally ena
 EnableServiceChecks |**Read-write.** Whether active service checks are globally enabled. Defaults to true.
 EnablePerfdata      |**Read-write.** Whether performance data processing is globally enabled. Defaults to true.
 UseVfork            |**Read-write.** Whether to use vfork(). Only available on *NIX. Defaults to true.
+AttachDebugger      |**Read-write.** Whether to attach a debugger when Icinga 2 crashes. Defaults to false.
 RunAsUser              |**Read-write.** Defines the user the Icinga 2 daemon is running as. Used in the `init.conf` configuration file.
 RunAsGroup             |**Read-write.** Defines the group the Icinga 2 daemon is running as. Used in the `init.conf` configuration file.
 
@@ -518,6 +518,29 @@ recursively included.
 The file names need to match the pattern given in the second parameter.
 When no pattern is specified the default pattern "*.conf" is used.
 
+## <a id="zone-includes"></a> Zone Includes
+
+The `include_zones` recursively includes all subdirectories for the
+given path.
+
+In addition to that it sets the `zone` attribute for all objects created
+in these subdirectories to the name of the subdirectory.
+
+Example:
+
+    include_zones "etc", "zones.d", "*.conf"
+    include_zones "puppet", "puppet-zones"
+
+The first parameter specifies a tag name for this directive. Each `include_zones`
+invocation should use a unique tag name. When copying the zones' configuration
+files Icinga uses the tag name as the name for the destination directory in
+`/var/lib/icinga2/api/config`.
+
+The second parameter specifies the directory which contains the subdirectories.
+
+The file names need to match the pattern given in the third parameter.
+When no pattern is specified the default pattern "*.conf" is used.
+
 ## <a id="library"></a> Library directive
 
 The `library` directive can be used to manually load additional
@@ -535,8 +558,8 @@ Functions can be defined using the `function` keyword.
 Example:
 
     function multiply(a, b) {
-         return a * b
-       }
+      return a * b
+    }
 
 When encountering the `return` keyword further execution of the function is terminated and
 the specified value is supplied to the caller of the function:
@@ -554,15 +577,15 @@ last expression which was performed by the function. For example, we could have
 `multiply` function like this:
 
     function multiply(a, b) {
-         a * b
-       }
+      a * b
+    }
 
 Anonymous functions can be created by omitting the name in the function definition. The
 resulting function object can be used like any other value:
 
     var fn = function() { 3 }
-       
-       fn() /* Returns 3 */
+
+    fn() /* Returns 3 */
 
 ## <a id="lambdas"></a> Lambda Expressions
 
@@ -575,8 +598,8 @@ Example:
 Multiple statements can be used by putting the function body into braces:
 
     f = (x) => {
-         log("Lambda called")
-         x * x
+      log("Lambda called")
+      x * x
     }
 
 Just like with ordinary functions the return value is the value of the last statement.
@@ -608,9 +631,9 @@ The local scope contains variables which only exist during the invocation of the
 object or apply statement. Local variables can be declared using the `var` keyword:
 
     function multiply(a, b) {
-         var temp = a * b
-         return temp
-       }
+      var temp = a * b
+      return temp
+    }
 
 Each time the `multiply` function is invoked a new `temp` variable is used which is in no way
 related to previous invocations of the function.
@@ -622,7 +645,7 @@ The `this` scope refers to the current object which the function or object/apply
 operates on.
 
     object Host "localhost" {
-         check_interval = 5m
+      check_interval = 5m
     }
 
 In this example the `this` scope refers to the "localhost" object. The `check_interval` attribute
@@ -631,7 +654,7 @@ is set for this particular host.
 You can explicitly access the `this` scope using the `this` keyword:
 
     object Host "localhost" {
-         var check_interval = 5m
+      var check_interval = 5m
   
       /* This explicitly specifies that the attribute should be set
        * for the host, if we had omitted `this.` the (poorly named)
@@ -646,19 +669,43 @@ Functions also have a `this` scope. However unlike for object/apply statements t
 a function is set to whichever object was used to invoke the function. Here's an example:
 
      hm = {
-          h_word = null
-                
-          function init(word) {
-            h_word = word
-          }
-        }
-        
-        /* Let's invoke the init() function */
-        hm.init("hello")
+       h_word = null
+       function init(word) {
+         h_word = word
+       }
+     }
+
+     /* Let's invoke the init() function */
+     hm.init("hello")
 
 We're using `hm.init` to invoke the function which causes the value of `hm` to become the `this`
 scope for this function call.
 
+## <a id="closures"></a> Closures
+
+By default `function`s, `object`s and `apply` rules do not have access to variables declared
+outside of their scope (except for global variables).
+
+In order to access variables which are defined in the outer scope the `use` keyword can be used:
+
+    function MakeHelloFunction(name) {
+      return function() use(name) {
+        log("Hello, " + name)
+      }
+    }
+
+In this case a new variable `name` is created inside the inner function's scope which has the
+value of the `name` function argument.
+
+Alternatively a different value for the inner variable can be specified:
+
+    function MakeHelloFunction(name) {
+      return function() use (greeting = "Hello, " + name) {
+        log(greeting)
+      }
+    }
+
 ## <a id="conditional-statements"></a> Conditional Statements
 
 Sometimes it can be desirable to only evaluate statements when certain conditions are met. The if/else
@@ -680,12 +727,12 @@ An if/else construct can also be used in place of any other value. The value of
 is the value of the last statement which was evaluated for the branch which was taken:
 
     a = if (true) {
-         log("Taking the 'true' branch")
-         7 * 3
-       } else {
-         log("Taking the 'false' branch")
-         9
-       }
+      log("Taking the 'true' branch")
+      7 * 3
+    } else {
+      log("Taking the 'false' branch")
+      9
+    }
 
 This example prints the log message "Taking the 'true' branch" and the `a` variable is set to 21 (7 * 3).
 
@@ -716,10 +763,10 @@ The `for` statement can be used to iterate over arrays and dictionaries.
 Example:
 
     var list = [ "a", "b", "c" ]
-       
-       for (item in list) {
-         log("Item: " + item)
-       }
+
+    for (item in list) {
+      log("Item: " + item)
+    }
 
 The loop body is evaluated once for each item in the array. The variable `item` is declared as a local
 variable just as if the `var` keyword had been used.
@@ -727,9 +774,9 @@ variable just as if the `var` keyword had been used.
 Iterating over dictionaries can be accomplished in a similar manner:
 
     var dict = { a = 3, b = 7 }
-       
-       for (key => value in dict) {
-         log("Key: " + key + ", Value: " + value)
+
+    for (key => value in dict) {
+      log("Key: " + key + ", Value: " + value)
     }
 
 The `continue` and `break` keywords can be used to control how the loop is executed: The `continue` keyword
@@ -764,7 +811,7 @@ type objects are made available using global variables which match the type's na
 The type object's `prototype` property can be used to find out which methods a certain type
 supports:
 
-       /* This returns: ["find","len","lower","replace","split","substr","to_string","upper"] */
+    /* This returns: ["find","len","lower","replace","split","substr","to_string","upper"] */
     keys(String.prototype)
 
 ## <a id="reserved-keywords"></a> Reserved Keywords