1 # Icinga 2 CLI Commands <a id="cli-commands"></a>
3 Icinga 2 comes with a number of CLI commands which support bash autocompletion.
5 These CLI commands will allow you to use certain functionality
6 provided by and around Icinga 2.
8 Each CLI command provides its own help and usage information, so please
9 make sure to always run them with the `--help` parameter.
11 Run `icinga2` without any arguments to get a list of all available global
16 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
19 icinga2 <command> [<arguments>]
22 * api setup (setup for API)
23 * ca list (lists all certificate signing requests)
24 * ca restore (restores a removed certificate request)
25 * ca remove (removes an outstanding certificate request)
26 * ca sign (signs an outstanding certificate request)
27 * console (Icinga debug console)
28 * daemon (starts Icinga 2)
29 * feature disable (disables specified feature)
30 * feature enable (enables specified feature)
31 * feature list (lists all available features)
32 * node setup (set up node)
33 * node wizard (wizard for node setup)
34 * object list (lists all objects)
35 * pki new-ca (sets up a new CA)
36 * pki new-cert (creates a new CSR)
37 * pki request (requests a certificate)
38 * pki save-cert (saves another Icinga 2 instance's certificate)
39 * pki sign-csr (signs a CSR)
40 * pki ticket (generates a ticket)
41 * variable get (gets a variable)
42 * variable list (lists all variables)
45 -h [ --help ] show this help message
46 -V [ --version ] show version information
47 --color use VT100 color codes even when stdout is not a
49 -D [ --define ] arg define a constant
50 -a [ --app ] arg application library name (default: icinga)
51 -l [ --library ] arg load a library
52 -I [ --include ] arg add include search directory
53 -x [ --log-level ] arg specify the log level for the console log.
54 The valid value is either debug, notice,
55 information (default), warning, or critical
56 -X [ --script-debugger ] whether to enable the script debugger
58 Report bugs at <https://github.com/Icinga/icinga2>
59 Icinga home page: <https://icinga.com/>
63 ## Icinga 2 CLI Bash Autocompletion <a id="cli-commands-autocompletion"></a>
65 Bash Auto-Completion (pressing `<TAB>`) is provided only for the corresponding context.
67 While `--config` suggests and auto-completes files and directories on disk,
68 `feature enable` only suggests disabled features.
70 RPM and Debian packages install the bash completion files into
71 `/etc/bash_completion.d/icinga2`.
73 You need to install the `bash-completion` package if not already installed.
78 # yum install bash-completion
84 # zypper install bash-completion
90 # apt-get install bash-completion
93 Ensure that the `bash-completion.d` directory is added to your shell
94 environment. You can manually source the icinga2 bash-completion file
95 into your current session and test it:
98 # source /etc/bash-completion.d/icinga2
102 ## Icinga 2 CLI Global Options <a id="cli-commands-global-options"></a>
106 By default the `icinga2` binary loads the `icinga` library. A different application type
107 can be specified with the `--app` command-line option.
108 Note: This is not needed by the average Icinga user, only developers.
112 Instead of loading libraries using the [`library` config directive](17-language-reference.md#library)
113 you can also use the `--library` command-line option.
114 Note: This is not needed by the average Icinga user, only developers.
118 [Global constants](17-language-reference.md#constants) can be set using the `--define` command-line option.
120 ### Config Include Path <a id="config-include-path"></a>
122 When including files you can specify that the include search path should be
123 checked. You can do this by putting your configuration file name in angle
130 This causes Icinga 2 to search its include path for the configuration file
131 `test.conf`. By default the installation path for the [Icinga Template Library](10-icinga-template-library.md#icinga-template-library)
132 is the only search directory.
134 Using the `--include` command-line option additional search directories can be
137 ## CLI command: Api <a id="cli-command-api"></a>
139 Provides helper functions to enable and setup the
140 [Icinga 2 API](12-icinga2-api.md#icinga2-api-setup).
142 ### CLI command: Api Setup <a id="cli-command-api-setup "></a>
145 # icinga2 api setup --help
146 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
149 icinga2 api setup [<arguments>]
151 Setup for Icinga 2 API.
154 -h [ --help ] show this help message
155 -V [ --version ] show version information
156 --color use VT100 color codes even when stdout is not a
158 -D [ --define ] arg define a constant
159 -I [ --include ] arg add include search directory
160 -x [ --log-level ] arg specify the log level for the console log.
161 The valid value is either debug, notice,
162 information (default), warning, or critical
163 -X [ --script-debugger ] whether to enable the script debugger
166 --cn arg The certificate's common name
168 Report bugs at <https://github.com/Icinga/icinga2>
169 Get support: <https://icinga.com/support/>
170 Documentation: <https://icinga.com/docs/>
171 Icinga home page: <https://icinga.com/>
174 ## CLI command: Ca <a id="cli-command-ca"></a>
176 List and manage incoming certificate signing requests. More details
177 can be found in the [signing methods](06-distributed-monitoring.md#distributed-monitoring-setup-sign-certificates-master)
178 chapter. This CLI command is available since v2.8.
182 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
185 icinga2 <command> [<arguments>]
188 * ca list (lists all certificate signing requests)
189 * ca sign (signs an outstanding certificate request)
190 * ca restore (restores a removed certificate request)
191 * ca remove (removes an outstanding certificate request)
194 -h [ --help ] show this help message
195 -V [ --version ] show version information
196 --color use VT100 color codes even when stdout is not a
198 -D [ --define ] arg define a constant
199 -a [ --app ] arg application library name (default: icinga)
200 -l [ --library ] arg load a library
201 -I [ --include ] arg add include search directory
202 -x [ --log-level ] arg specify the log level for the console log.
203 The valid value is either debug, notice,
204 information (default), warning, or critical
205 -X [ --script-debugger ] whether to enable the script debugger
207 Report bugs at <https://github.com/Icinga/icinga2>
208 Icinga home page: <https://icinga.com/>
212 ### CLI command: Ca List <a id="cli-command-ca-list"></a>
215 icinga2 ca list --help
216 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
219 icinga2 ca list [<arguments>]
221 Lists pending certificate signing requests.
224 -h [ --help ] show this help message
225 -V [ --version ] show version information
226 --color use VT100 color codes even when stdout is not a
228 -D [ --define ] arg define a constant
229 -I [ --include ] arg add include search directory
230 -x [ --log-level ] arg specify the log level for the console log.
231 The valid value is either debug, notice,
232 information (default), warning, or critical
233 -X [ --script-debugger ] whether to enable the script debugger
236 --all List all certificate signing requests, including
237 signed. Note: Old requests are automatically
238 cleaned by Icinga after 1 week.
239 --removed List all removed CSRs (for use with 'ca restore')
240 --json encode output as JSON
242 Report bugs at <https://github.com/Icinga/icinga2>
243 Get support: <https://icinga.com/support/>
244 Documentation: <https://icinga.com/docs/>
245 Icinga home page: <https://icinga.com/>
248 ## CLI command: Console <a id="cli-command-console"></a>
250 The CLI command `console` can be used to debug and evaluate Icinga 2 config expressions,
251 e.g. to test [functions](17-language-reference.md#functions) in your local sandbox.
255 Icinga 2 (version: v2.11.0)
256 <1> => function test(name) {
257 <1> .. log("Hello " + name)
261 information/config: Hello World
266 Further usage examples can be found in the [library reference](18-library-reference.md#library-reference) chapter.
269 # icinga2 console --help
270 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
273 icinga2 console [<arguments>]
275 Interprets Icinga script expressions.
278 -h [ --help ] show this help message
279 -V [ --version ] show version information
280 --color use VT100 color codes even when stdout is not a
282 -D [ --define ] arg define a constant
283 -a [ --app ] arg application library name (default: icinga)
284 -l [ --library ] arg load a library
285 -I [ --include ] arg add include search directory
286 -x [ --log-level ] arg specify the log level for the console log.
287 The valid value is either debug, notice,
288 information (default), warning, or critical
289 -X [ --script-debugger ] whether to enable the script debugger
292 -c [ --connect ] arg connect to an Icinga 2 instance
293 -e [ --eval ] arg evaluate expression and terminate
294 -r [ --file ] arg evaluate a file and terminate
295 --syntax-only only validate syntax (requires --eval or --file)
296 --sandbox enable sandbox mode
298 Report bugs at <https://github.com/Icinga/icinga2>
299 Icinga home page: <https://icinga.com/>
303 On operating systems without the `libedit` library installed there is no
304 support for line-editing or a command history. However you can
305 use the `rlwrap` program if you require those features:
308 $ rlwrap icinga2 console
311 The debug console can be used to connect to a running Icinga 2 instance using
312 the [REST API](12-icinga2-api.md#icinga2-api). [API permissions](12-icinga2-api.md#icinga2-api-permissions)
313 are required for executing config expressions and auto-completion.
317 > The debug console does not currently support TLS certificate verification.
319 > Runtime modifications are not validated and might cause the Icinga 2
320 > daemon to crash or behave in an unexpected way. Use these runtime changes
321 > at your own risk and rather *inspect and debug objects read-only*.
323 You can specify the API URL using the `--connect` parameter.
325 Although the password can be specified there process arguments on UNIX platforms are
326 usually visible to other users (e.g. through `ps`). In order to securely specify the
327 user credentials the debug console supports two environment variables:
329 Environment variable | Description
330 ---------------------|-------------
331 ICINGA2_API_USERNAME | The API username.
332 ICINGA2_API_PASSWORD | The API password.
337 $ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/'
338 Icinga 2 (version: v2.11.0)
342 Once connected you can inspect variables and execute other expressions by entering them at the prompt:
345 <1> => var h = get_host("icinga2-agent1.localdomain")
347 <2> => h.last_check_result
350 check_source = "icinga2-agent1.localdomain"
351 command = [ "/usr/local/sbin/check_ping", "-H", "127.0.0.1", "-c", "5000,100%", "-w", "3000,80%" ]
352 execution_end = 1446653527.174983
353 execution_start = 1446653523.152673
354 exit_status = 0.000000
355 output = "PING OK - Packet loss = 0%, RTA = 0.11 ms"
356 performance_data = [ "rta=0.114000ms;3000.000000;5000.000000;0.000000", "pl=0%;80;100;0" ]
357 schedule_end = 1446653527.175133
358 schedule_start = 1446653583.150000
365 state_type = 1.000000
371 state_type = 1.000000
377 You can use the `--eval` parameter to evaluate a single expression in batch mode.
378 Using the `--file` option you can specify a file which should be evaluated.
379 The output format for batch mode is JSON.
381 The `--syntax-only` option can be used in combination with `--eval` or `--file`
382 to check a script for syntax errors. In this mode the script is parsed to identify
383 syntax errors but not evaluated.
385 Here's an example that retrieves the command that was used by Icinga to check the `icinga2-agent1.localdomain` host:
388 $ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/' --eval 'get_host("icinga2-agent1.localdomain").last_check_result.command' | python -m json.tool
390 "/usr/local/sbin/check_ping",
400 ## CLI command: Daemon <a id="cli-command-daemon"></a>
402 The CLI command `daemon` provides the functionality to start/stop Icinga 2.
403 Furthermore it allows to run the [configuration validation](11-cli-commands.md#config-validation).
406 # icinga2 daemon --help
407 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
410 icinga2 daemon [<arguments>]
415 -h [ --help ] show this help message
416 -V [ --version ] show version information
417 --color use VT100 color codes even when stdout is not a
419 -D [ --define ] arg define a constant
420 -a [ --app ] arg application library name (default: icinga)
421 -l [ --library ] arg load a library
422 -I [ --include ] arg add include search directory
423 -x [ --log-level ] arg specify the log level for the console log.
424 The valid value is either debug, notice,
425 information (default), warning, or critical
426 -X [ --script-debugger ] whether to enable the script debugger
429 -c [ --config ] arg parse a configuration file
430 -z [ --no-config ] start without a configuration file
431 -C [ --validate ] exit after validating the configuration
432 -e [ --errorlog ] arg log fatal errors to the specified log file (only
433 works in combination with --daemonize or
435 -d [ --daemonize ] detach from the controlling terminal
436 --close-stdio do not log to stdout (or stderr) after startup
438 Report bugs at <https://github.com/Icinga/icinga2>
439 Icinga home page: <https://icinga.com/>
442 ### Config Files <a id="cli-command-daemon-config-files"></a>
444 You can specify one or more configuration files with the `--config` option.
445 Configuration files are processed in the order they're specified on the command-line.
447 When no configuration file is specified and the `--no-config` is not used
448 Icinga 2 automatically falls back to using the configuration file
449 `ConfigDir + "/icinga2.conf"` (where ConfigDir is usually `/etc/icinga2`).
451 ### Validation <a id="cli-command-daemon-validation"></a>
453 The `--validate` option can be used to check if configuration files
454 contain errors. If any errors are found, the exit status is 1, otherwise 0
455 is returned. More details in the [configuration validation](11-cli-commands.md#config-validation) chapter.
457 ## CLI command: Feature <a id="cli-command-feature"></a>
459 The `feature enable` and `feature disable` commands can be used to enable and disable features:
462 # icinga2 feature disable <tab>
463 --app --define --include --log-level --version checker graphite mainlog
464 --color --help --library --script-debugger api command ido-mysql notification
468 # icinga2 feature enable <tab>
469 --app --define --include --log-level --version debuglog ido-pgsql livestatus perfdata syslog
470 --color --help --library --script-debugger compatlog gelf influxdb opentsdb statusdata
473 The `feature list` command shows which features are currently enabled:
476 # icinga2 feature list
477 Disabled features: compatlog debuglog gelf ido-pgsql influxdb livestatus opentsdb perfdata statusdata syslog
478 Enabled features: api checker command graphite ido-mysql mainlog notification
481 ## CLI command: Node <a id="cli-command-node"></a>
483 Provides the functionality to setup master and client
484 nodes in a [distributed monitoring](06-distributed-monitoring.md#distributed-monitoring) scenario.
487 # icinga2 node --help
488 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
491 icinga2 <command> [<arguments>]
494 * node setup (set up node)
495 * node wizard (wizard for node setup)
498 -h [ --help ] show this help message
499 -V [ --version ] show version information
500 --color use VT100 color codes even when stdout is not a
502 -D [ --define ] arg define a constant
503 -a [ --app ] arg application library name (default: icinga)
504 -l [ --library ] arg load a library
505 -I [ --include ] arg add include search directory
506 -x [ --log-level ] arg specify the log level for the console log.
507 The valid value is either debug, notice,
508 information (default), warning, or critical
509 -X [ --script-debugger ] whether to enable the script debugger
511 Report bugs at <https://github.com/Icinga/icinga2>
512 Icinga home page: <https://icinga.com/>
515 ## CLI command: Object <a id="cli-command-object"></a>
517 The `object` CLI command can be used to list all configuration objects and their
518 attributes. The command also shows where each of the attributes was modified and as such
519 provides debug information for further configuration problem analysis.
520 That way you can also identify which objects have been created from your [apply rules](17-language-reference.md#apply).
522 Runtime modifications via the [REST API](12-icinga2-api.md#icinga2-api-config-objects)
523 are not immediately updated. Furthermore there is a known issue with
524 [group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
525 You need to restart Icinga 2 in order to update the `icinga2.debug` cache file.
527 More information can be found in the [troubleshooting](15-troubleshooting.md#troubleshooting-list-configuration-objects) section.
530 # icinga2 object --help
531 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
534 icinga2 <command> [<arguments>]
537 * object list (lists all objects)
540 -h [ --help ] show this help message
541 -V [ --version ] show version information
542 --color use VT100 color codes even when stdout is not a
544 -D [ --define ] arg define a constant
545 -a [ --app ] arg application library name (default: icinga)
546 -l [ --library ] arg load a library
547 -I [ --include ] arg add include search directory
548 -x [ --log-level ] arg specify the log level for the console log.
549 The valid value is either debug, notice,
550 information (default), warning, or critical
551 -X [ --script-debugger ] whether to enable the script debugger
553 Report bugs at <https://github.com/Icinga/icinga2>
554 Icinga home page: <https://icinga.com/>
557 ## CLI command: Pki <a id="cli-command-pki"></a>
559 Provides the CLI commands to
561 * generate a new certificate authority (CA)
562 * generate a new CSR or self-signed certificate
563 * sign a CSR and return a certificate
564 * save a master certificate manually
565 * request a signed certificate from the master
566 * generate a new ticket for the client setup
568 This functionality is used by the [node setup/wizard](11-cli-commands.md#cli-command-node) CLI commands.
569 You will need them in the [distributed monitoring chapter](06-distributed-monitoring.md#distributed-monitoring).
573 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
576 icinga2 <command> [<arguments>]
579 * pki new-ca (sets up a new CA)
580 * pki new-cert (creates a new CSR)
581 * pki request (requests a certificate)
582 * pki save-cert (saves another Icinga 2 instance's certificate)
583 * pki sign-csr (signs a CSR)
584 * pki ticket (generates a ticket)
587 -h [ --help ] show this help message
588 -V [ --version ] show version information
589 --color use VT100 color codes even when stdout is not a
591 -D [ --define ] arg define a constant
592 -a [ --app ] arg application library name (default: icinga)
593 -l [ --library ] arg load a library
594 -I [ --include ] arg add include search directory
595 -x [ --log-level ] arg specify the log level for the console log.
596 The valid value is either debug, notice,
597 information (default), warning, or critical
598 -X [ --script-debugger ] whether to enable the script debugger
600 Report bugs at <https://github.com/Icinga/icinga2>
601 Icinga home page: <https://icinga.com/>
604 ## CLI command: Variable <a id="cli-command-variable"></a>
606 Lists all configured variables (constants) in a similar fashion like [object list](11-cli-commands.md#cli-command-object).
609 # icinga2 variable --help
610 icinga2 - The Icinga 2 network monitoring daemon (version: v2.11.0)
613 icinga2 <command> [<arguments>]
616 * variable get (gets a variable)
617 * variable list (lists all variables)
620 -h [ --help ] show this help message
621 -V [ --version ] show version information
622 --color use VT100 color codes even when stdout is not a
624 -D [ --define ] arg define a constant
625 -a [ --app ] arg application library name (default: icinga)
626 -l [ --library ] arg load a library
627 -I [ --include ] arg add include search directory
628 -x [ --log-level ] arg specify the log level for the console log.
629 The valid value is either debug, notice,
630 information (default), warning, or critical
631 -X [ --script-debugger ] whether to enable the script debugger
633 Report bugs at <https://github.com/Icinga/icinga2>
634 Icinga home page: <https://icinga.com/>
637 ## Enabling/Disabling Features <a id="enable-features"></a>
639 Icinga 2 provides configuration files for some commonly used features. These
640 are installed in the `/etc/icinga2/features-available` directory and can be
641 enabled and disabled using the `icinga2 feature enable` and `icinga2 feature disable`
642 [CLI commands](11-cli-commands.md#cli-command-feature), respectively.
644 The `icinga2 feature enable` CLI command creates symlinks in the
645 `/etc/icinga2/features-enabled` directory which is included by default
646 in the example configuration file.
648 You can view a list of enabled and disabled features:
651 # icinga2 feature list
652 Disabled features: api command compatlog debuglog graphite icingastatus ido-mysql ido-pgsql livestatus notification perfdata statusdata syslog
653 Enabled features: checker mainlog notification
656 Using the `icinga2 feature enable` command you can enable features:
659 # icinga2 feature enable graphite
660 Enabling feature graphite. Make sure to restart Icinga 2 for these changes to take effect.
663 You can disable features using the `icinga2 feature disable` command:
666 # icinga2 feature disable ido-mysql livestatus
667 Disabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect.
668 Disabling feature livestatus. Make sure to restart Icinga 2 for these changes to take effect.
671 The `icinga2 feature enable` and `icinga2 feature disable` commands do not
672 restart Icinga 2. You will need to restart Icinga 2 using the init script
673 after enabling or disabling features.
677 ## Configuration Validation <a id="config-validation"></a>
679 Once you've edited the configuration files make sure to tell Icinga 2 to validate
680 the configuration changes. Icinga 2 will log any configuration error including
681 a hint on the file, the line number and the affected configuration line itself.
683 The following example creates an apply rule without any `assign` condition.
686 apply Service "my-ping4" {
687 import "generic-service"
688 check_command = "ping4"
689 //assign where host.address
693 Validate the configuration:
698 [2014-05-22 17:07:25 +0200] critical/ConfigItem: Location:
699 /etc/icinga2/conf.d/tests/my.conf(5): }
700 /etc/icinga2/conf.d/tests/my.conf(6):
701 /etc/icinga2/conf.d/tests/my.conf(7): apply Service "my-ping4" {
703 /etc/icinga2/conf.d/tests/my.conf(8): import "test-generic-service"
704 /etc/icinga2/conf.d/tests/my.conf(9): check_command = "ping4"
706 Config error: 'apply' is missing 'assign'
707 [2014-05-22 17:07:25 +0200] critical/ConfigItem: 1 errors, 0 warnings.
708 Icinga 2 detected configuration errors.
711 If you encounter errors during configuration validation, please make sure
712 to read the [troubleshooting](15-troubleshooting.md#troubleshooting) chapter.
714 You can also use the [CLI command](11-cli-commands.md#cli-command-object) `icinga2 object list`
715 after validation passes to analyze object attributes, inheritance or created
716 objects by apply rules.
717 Find more on troubleshooting with `object list` in [this chapter](15-troubleshooting.md#troubleshooting-list-configuration-objects).
720 ## Reload on Configuration Changes <a id="config-change-reload"></a>
722 Every time you have changed your configuration you should first tell Icinga 2
723 to [validate](11-cli-commands.md#config-validation). If there are no validation errors, you can
724 safely reload the Icinga 2 daemon.
727 # systemctl reload icinga2
730 The `reload` action will send the `SIGHUP` signal to the Icinga 2 daemon
731 which will validate the configuration in a separate process and not stop
732 the other events like check execution, notifications, etc.