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 -l [ --library ] arg load a library
71 -I [ --include ] arg add include search directory
72 -x [ --log-level ] arg specify the log level for the console log
76 Report bugs at <https://dev.icinga.org/>
77 Icinga home page: <https://www.icinga.org/>
80 ## <a id="cli-commands-autocompletion"></a> Icinga 2 CLI Bash Autocompletion
82 Bash Auto-Completion (pressing `<TAB>`) is provided only for the corresponding context.
84 While `--config` will suggest and auto-complete files and directories on disk,
85 `feature enable` will only suggest disabled features. `repository` will know
86 about object specific attributes, and so on. Try it yourself.
88 RPM and Debian packages install the bash completion files into
89 `/etc/bash_completion.d/icinga2`.
91 You will need to install the `bash-completion` package if not already installed.
95 # yum install bash-completion
99 # zypper install bash-completion
103 # apt-get install bash-completion
105 ## <a id="cli-commands-global-options"></a> Icinga 2 CLI Global Options
109 Instead of loading libraries using the [`library` config directive](19-language-reference.md#library)
110 you can also use the `--library` command-line option.
114 [Global constants](19-language-reference.md#constants) can be set using the `--define` command-line option.
116 ### <a id="config-include-path"></a> Config Include Path
118 When including files you can specify that the include search path should be
119 checked. You can do this by putting your configuration file name in angle
124 This would cause Icinga 2 to search its include path for the configuration file
125 `test.conf`. By default the installation path for the Icinga Template Library
126 is the only search directory.
128 Using the `--include` command-line option additional search directories can be
132 ## <a id="cli-command-console"></a> CLI command: Console
134 The CLI command `console` can be used to evaluate Icinga config expressions, e.g. to test
135 `assign where` rules.
138 Icinga (version: v2.2.0-435-gc95d2f1)
139 <1> => function test(name) {
140 <1> .. log("Hello " + name)
144 information/config: Hello World
147 The `console` command does not support line-editing or a command history. However you can
148 use the `rlwrap` program if you require those features:
150 $ rlwrap icinga2 console
152 ## <a id="cli-command-daemon"></a> CLI command: Daemon
154 The CLI command `daemon` provides the functionality to start/stop Icinga 2.
155 Furthermore it provides the [configuration validation](8-cli-commands.md#config-validation).
157 # icinga2 daemon --help
158 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
161 icinga2 daemon [<arguments>]
166 -h [ --help ] show this help message
167 -V [ --version ] show version information
168 --color use VT100 color codes even when stdout is not a
170 -D [ --define ] arg define a constant
171 -l [ --library ] arg load a library
172 -I [ --include ] arg add include search directory
173 -x [ --log-level ] arg specify the log level for the console log
176 -c [ --config ] arg parse a configuration file
177 -z [ --no-config ] start without a configuration file
178 -C [ --validate ] exit after validating the configuration
179 -e [ --errorlog ] arg log fatal errors to the specified log file (only works
180 in combination with --daemonize)
181 -d [ --daemonize ] detach from the controlling terminal
183 Report bugs at <https://dev.icinga.org/>
184 Icinga home page: <https://www.icinga.org/>
188 Using the `--config` option you can specify one or more configuration files.
189 Config files are processed in the order they're specified on the command-line.
191 When no configuration file is specified and the `--no-config` is not used
192 Icinga 2 automatically falls back to using the configuration file
193 `SysconfDir + "/icinga2/icinga2.conf"` (where SysconfDir is usually `/etc`).
195 ### Config Validation
197 The `--validate` option can be used to check if your configuration files
198 contain errors. If any errors are found the exit status is 1, otherwise 0
199 is returned. More details in the [configuration validation](8-cli-commands.md#config-validation) chapter.
202 ## <a id="cli-command-feature"></a> CLI command: Feature
204 The `feature enable` and `feature disable` commands can be used to enable and disable features:
206 # icinga2 feature disable <tab>
207 checker --color --define --help --include --library --log-level mainlog notification --version
209 # icinga2 feature enable <tab>
210 api command debuglog graphite icingastatus ido-pgsql --library --log-level statusdata --version
211 --color compatlog --define --help ido-mysql --include livestatus perfdata syslog
213 The `feature list` command shows which features are currently enabled:
215 # icinga2 feature list
216 Disabled features: agent command compatlog debuglog gelf graphite icingastatus notification perfdata statusdata syslog
217 Enabled features: api checker livestatus mainlog
220 ## <a id="cli-command-node"></a> CLI command: Node
222 Provides the functionality to install and manage master and client
223 nodes in a [remote monitoring ](10-icinga2-client.md#icinga2-client) or
224 [distributed cluster](12-distributed-monitoring-ha.md#distributed-monitoring-high-availability) scenario.
227 # icinga2 node --help
228 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
231 icinga2 <command> [<arguments>]
234 * node add (add node)
235 * node blacklist add (adds a new blacklist filter)
236 * node blacklist list (lists all blacklist filters)
237 * node blacklist remove (removes a blacklist filter)
238 * node list (lists all nodes)
239 * node remove (removes node)
240 * node set (set node attributes)
241 * node setup (set up node)
242 * node update-config (update node config)
243 * node whitelist add (adds a new whitelist filter)
244 * node whitelist list (lists all whitelist filters)
245 * node whitelist remove (removes a whitelist filter)
246 * node wizard (wizard for node setup)
249 -h [ --help ] show this help message
250 -V [ --version ] show version information
251 --color use VT100 color codes even when stdout is not a
253 -D [ --define ] arg define a constant
254 -l [ --library ] arg load a library
255 -I [ --include ] arg add include search directory
256 -x [ --log-level ] arg specify the log level for the console log
260 Report bugs at <https://dev.icinga.org/>
261 Icinga home page: <https://www.icinga.org/>
264 ## <a id="cli-command-object"></a> CLI command: Object
266 The `object` CLI command can be used to list all configuration objects and their
267 attributes. The command also shows where each of the attributes was modified.
268 That way you can also identify which objects have been created from your [apply rules](19-language-reference.md#apply).
270 More information can be found in the [troubleshooting](16-troubleshooting.md#list-configuration-objects) section.
272 # icinga2 object --help
273 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
276 icinga2 <command> [<arguments>]
279 * object list (lists all objects)
282 -h [ --help ] show this help message
283 -V [ --version ] show version information
284 --color use VT100 color codes even when stdout is not a
286 -D [ --define ] arg define a constant
287 -l [ --library ] arg load a library
288 -I [ --include ] arg add include search directory
289 -x [ --log-level ] arg specify the log level for the console log
293 Report bugs at <https://dev.icinga.org/>
294 Icinga home page: <https://www.icinga.org/>
298 ## <a id="cli-command-pki"></a> CLI command: Pki
300 Provides the CLI commands to
302 * generate a new local CA
303 * generate a new CSR or self-signed certificate
304 * sign a CSR and return a certificate
305 * save a master certificate manually
306 * request a signed certificate from the master
307 * generate a new ticket for the client setup
309 This functionality is used by the [node setup/wizard](8-cli-commands.md#cli-command-pki) CLI commands too.
312 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
315 icinga2 <command> [<arguments>]
318 * pki new-ca (sets up a new CA)
319 * pki new-cert (creates a new CSR)
320 * pki request (requests a certificate)
321 * pki save-cert (saves another Icinga 2 instance's certificate)
322 * pki sign-csr (signs a CSR)
323 * pki ticket (generates a ticket)
326 -h [ --help ] show this help message
327 -V [ --version ] show version information
328 --color use VT100 color codes even when stdout is not a
330 -D [ --define ] arg define a constant
331 -l [ --library ] arg load a library
332 -I [ --include ] arg add include search directory
333 -x [ --log-level ] arg specify the log level for the console log
337 Report bugs at <https://dev.icinga.org/>
338 Icinga home page: <https://www.icinga.org/>
341 ## <a id="cli-command-repository"></a> CLI command: Repository
343 Provides the functionality to manage the Icinga 2 configuration repository in
344 `/etc/icinga2/repository.d`. All changes are logged and must be committed or
345 cleared after review.
350 > The CLI command `repository` only supports basic configuration manipulation (add, remove)
351 > and a limited set of objects required for the [remote client] integration. Future
352 > versions will support more options (set, etc.).
354 > Please check the Icinga 2 development roadmap for updates.
357 # icinga2 repository --help
358 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
361 icinga2 <command> [<arguments>]
364 * repository clear-changes (clear uncommitted repository changes)
365 * repository commit (commit repository changes)
366 * repository endpoint add (adds a new Endpoint object)
367 * repository endpoint list (lists all Endpoint objects)
368 * repository endpoint remove (removes a Endpoint object)
369 * repository host add (adds a new Host object)
370 * repository host list (lists all Host objects)
371 * repository host remove (removes a Host object)
372 * repository service add (adds a new Service object)
373 * repository service list (lists all Service objects)
374 * repository service remove (removes a Service object)
375 * repository zone add (adds a new Zone object)
376 * repository zone list (lists all Zone objects)
377 * repository zone remove (removes a Zone object)
380 -h [ --help ] show this help message
381 -V [ --version ] show version information
382 --color use VT100 color codes even when stdout is not a
384 -D [ --define ] arg define a constant
385 -l [ --library ] arg load a library
386 -I [ --include ] arg add include search directory
387 -x [ --log-level ] arg specify the log level for the console log
391 Report bugs at <https://dev.icinga.org/>
392 Icinga home page: <https://www.icinga.org/>
396 ## <a id="cli-command-variable"></a> CLI command: Troubleshoot
398 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).
400 Its output defaults to a file named `troubleshooting-[TIMESTAMP].log` so it won't overwrite older troubleshooting files.
403 > Keep in mind that this tool can not collect information from other icinga2 nodes, you will have to run it on
404 > each of one of you instances.
405 > This is only a tool to collect information to help others help you, it will not attempt to fix anything.
408 # icinga2 troubleshoot --help
409 icinga2 - The Icinga 2 network monitoring daemon (version: v2.2.0-551-g1d0f6ed)
412 icinga2 troubleshoot [<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 aterminal
418 -D [ --define ] arg define a constant
419 -l [ --library ] arg load a library
420 -I [ --include ] arg add include search directory
421 -x [ --log-level ] arg specify the log level for the console log
424 -c [ --console ] print to console instead of file
425 -o [ --output ] arg path to output file
426 --include-vars print variables to separate file
427 --inluce-objects print object to separate file
429 Report bugs at <https://dev.icinga.org/>
430 Icinga home page: <https://www.icinga.org/>
432 ## <a id="cli-command-variable"></a> CLI command: Variable
434 Lists all configured variables (constants) in a similar fasion like [object list](8-cli-commands.md#cli-command-object).
436 # icinga2 variable --help
437 icinga2 - The Icinga 2 network monitoring daemon (version: v2.1.1-299-gf695275)
440 icinga2 <command> [<arguments>]
443 * variable get (gets a variable)
444 * variable list (lists all variables)
447 -h [ --help ] show this help message
448 -V [ --version ] show version information
449 --color use VT100 color codes even when stdout is not a
451 -D [ --define ] arg define a constant
452 -l [ --library ] arg load a library
453 -I [ --include ] arg add include search directory
454 -x [ --log-level ] arg specify the log level for the console log
458 Report bugs at <https://dev.icinga.org/>
459 Icinga home page: <https://www.icinga.org/>
462 ## <a id="features"></a> Enabling/Disabling Features
464 Icinga 2 provides configuration files for some commonly used features. These
465 are installed in the `/etc/icinga2/features-available` directory and can be
466 enabled and disabled using the `icinga2 feature enable` and `icinga2 feature disable`
467 [CLI commands](8-cli-commands.md#cli-command-feature), respectively.
469 The `icinga2 feature enable` CLI command creates symlinks in the
470 `/etc/icinga2/features-enabled` directory which is included by default
471 in the example configuration file.
473 You can view a list of enabled and disabled features:
475 # icinga2 feature list
476 Disabled features: api command compatlog debuglog graphite icingastatus ido-mysql ido-pgsql livestatus notification perfdata statusdata syslog
477 Enabled features: checker mainlog notification
479 Using the `icinga2 feature enable` command you can enable features:
481 # icinga2 feature enable graphite
482 Enabling feature graphite. Make sure to restart Icinga 2 for these changes to take effect.
485 You can disable features using the `icinga2 feature disable` command:
487 # icinga2 feature disable ido-mysql livestatus
488 Disabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect.
489 Disabling feature livestatus. Make sure to restart Icinga 2 for these changes to take effect.
492 The `icinga2 feature enable` and `icinga2 feature disable` commands do not
493 restart Icinga 2. You will need to restart Icinga 2 using the init script
494 after enabling or disabling features.
498 ## <a id="config-validation"></a> Configuration Validation
500 Once you've edited the configuration files make sure to tell Icinga 2 to validate
501 the configuration changes. Icinga 2 will log any configuration error including
502 a hint on the file, the line number and the affected configuration line itself.
504 The following example creates an apply rule without any `assign` condition.
506 apply Service "5872-ping4" {
507 import "generic-service"
508 check_command = "ping4"
509 //assign where match("5872-*", host.name)
512 Validate the configuration with the init script option `checkconfig`:
514 # /etc/init.d/icinga2 checkconfig
518 > Using [systemd](2-getting-started.md#systemd-service) you need to manually validate the configuration using
519 > the CLI command below.
521 Or manually passing the `-C` argument:
523 # /usr/sbin/icinga2 daemon -c /etc/icinga2/icinga2.conf -C
525 [2014-05-22 17:07:25 +0200] critical/ConfigItem: Location:
526 /etc/icinga2/conf.d/tests/5872.conf(5): }
527 /etc/icinga2/conf.d/tests/5872.conf(6):
528 /etc/icinga2/conf.d/tests/5872.conf(7): apply Service "5872-ping4" {
530 /etc/icinga2/conf.d/tests/5872.conf(8): import "test-generic-service"
531 /etc/icinga2/conf.d/tests/5872.conf(9): check_command = "ping4"
533 Config error: 'apply' is missing 'assign'
534 [2014-05-22 17:07:25 +0200] critical/ConfigItem: 1 errors, 0 warnings.
535 Icinga 2 detected configuration errors.
539 > Icinga 2 will automatically detect the default path for `icinga2.conf`
540 > in `SysconfDir + /icinga2/icinga2.conf` and you can safely omit this parameter.
542 > `# icinga2 daemon -C`
544 If you encouter errors during configuration validation, please make sure
545 to read the [troubleshooting](16-troubleshooting.md#troubleshooting) chapter.
547 You can also use the [CLI command](8-cli-commands.md#cli-command-object) `icinga2 object list`
548 after validation passes to analyze object attributes, inheritance or created
549 objects by apply rules.
550 Find more on troubleshooting with `object list` in [this chapter](16-troubleshooting.md#list-configuration-objects).
552 Example filtered by `Service` objects with the name `ping*`:
554 # icinga2 object list --type Service --name *ping*
555 Object 'nbmif.int.netways.de!ping4' of type 'Service':
556 * __name = 'nbmif.int.netways.de!ping4'
557 * check_command = 'ping4'
558 % = modified in '/etc/icinga2/conf.d/services.conf', lines 17:3-17:25
559 * check_interval = 60
560 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 28:3-28:21
561 * host_name = 'nbmif.int.netways.de'
562 % = modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
563 * max_check_attempts = 3
564 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 27:3-27:24
566 % = modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
567 * retry_interval = 30
568 % = modified in '/etc/icinga2/conf.d/templates.conf', lines 29:3-29:22
569 * templates = [ 'ping4', 'generic-service' ]
570 % += modified in '/etc/icinga2/conf.d/services.conf', lines 14:1-14:21
571 % += modified in '/etc/icinga2/conf.d/templates.conf', lines 26:1-30:1
574 % += modified in '/etc/icinga2/conf.d/services.conf', lines 18:3-18:19
576 % = modified in '/etc/icinga2/conf.d/services.conf', lines 18:3-18:19
580 ## <a id="config-change-reload"></a> Reload on Configuration Changes
582 Everytime you have changed your configuration you should first tell Icinga 2
583 to [validate](8-cli-commands.md#config-validation). If there are no validation errors you can
584 safely reload the Icinga 2 daemon.
586 # /etc/init.d/icinga2 reload
590 > The `reload` action will send the `SIGHUP` signal to the Icinga 2 daemon
591 > which will validate the configuration in a separate process and not stop
592 > the other events like check execution, notifications, etc.
594 > Details can be found [here](18-migrating-from-icinga-1x.md#differences-1x-2-real-reload).