1 # <a id="cli-commands"></a> Icinga 2 CLI Commands
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 the Icinga 2 daemon.
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
15 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
18 icinga2 <command> [<arguments>]
21 * console (Icinga console)
22 * daemon (starts Icinga 2)
23 * feature disable (disables specified feature)
24 * feature enable (enables specified feature)
25 * feature list (lists all enabled features)
27 * node blacklist add (adds a new blacklist filter)
28 * node blacklist list (lists all blacklist filters)
29 * node blacklist remove (removes a blacklist filter)
30 * node list (lists all nodes)
31 * node remove (removes node)
32 * node set (set node attributes)
33 * node setup (set up node)
34 * node update-config (update node config)
35 * node whitelist add (adds a new whitelist filter)
36 * node whitelist list (lists all whitelist filters)
37 * node whitelist remove (removes a whitelist filter)
38 * node wizard (wizard for node setup)
39 * object list (lists all objects)
40 * pki new-ca (sets up a new CA)
41 * pki new-cert (creates a new CSR)
42 * pki request (requests a certificate)
43 * pki save-cert (saves another Icinga 2 instance's certificate)
44 * pki sign-csr (signs a CSR)
45 * pki ticket (generates a ticket)
46 * repository clear-changes (clear uncommitted repository changes)
47 * repository commit (commit repository changes)
48 * repository endpoint add (adds a new Endpoint object)
49 * repository endpoint list (lists all Endpoint objects)
50 * repository endpoint remove (removes a Endpoint object)
51 * repository host add (adds a new Host object)
52 * repository host list (lists all Host objects)
53 * repository host remove (removes a Host object)
54 * repository service add (adds a new Service object)
55 * repository service list (lists all Service objects)
56 * repository service remove (removes a Service object)
57 * repository zone add (adds a new Zone object)
58 * repository zone list (lists all Zone objects)
59 * repository zone remove (removes a Zone object)
60 * troubleshoot (collect information for troubleshooting)
61 * variable get (gets a variable)
62 * variable list (lists all variables)
65 -h [ --help ] show this help message
66 -V [ --version ] show version information
67 --color use VT100 color codes even when stdout is not a
69 -D [ --define ] arg define a constant
70 -a [ --app ] arg application library name (default: icinga)
71 -l [ --library ] arg load a library
72 -I [ --include ] arg add include search directory
73 -x [ --log-level ] arg specify the log level for the console log
77 Report bugs at <https://dev.icinga.org/>
78 Icinga home page: <https://www.icinga.org/>
81 ## <a id="cli-commands-autocompletion"></a> Icinga 2 CLI Bash Autocompletion
83 Bash Auto-Completion (pressing `<TAB>`) is provided only for the corresponding context.
85 While `--config` will suggest and auto-complete files and directories on disk,
86 `feature enable` will only suggest disabled features. `repository` will know
87 about object specific attributes, and so on. Try it yourself.
89 RPM and Debian packages install the bash completion files into
90 `/etc/bash_completion.d/icinga2`.
92 You will need to install the `bash-completion` package if not already installed.
96 # yum install bash-completion
100 # zypper install bash-completion
104 # apt-get install bash-completion
106 ## <a id="cli-commands-global-options"></a> Icinga 2 CLI Global Options
110 By default the `icinga2` binary loads the `icinga` library. A different application type
111 can be specified with the `--app` command-line option.
115 Instead of loading libraries using the [`library` config directive](18-language-reference.md#library)
116 you can also use the `--library` command-line option.
120 [Global constants](18-language-reference.md#constants) can be set using the `--define` command-line option.
122 ### <a id="config-include-path"></a> Config Include Path
124 When including files you can specify that the include search path should be
125 checked. You can do this by putting your configuration file name in angle
130 This would cause Icinga 2 to search its include path for the configuration file
131 `test.conf`. By default the installation path for the Icinga Template Library
132 is the only search directory.
134 Using the `--include` command-line option additional search directories can be
138 ## <a id="cli-command-console"></a> CLI command: Console
140 The CLI command `console` can be used to evaluate Icinga config expressions, e.g. to test
141 [functions](18-language-reference.md#functions).
144 Icinga 2 (version: v2.4.0)
145 <1> => function test(name) {
146 <1> .. log("Hello " + name)
150 information/config: Hello World
155 On operating systems without the `libedit` library installed there is no
156 support for line-editing or a command history. However you can
157 use the `rlwrap` program if you require those features:
159 $ rlwrap icinga2 console
161 The `console` can be used to connect to a running Icinga 2 instance using
162 the [REST API](9-icinga2-api.md#icinga2-api). [API permissions](9-icinga2-api.md#icinga2-api-permissions)
163 are required for executing config expressions and auto-completion.
166 > The console does not currently support SSL certificate verification.
168 You can specify the API URL using the `--connect` parameter.
170 Although the password can be specified there process arguments on UNIX platforms are usually visible to other users (e.g. through `ps`). In order to securely specify the user credentials the console supports two environment variables:
172 Environment variable | Description
173 ---------------------|-------------
174 ICINGA2_API_USERNAME | The API username.
175 ICINGA2_API_PASSWORD | The API password.
179 $ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/'
180 Icinga 2 (version: v2.4.0)
183 Once connected you can inspect variables and execute other expressions by entering them at the prompt:
185 <1> => var h = get_host("example.localdomain")
187 <2> => h.last_check_result
190 check_source = "example.localdomain"
191 command = [ "/usr/local/sbin/check_ping", "-H", "127.0.0.1", "-c", "5000,100%", "-w", "3000,80%" ]
192 execution_end = 1446653527.174983
193 execution_start = 1446653523.152673
194 exit_status = 0.000000
195 output = "PING OK - Packet loss = 0%, RTA = 0.11 ms"
196 performance_data = [ "rta=0.114000ms;3000.000000;5000.000000;0.000000", "pl=0%;80;100;0" ]
197 schedule_end = 1446653527.175133
198 schedule_start = 1446653583.150000
205 state_type = 1.000000
211 state_type = 1.000000
217 You can use the `--eval` parameter to evaluate a single expression in batch mode. The output format for batch mode is JSON.
219 Here's an example that retrieves the command that was used by Icinga to check the `example.localdomain` host:
221 $ ICINGA2_API_PASSWORD=icinga icinga2 console --connect 'https://root@localhost:5665/' --eval 'get_host("example.localdomain").last_check_result.command' | python -m json.tool
223 "/usr/local/sbin/check_ping",
232 ## <a id="cli-command-daemon"></a> CLI command: Daemon
234 The CLI command `daemon` provides the functionality to start/stop Icinga 2.
235 Furthermore it provides the [configuration validation](8-cli-commands.md#config-validation).
237 # icinga2 daemon --help
238 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
241 icinga2 daemon [<arguments>]
246 -h [ --help ] show this help message
247 -V [ --version ] show version information
248 --color use VT100 color codes even when stdout is not a
250 -D [ --define ] arg define a constant
251 -a [ --app ] arg application library name (default: icinga)
252 -l [ --library ] arg load a library
253 -I [ --include ] arg add include search directory
254 -x [ --log-level ] arg specify the log level for the console log
257 -c [ --config ] arg parse a configuration file
258 -z [ --no-config ] start without a configuration file
259 -C [ --validate ] exit after validating the configuration
260 -e [ --errorlog ] arg log fatal errors to the specified log file (only works
261 in combination with --daemonize)
262 -d [ --daemonize ] detach from the controlling terminal
264 Report bugs at <https://dev.icinga.org/>
265 Icinga home page: <https://www.icinga.org/>
269 Using the `--config` option you can specify one or more configuration files.
270 Config files are processed in the order they're specified on the command-line.
272 When no configuration file is specified and the `--no-config` is not used
273 Icinga 2 automatically falls back to using the configuration file
274 `SysconfDir + "/icinga2/icinga2.conf"` (where SysconfDir is usually `/etc`).
276 ### Config Validation
278 The `--validate` option can be used to check if your configuration files
279 contain errors. If any errors are found, the exit status is 1, otherwise 0
280 is returned. More details in the [configuration validation](8-cli-commands.md#config-validation) chapter.
283 ## <a id="cli-command-feature"></a> CLI command: Feature
285 The `feature enable` and `feature disable` commands can be used to enable and disable features:
287 # icinga2 feature disable <tab>
288 checker --color --define --help --include --library --log-level mainlog notification --version
290 # icinga2 feature enable <tab>
291 api command debuglog graphite icingastatus ido-pgsql --library --log-level statusdata --version
292 --color compatlog --define --help ido-mysql --include livestatus perfdata syslog
294 The `feature list` command shows which features are currently enabled:
296 # icinga2 feature list
297 Disabled features: agent command compatlog debuglog gelf graphite icingastatus notification perfdata statusdata syslog
298 Enabled features: api checker livestatus mainlog
301 ## <a id="cli-command-node"></a> CLI command: Node
303 Provides the functionality to install and manage master and client
304 nodes in a [remote monitoring ](11-icinga2-client.md#icinga2-client) or
305 [distributed cluster](13-distributed-monitoring-ha.md#distributed-monitoring-high-availability) scenario.
308 # icinga2 node --help
309 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
312 icinga2 <command> [<arguments>]
315 * node add (add node)
316 * node blacklist add (adds a new blacklist filter)
317 * node blacklist list (lists all blacklist filters)
318 * node blacklist remove (removes a blacklist filter)
319 * node list (lists all nodes)
320 * node remove (removes node)
321 * node set (set node attributes)
322 * node setup (set up node)
323 * node update-config (update node config)
324 * node whitelist add (adds a new whitelist filter)
325 * node whitelist list (lists all whitelist filters)
326 * node whitelist remove (removes a whitelist filter)
327 * node wizard (wizard for node setup)
330 -h [ --help ] show this help message
331 -V [ --version ] show version information
332 --color use VT100 color codes even when stdout is not a
334 -D [ --define ] arg define a constant
335 -a [ --app ] arg application library name (default: icinga)
336 -l [ --library ] arg load a library
337 -I [ --include ] arg add include search directory
338 -x [ --log-level ] arg specify the log level for the console log
342 Report bugs at <https://dev.icinga.org/>
343 Icinga home page: <https://www.icinga.org/>
346 ## <a id="cli-command-object"></a> CLI command: Object
348 The `object` CLI command can be used to list all configuration objects and their
349 attributes. The command also shows where each of the attributes was modified.
350 That way you can also identify which objects have been created from your [apply rules](18-language-reference.md#apply).
352 More information can be found in the [troubleshooting](16-troubleshooting.md#list-configuration-objects) section.
354 # icinga2 object --help
355 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
358 icinga2 <command> [<arguments>]
361 * object list (lists all objects)
364 -h [ --help ] show this help message
365 -V [ --version ] show version information
366 --color use VT100 color codes even when stdout is not a
368 -D [ --define ] arg define a constant
369 -a [ --app ] arg application library name (default: icinga)
370 -l [ --library ] arg load a library
371 -I [ --include ] arg add include search directory
372 -x [ --log-level ] arg specify the log level for the console log
376 Report bugs at <https://dev.icinga.org/>
377 Icinga home page: <https://www.icinga.org/>
381 ## <a id="cli-command-pki"></a> CLI command: Pki
383 Provides the CLI commands to
385 * generate a new local CA
386 * generate a new CSR or self-signed certificate
387 * sign a CSR and return a certificate
388 * save a master certificate manually
389 * request a signed certificate from the master
390 * generate a new ticket for the client setup
392 This functionality is used by the [node setup/wizard](8-cli-commands.md#cli-command-pki) CLI commands too.
395 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
398 icinga2 <command> [<arguments>]
401 * pki new-ca (sets up a new CA)
402 * pki new-cert (creates a new CSR)
403 * pki request (requests a certificate)
404 * pki save-cert (saves another Icinga 2 instance's certificate)
405 * pki sign-csr (signs a CSR)
406 * pki ticket (generates a ticket)
409 -h [ --help ] show this help message
410 -V [ --version ] show version information
411 --color use VT100 color codes even when stdout is not a
413 -D [ --define ] arg define a constant
414 -a [ --app ] arg application library name (default: icinga)
415 -l [ --library ] arg load a library
416 -I [ --include ] arg add include search directory
417 -x [ --log-level ] arg specify the log level for the console log
421 Report bugs at <https://dev.icinga.org/>
422 Icinga home page: <https://www.icinga.org/>
425 ## <a id="cli-command-repository"></a> CLI command: Repository
427 Provides the functionality to manage the Icinga 2 configuration repository in
428 `/etc/icinga2/repository.d`. All changes are logged and must be committed or
429 cleared after review.
434 > The CLI command `repository` only supports basic configuration manipulation (add, remove)
435 > and a limited set of objects required for the [remote client] integration. Future
436 > versions will support more options (set, etc.).
438 > Please check the Icinga 2 development roadmap for updates.
441 # icinga2 repository --help
442 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
445 icinga2 <command> [<arguments>]
448 * repository clear-changes (clear uncommitted repository changes)
449 * repository commit (commit repository changes)
450 * repository endpoint add (adds a new Endpoint object)
451 * repository endpoint list (lists all Endpoint objects)
452 * repository endpoint remove (removes a Endpoint object)
453 * repository host add (adds a new Host object)
454 * repository host list (lists all Host objects)
455 * repository host remove (removes a Host object)
456 * repository service add (adds a new Service object)
457 * repository service list (lists all Service objects)
458 * repository service remove (removes a Service object)
459 * repository zone add (adds a new Zone object)
460 * repository zone list (lists all Zone objects)
461 * repository zone remove (removes a Zone object)
464 -h [ --help ] show this help message
465 -V [ --version ] show version information
466 --color use VT100 color codes even when stdout is not a
468 -D [ --define ] arg define a constant
469 -a [ --app ] arg application library name (default: icinga)
470 -l [ --library ] arg load a library
471 -I [ --include ] arg add include search directory
472 -x [ --log-level ] arg specify the log level for the console log
476 Report bugs at <https://dev.icinga.org/>
477 Icinga home page: <https://www.icinga.org/>
481 ## <a id="cli-command-troubleshoot"></a> CLI command: Troubleshoot
483 Collects basic information like version, paths, log files and crash reports for troubleshooting purposes and prints them to a file or the console. See [troubleshooting](16-troubleshooting.md#troubleshooting-information-required).
485 Its output defaults to a file named `troubleshooting-[TIMESTAMP].log` so it won't overwrite older troubleshooting files.
488 > Keep in mind that this tool can not collect information from other icinga2 nodes, you will have to run it on
489 > each of one of you instances.
490 > This is only a tool to collect information to help others help you, it will not attempt to fix anything.
493 # icinga2 troubleshoot --help
494 icinga2 - The Icinga 2 network monitoring daemon (version: v2.2.0-551-g1d0f6ed)
497 icinga2 troubleshoot [<arguments>]
500 -h [ --help ] show this help message
501 -V [ --version ] show version information
502 --color use VT100 color codes even when stdout is not aterminal
503 -D [ --define ] arg define a constant
504 -a [ --app ] arg application library name (default: icinga)
505 -l [ --library ] arg load a library
506 -I [ --include ] arg add include search directory
507 -x [ --log-level ] arg specify the log level for the console log
510 -c [ --console ] print to console instead of file
511 -o [ --output ] arg path to output file
512 --include-vars print variables to separate file
513 --inluce-objects print object to separate file
515 Report bugs at <https://dev.icinga.org/>
516 Icinga home page: <https://www.icinga.org/>
518 ## <a id="cli-command-variable"></a> CLI command: Variable
520 Lists all configured variables (constants) in a similar fasion like [object list](8-cli-commands.md#cli-command-object).
522 # icinga2 variable --help
523 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
526 icinga2 <command> [<arguments>]
529 * variable get (gets a variable)
530 * variable list (lists all variables)
533 -h [ --help ] show this help message
534 -V [ --version ] show version information
535 --color use VT100 color codes even when stdout is not a
537 -D [ --define ] arg define a constant
538 -a [ --app ] arg application library name (default: icinga)
539 -l [ --library ] arg load a library
540 -I [ --include ] arg add include search directory
541 -x [ --log-level ] arg specify the log level for the console log
545 Report bugs at <https://dev.icinga.org/>
546 Icinga home page: <https://www.icinga.org/>
549 ## <a id="enable-features"></a> Enabling/Disabling Features
551 Icinga 2 provides configuration files for some commonly used features. These
552 are installed in the `/etc/icinga2/features-available` directory and can be
553 enabled and disabled using the `icinga2 feature enable` and `icinga2 feature disable`
554 [CLI commands](8-cli-commands.md#cli-command-feature), respectively.
556 The `icinga2 feature enable` CLI command creates symlinks in the
557 `/etc/icinga2/features-enabled` directory which is included by default
558 in the example configuration file.
560 You can view a list of enabled and disabled features:
562 # icinga2 feature list
563 Disabled features: api command compatlog debuglog graphite icingastatus ido-mysql ido-pgsql livestatus notification perfdata statusdata syslog
564 Enabled features: checker mainlog notification
566 Using the `icinga2 feature enable` command you can enable features:
568 # icinga2 feature enable graphite
569 Enabling feature graphite. Make sure to restart Icinga 2 for these changes to take effect.
572 You can disable features using the `icinga2 feature disable` command:
574 # icinga2 feature disable ido-mysql livestatus
575 Disabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect.
576 Disabling feature livestatus. Make sure to restart Icinga 2 for these changes to take effect.
579 The `icinga2 feature enable` and `icinga2 feature disable` commands do not
580 restart Icinga 2. You will need to restart Icinga 2 using the init script
581 after enabling or disabling features.
585 ## <a id="config-validation"></a> Configuration Validation
587 Once you've edited the configuration files make sure to tell Icinga 2 to validate
588 the configuration changes. Icinga 2 will log any configuration error including
589 a hint on the file, the line number and the affected configuration line itself.
591 The following example creates an apply rule without any `assign` condition.
593 apply Service "5872-ping4" {
594 import "generic-service"
595 check_command = "ping4"
596 //assign where match("5872-*", host.name)
599 Validate the configuration with the init script option `checkconfig`:
601 # /etc/init.d/icinga2 checkconfig
605 > Using [systemd](2-getting-started.md#systemd-service) you need to manually validate the configuration using
606 > the CLI command below.
608 Or manually passing the `-C` argument:
610 # /usr/sbin/icinga2 daemon -c /etc/icinga2/icinga2.conf -C
612 [2014-05-22 17:07:25 +0200] critical/ConfigItem: Location:
613 /etc/icinga2/conf.d/tests/5872.conf(5): }
614 /etc/icinga2/conf.d/tests/5872.conf(6):
615 /etc/icinga2/conf.d/tests/5872.conf(7): apply Service "5872-ping4" {
617 /etc/icinga2/conf.d/tests/5872.conf(8): import "test-generic-service"
618 /etc/icinga2/conf.d/tests/5872.conf(9): check_command = "ping4"
620 Config error: 'apply' is missing 'assign'
621 [2014-05-22 17:07:25 +0200] critical/ConfigItem: 1 errors, 0 warnings.
622 Icinga 2 detected configuration errors.
626 > Icinga 2 will automatically detect the default path for `icinga2.conf`
627 > in `SysconfDir + /icinga2/icinga2.conf` and you can safely omit this parameter.
629 > `# icinga2 daemon -C`
631 If you encounter errors during configuration validation, please make sure
632 to read the [troubleshooting](16-troubleshooting.md#troubleshooting) chapter.
634 You can also use the [CLI command](8-cli-commands.md#cli-command-object) `icinga2 object list`
635 after validation passes to analyze object attributes, inheritance or created
636 objects by apply rules.
637 Find more on troubleshooting with `object list` in [this chapter](16-troubleshooting.md#list-configuration-objects).
639 Example filtered by `Service` objects with the name `ping*`:
641 # icinga2 object list --type Service --name *ping*
642 Object 'icinga.org!ping4' of type 'Service':
643 * __name = 'icinga.org!ping4'
644 * check_command = 'ping4'
645 % = modified in '/etc/icinga2/conf.d/services.conf', lines 17:3-17:25
646 * check_interval = 60
647 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 28:3-28:21
648 * host_name = 'icinga.org'
649 % = modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
650 * max_check_attempts = 3
651 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 27:3-27:24
653 % = modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
654 * retry_interval = 30
655 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 29:3-29:22
656 * templates = [ 'ping4', 'generic-service' ]
657 % += modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
658 % += modified in '/etc/icinga2/conf.d/templates.conf', lines 26:1-30:1
661 % += modified in '/etc/icinga2/conf.d/services.conf', lines 18:3-18:19
663 % = modified in '/etc/icinga2/conf.d/services.conf', lines 18:3-18:19
667 ## <a id="config-change-reload"></a> Reload on Configuration Changes
669 Everytime you have changed your configuration you should first tell Icinga 2
670 to [validate](8-cli-commands.md#config-validation). If there are no validation errors, you can
671 safely reload the Icinga 2 daemon.
673 # /etc/init.d/icinga2 reload
677 > The `reload` action will send the `SIGHUP` signal to the Icinga 2 daemon
678 > which will validate the configuration in a separate process and not stop
679 > the other events like check execution, notifications, etc.
681 > Details can be found [here](23-migrating-from-icinga-1x.md#differences-1x-2-real-reload).