]> granicus.if.org Git - icinga2/commitdiff
Add documentation for the script debugger
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 10 Nov 2015 13:45:27 +0000 (14:45 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 10 Nov 2015 13:45:46 +0000 (14:45 +0100)
fixes #10577

doc/1-about.md
doc/12-agent-based-checks.md
doc/15-features.md
doc/16-troubleshooting.md
doc/20-script-debugger.md [new file with mode: 0644]
doc/21-development.md [moved from doc/20-debug.md with 98% similarity]
doc/22-migrating-from-icinga-1x.md [moved from doc/21-migrating-from-icinga-1x.md with 99% similarity]
doc/23-appendix.md [moved from doc/22-appendix.md with 100% similarity]
doc/3-monitoring-basics.md
doc/8-cli-commands.md
mkdocs.yml

index 1f1bbb0f73e8e6a20c6d19aa70a3f04049c2d8e8..85fa68607e8266e18c91c60fcbf9114978f3afe9 100644 (file)
@@ -31,7 +31,7 @@ Please get in touch with the Icinga team at https://www.icinga.org/community/.
 If you want to help update this documentation please read
 [this howto](https://wiki.icinga.org/display/community/Update+the+Icinga+2+documentation).
 
-### <a id="development"></a> Icinga 2 Development
+### <a id="development-info"></a> Icinga 2 Development
 
 You can follow Icinga 2's development closely by checking
 out these resources:
index 3bd360b94a9790b47363e232e1cd96a4ff6ff3fc..15e2d5fca15ed5e78156e09de586989e0ac0cb0c 100644 (file)
@@ -181,7 +181,7 @@ SNMP Traps can be received and filtered by using [SNMPTT](http://snmptt.sourcefo
 and specific trap handlers passing the check results to Icinga 2.
 
 Following the SNMPTT [Format](http://snmptt.sourceforge.net/docs/snmptt.shtml#SNMPTT.CONF-FORMAT)
-documentation and the Icinga external command syntax found [here](22-appendix.md#external-commands-list-detail)
+documentation and the Icinga external command syntax found [here](23-appendix.md#external-commands-list-detail)
 we can create generic services that can accommodate any number of hosts for a given scenario.
 
 ### <a id="simple-traps"></a> Simple SNMP Traps
index db13c96f2c58398bf69e5fc9f818634979f09728..c337cccb438b83026e1633a794aae40ba676ea3b 100644 (file)
@@ -74,7 +74,7 @@ Example for PostgreSQL:
     (1 Zeile)
 
 
-A detailed list on the available table attributes can be found in the [DB IDO Schema documentation](22-appendix.md#schema-db-ido).
+A detailed list on the available table attributes can be found in the [DB IDO Schema documentation](23-appendix.md#schema-db-ido).
 
 
 ## <a id="external-commands"></a> External Commands
@@ -102,7 +102,7 @@ a forced service check:
     Oct 17 15:01:25 icinga-server icinga2: Executing external command: [1382014885] SCHEDULE_FORCED_SVC_CHECK;localhost;ping4;1382014885
     Oct 17 15:01:25 icinga-server icinga2: Rescheduling next check for service 'ping4'
 
-A list of currently supported external commands can be found [here](22-appendix.md#external-commands-list-detail).
+A list of currently supported external commands can be found [here](23-appendix.md#external-commands-list-detail).
 
 Detailed information on the commands and their required parameters can be found
 on the [Icinga 1.x documentation](http://docs.icinga.org/latest/en/extcommands2.html).
@@ -414,7 +414,7 @@ re-implementation of the Livestatus protocol which is compatible with MK
 Livestatus.
 
 Details on the available tables and attributes with Icinga 2 can be found
-in the [Livestatus Schema](22-appendix.md#schema-livestatus) section.
+in the [Livestatus Schema](23-appendix.md#schema-livestatus) section.
 
 You can enable Livestatus using icinga2 feature enable:
 
@@ -490,7 +490,7 @@ Example using the tcp socket listening on port `6558`:
 
 ### <a id="livestatus-command-queries"></a> Livestatus COMMAND Queries
 
-A list of available external commands and their parameters can be found [here](22-appendix.md#external-commands-list-detail)
+A list of available external commands and their parameters can be found [here](23-appendix.md#external-commands-list-detail)
 
     $ echo -e 'COMMAND <externalcommandstring>' | netcat 127.0.0.1 6558
 
@@ -591,7 +591,7 @@ Default separators.
 
 The `commands` table is populated with `CheckCommand`, `EventCommand` and `NotificationCommand` objects.
 
-A detailed list on the available table attributes can be found in the [Livestatus Schema documentation](22-appendix.md#schema-livestatus).
+A detailed list on the available table attributes can be found in the [Livestatus Schema documentation](23-appendix.md#schema-livestatus).
 
 
 ## <a id="status-data"></a> Status Data Files
index 08f27970d9ac7ef0cfdff66d9f76790d30863d01..95670d126ea707cd8963df23cc02945a6ea76b04 100644 (file)
@@ -13,7 +13,7 @@
 * How was Icinga 2 installed (and which repository in case) and which distribution are you using
 * Provide complete configuration snippets explaining your problem in detail
 * If the check command failed - what's the output of your manual plugin tests?
-* In case of [debugging](20-debug.md#debug) Icinga 2, the full back traces and outputs
+* In case of [debugging](21-development.md#development) Icinga 2, the full back traces and outputs
 
 ## <a id="troubleshooting-enable-debug-output"></a> Enable Debug Output
 
diff --git a/doc/20-script-debugger.md b/doc/20-script-debugger.md
new file mode 100644 (file)
index 0000000..e28f69d
--- /dev/null
@@ -0,0 +1,105 @@
+# <a id="script-debugger"></a> Script Debugger
+
+You can run the Icinga 2 daemon with the `-X` (`--script-debugger`)
+parameter to enable the script debugger:
+
+    # icinga2 daemon -X
+
+When an exception occurs or the [debugger](18-language-reference.md#breakpoints)
+keyword is encountered in a user script Icinga 2 launches a console that
+allows the user to debug the script.
+
+Here is a list of common error which can be diagnosed with the script debugger:
+
+* Configuration errors (apply)
+* Errors in user-defined functions
+
+## <a id="script-debugger-config-errors"></a> Debugging Configuration Errors
+
+The following example illustrates the problem of a service [apply rule](3-monitoring-basics.md#using-apply-for)
+which expects a dictionary value for `config`, but the host custom attribute only
+provides a string value:
+
+    object Host "script-debugger-host" {
+      check_command = "icinga"
+
+      vars.http_vhosts["example.org"] = "192.168.1.100" // a string value
+    }
+
+    apply Service for (http_vhost => config in host.vars.http_vhosts) {
+      import "generic-service"
+
+      vars += config // expects a dictionary
+
+      check_command = "http"
+    }
+
+The error message on config validation will warn about the wrong value type,
+but does not provide any context which objects are affected.
+
+Enable the script debugger and run the config validation:
+
+    # icinga2 daemon -C -X
+
+    Breakpoint encountered in /etc/icinga2/conf.d/services.conf: 59:67-65:1
+    Exception: Error: Error while evaluating expression: Cannot convert value of type 'String' to an object.
+    Location:
+    /etc/icinga2/conf.d/services.conf(62):   check_command = "http"
+    /etc/icinga2/conf.d/services.conf(63):
+    /etc/icinga2/conf.d/services.conf(64):   vars += config
+                                             ^^^^^^^^^^^^^^
+    /etc/icinga2/conf.d/services.conf(65): }
+    /etc/icinga2/conf.d/services.conf(66):
+    You can inspect expressions (such as variables) by entering them at the prompt.
+    To leave the debugger and continue the program use "$continue".
+    <1> =>
+
+You can print the variables `vars` and `config` to get an idea about
+their values:
+
+    <1> => vars
+    null
+    <2> => config
+    "192.168.1.100"
+    <3> =>
+
+The `vars` attribute has to be a dictionary. Trying to set this attribute to a string caused
+the error in our configuration example.
+
+In order to determine the name of the host where the value of the `config` variable came from
+you can inspect attributes of the service object:
+
+    <3> => host_name
+    "script-debugger-host-01"
+    <4> => name
+    "http"
+
+Additionally you can view the service object attributes by printing the value of `this`.
+
+## <a id="script-debugger-breakpoints"></a> Using Breakpoints
+
+In order to halt execution in a script you can use the `debugger` keyword:
+
+    object Host "script-debugger-host-02" {
+      check_command = "dummy"
+      check_interval = 5s
+
+      vars.dummy_text = {{
+        var text = "Hello from " + macro("$name$")
+        debugger
+        return text
+      }}
+    }
+
+Icinga 2 will spawn a debugger console every time the function is executed:
+
+    # icinga2 daemon -X
+    ...
+    Breakpoint encountered in /etc/icinga2/tests/script-debugger.conf: 7:5-7:12
+    You can inspect expressions (such as variables) by entering them at the prompt.
+    To leave the debugger and continue the program use "$continue".
+    <1> => text
+    "Hello from script-debugger-host-02"
+    <2> => $continue
+
+
similarity index 98%
rename from doc/20-debug.md
rename to doc/21-development.md
index 8c907307f6151a695c72d7b18dc7d5005b9ceb89..043948b28750a7968b77d41ae0f271602cd2e047 100644 (file)
@@ -1,4 +1,7 @@
-# <a id="debug"></a> Debug Icinga 2
+# <a id="development"></a> Develop Icinga 2
+
+This chapter provides hints on Icinga 2 development
+especially for debugging purposes.
 
 > **Note**
 >
similarity index 99%
rename from doc/21-migrating-from-icinga-1x.md
rename to doc/22-migrating-from-icinga-1x.md
index eaace3994fbfa8d196db12e2ca6208d314e3b793..c6e742f444b7b5727c8319e2ec402aa5532abc1b 100644 (file)
@@ -29,7 +29,7 @@ object specific policies.
 For a long-term migration of your configuration you should consider re-creating
 your configuration based on the proposed Icinga 2 configuration paradigm.
 
-Please read the [next chapter](21-migrating-from-icinga-1x.md#differences-1x-2) to find out more about the differences
+Please read the [next chapter](22-migrating-from-icinga-1x.md#differences-1x-2) to find out more about the differences
 between 1.x and 2.
 
 ### <a id="manual-config-migration-hints"></a> Manual Config Migration Hints
@@ -42,7 +42,7 @@ The examples are taken from Icinga 1.x test and production environments and conv
 straight into a possible Icinga 2 format. If you found a different strategy, please
 let us know!
 
-If you require in-depth explanations, please check the [next chapter](21-migrating-from-icinga-1x.md#differences-1x-2).
+If you require in-depth explanations, please check the [next chapter](22-migrating-from-icinga-1x.md#differences-1x-2).
 
 #### <a id="manual-config-migration-hints-Intervals"></a> Manual Config Migration Hints for Intervals
 
@@ -205,7 +205,7 @@ While you could manually migrate this like (please note the new generic command
 
 #### <a id="manual-config-migration-hints-runtime-macros"></a> Manual Config Migration Hints for Runtime Macros
 
-Runtime macros have been renamed. A detailed comparison table can be found [here](21-migrating-from-icinga-1x.md#differences-1x-2-runtime-macros).
+Runtime macros have been renamed. A detailed comparison table can be found [here](22-migrating-from-icinga-1x.md#differences-1x-2-runtime-macros).
 
 For example, accessing the service check output looks like the following in Icinga 1.x:
 
@@ -278,7 +278,7 @@ while the service check command resolves its value to the service attribute attr
 #### <a id="manual-config-migration-hints-contacts-users"></a> Manual Config Migration Hints for Contacts (Users)
 
 Contacts in Icinga 1.x act as users in Icinga 2, but do not have any notification commands specified.
-This migration part is explained in the [next chapter](21-migrating-from-icinga-1x.md#manual-config-migration-hints-notifications).
+This migration part is explained in the [next chapter](22-migrating-from-icinga-1x.md#manual-config-migration-hints-notifications).
 
     define contact{
       contact_name                    testconfig-user
@@ -288,7 +288,7 @@ This migration part is explained in the [next chapter](21-migrating-from-icinga-
       email                           icinga@localhost
     }
 
-The `service_notification_options` can be [mapped](21-migrating-from-icinga-1x.md#manual-config-migration-hints-notification-filters)
+The `service_notification_options` can be [mapped](22-migrating-from-icinga-1x.md#manual-config-migration-hints-notification-filters)
 into generic `state` and `type` filters, if additional notification filtering is required. `alias` gets
 renamed to `display_name`.
 
@@ -340,7 +340,7 @@ Assign it to the host or service and set the newly generated notification comman
 
 
 Convert the `notification_options` attribute from Icinga 1.x to Icinga 2 `states` and `types`. Details
-[here](21-migrating-from-icinga-1x.md#manual-config-migration-hints-notification-filters). Add the notification period.
+[here](22-migrating-from-icinga-1x.md#manual-config-migration-hints-notification-filters). Add the notification period.
 
       states = [ OK, Warning, Critical ]
       types = [ Recovery, Problem, Custom ]
@@ -577,7 +577,7 @@ enabled.
       assign where "hg_svcdep2" in host.groups
     }
 
-Host dependencies are explained in the [next chapter](21-migrating-from-icinga-1x.md#manual-config-migration-hints-host-parents).
+Host dependencies are explained in the [next chapter](22-migrating-from-icinga-1x.md#manual-config-migration-hints-host-parents).
 
 
 
@@ -948,7 +948,7 @@ In Icinga 1.x arguments are specified in the `check_command` attribute and
 are separated from the command name using an exclamation mark (`!`).
 
 Please check the migration hints for a detailed
-[migration example](21-migrating-from-icinga-1x.md#manual-config-migration-hints-check-command-arguments).
+[migration example](22-migrating-from-icinga-1x.md#manual-config-migration-hints-check-command-arguments).
 
 > **Note**
 >
similarity index 100%
rename from doc/22-appendix.md
rename to doc/23-appendix.md
index ffe267e739954b5a0a7a5ea6b01818233cc4a675..6cad4c0f41144178fc2b27da17e854175b83c30b 100644 (file)
@@ -1774,7 +1774,7 @@ Rephrased: If the parent service object changes into the `Warning` state, this
 dependency will fail and render all child objects (hosts or services) unreachable.
 
 You can determine the child's reachability by querying the `is_reachable` attribute
-in for example [DB IDO](22-appendix.md#schema-db-ido-extensions).
+in for example [DB IDO](23-appendix.md#schema-db-ido-extensions).
 
 ### <a id="dependencies-implicit-host-service"></a> Implicit Dependencies for Services on Host
 
index c399fe807ddd79f475fb9b7cf52c86328122e7ad..0ec471bfdbeaaf63cf21bd9e0493ffeb39459b21 100644 (file)
@@ -678,5 +678,5 @@ safely reload the Icinga 2 daemon.
 > which will validate the configuration in a separate process and not stop
 > the other events like check execution, notifications, etc.
 >
-> Details can be found [here](21-migrating-from-icinga-1x.md#differences-1x-2-real-reload).
+> Details can be found [here](22-migrating-from-icinga-1x.md#differences-1x-2-real-reload).
 
index fd103dddd94a5b9598bccf2261393660e15c626b..1550c1516f2df91766c853501672ce788ad3c5f6 100644 (file)
@@ -21,9 +21,10 @@ pages:
 - [17-upgrading-icinga-2.md, Upgrading Icinga 2]
 - [18-language-reference.md, Language Reference]
 - [19-library-reference.md, Library Reference]
-- [20-debug.md, Debug]
-- [21-migrating-from-icinga-1x.md, Migrating from Icinga 1.x]
-- [22-appendix.md, Appendix]
+- [20-script-debugger.md, Script Debugger]
+- [21-development.md, Development]
+- [22-migrating-from-icinga-1x.md, Migrating from Icinga 1.x]
+- [23-appendix.md, Appendix]
 theme: readthedocs
 markdown_extensions: [smarty]
 extra_javascript: [scroll.js]