]> granicus.if.org Git - icinga2/blob - doc/4-configuring-icinga-2.md
Update documentation
[icinga2] / doc / 4-configuring-icinga-2.md
1 # <a id="configuring-icinga2-first-steps"></a> Configuring Icinga 2: First Steps
2
3 ## <a id="icinga2-conf"></a> icinga2.conf
4
5 An example configuration file is installed for you in `/etc/icinga2/icinga2.conf`.
6
7 Here's a brief description of the example configuration:
8
9     /**
10      * Icinga 2 configuration file
11      * - this is where you define settings for the Icinga application including
12      * which hosts/services to check.
13      *
14      * For an overview of all available configuration options please refer
15      * to the documentation that is distributed as part of Icinga 2.
16      */
17
18 Icinga 2 supports [C/C++-style comments](13-language-reference.md#comments).
19
20     /**
21      * The constants.conf defines global constants.
22      */
23     include "constants.conf"
24
25 The `include` directive can be used to include other files.
26
27     /**
28      * The zones.conf defines zones for a cluster setup.
29      * Not required for single instance setups.
30      */
31      include "zones.conf"
32
33     /**
34      * The Icinga Template Library (ITL) provides a number of useful templates
35      * and command definitions.
36      * Common monitoring plugin command definitions are included separately.
37      */
38     include <itl>
39     include <plugins>
40
41     /**
42      * The features-available directory contains a number of configuration
43      * files for features which can be enabled and disabled using the
44      * icinga2 feature enable / icinga2 feature disable CLI commands.
45      * These commands work by creating and removing symbolic links in
46      * the features-enabled directory.
47      */
48     include "features-enabled/*.conf"
49
50 This `include` directive takes care of including the configuration files for all
51 the features which have been enabled with `icinga2 feature enable`. See
52 [Enabling/Disabling Features](6-cli-commands.md#features) for more details.
53
54     /**
55      * The repository.d directory contains all configuration objects
56      * managed by the 'icinga2 repository' CLI commands.
57      */
58     include_recursive "repository.d"
59
60 This `include_recursive` directive is used for discovery of services on remote clients
61 and their generated configuration described in
62 [this chapter](5-monitoring-remote-systems.md#icinga2-remote-monitoring-master-discovery-generate-config).
63
64
65     /**
66      * Although in theory you could define all your objects in this file
67      * the preferred way is to create separate directories and files in the conf.d
68      * directory. Each of these files must have the file extension ".conf".
69      */
70     include_recursive "conf.d"
71
72 You can put your own configuration files in the [conf.d](4-configuring-icinga-2.md#conf-d) directory. This
73 directive makes sure that all of your own configuration files are included.
74
75 > **Tip**
76 >
77 > The example configuration is shipped in this directory too. You can either
78 > remove it entirely, or adapt the existing configuration structure with your
79 > own object configuration.
80
81 ## <a id="constants-conf"></a> constants.conf
82
83 The `constants.conf` configuration file can be used to define global constants.
84
85 By default, you need to make sure to set these constants:
86
87 * The `PluginDir` constant must be pointed to your [check plugins](2-getting-started.md#setting-up-check-plugins) path.
88 This constant is required by the shipped
89 [plugin check command configuration](16-icinga-template-library.md#plugin-check-commands).
90 * The `NodeName` constant defines your local node name. Should be set to FQDN which is the default
91 if not set. This constant is required for local host configuration, monitoring remote clients and
92 cluster setup.
93
94 Example:
95
96     /* The directory which contains the plugins from the Monitoring Plugins project. */
97     const PluginDir = "/usr/lib64/nagios/plugins"
98
99
100     /* The directory which contains the Manubulon plugins.
101      * Check the documentation, chapter "SNMP Manubulon Plugin Check Commands", for details.
102      */
103     const ManubulonPluginDir = "/usr/lib64/nagios/plugins"
104
105     /* Our local instance name. By default this is the server's hostname as returned by `hostname --fqdn`.
106      * This should be the common name from the API certificate.
107      */
108     //const NodeName = "localhost"
109
110     /* Our local zone name. */
111     const ZoneName = NodeName
112
113     /* Secret key for remote node tickets */
114     const TicketSalt = ""
115
116 The `ZoneName` and `TicketSalt` constants are required for remote client
117 and distributed setups only.
118
119 ## <a id="conf-d"></a> The conf.d Directory
120
121 This directory contains example configuration which should help you get started
122 with monitoring the local host and its services. It is included in the
123 [icinga2.conf](4-configuring-icinga-2.md#icinga2-conf) configuration file by default.
124
125 It can be used as reference example for your own configuration strategy.
126 Just keep in mind to include the main directories in the
127 [icinga2.conf](4-configuring-icinga-2.md#icinga2-conf) file.
128
129 You are certainly not bound to it. Remove it, if you prefer your own
130 way of deploying Icinga 2 configuration.
131
132 Further details on configuration best practice and how to build your
133 own strategy is described in [this chapter](3-monitoring-basics.md#configuration-best-practice).
134
135 Available configuration files shipped by default:
136
137 * [hosts.conf](4-configuring-icinga-2.md#hosts-conf)
138 * [services.conf](4-configuring-icinga-2.md#services-conf)
139 * [users.conf](4-configuring-icinga-2.md#users-conf)
140 * [notifications.conf](4-configuring-icinga-2.md#notifications-conf)
141 * [commands.conf](4-configuring-icinga-2.md#commands-conf)
142 * [groups.conf](4-configuring-icinga-2.md#groups-conf)
143 * [templates.conf](4-configuring-icinga-2.md#templates-conf)
144 * [downtimes.conf](4-configuring-icinga-2.md#downtimes-conf)
145 * [timeperiods.conf](4-configuring-icinga-2.md#timeperiods-conf)
146 * [satellite.conf](4-configuring-icinga-2.md#satellite-conf)
147
148 ### <a id="hosts-conf"></a> hosts.conf
149
150 The `hosts.conf` file contains an example host based on your
151 `NodeName` setting in [constants.conf](4-configuring-icinga-2.md#constants-conf). You
152 can use global constants for your object names instead of string
153 values.
154
155 The `import` keyword is used to import the `generic-host` template which
156 takes care of setting up the host check command to `hostalive`. If you
157 require a different check command, you can override it in the object definition.
158
159 The `vars` attribute can be used to define custom attributes which are available
160 for check and notification commands. Most of the [Plugin Check Commands](16-icinga-template-library.md#plugin-check-commands)
161 in the Icinga Template Library require an `address` attribute.
162
163 The custom attribute `os` is evaluated by the `linux-servers` group in
164 [groups.conf](4-configuring-icinga-2.md#groups-conf) making the local host a member.
165
166 The example host will show you how to
167
168 * define http vhost attributes for the `http` service apply rule defined
169 in [services.conf](4-configuring-icinga-2.md#services-conf).
170 * define disks (all, specific `/`) and their attributes for the `disk`
171 service apply rule defined in [services.conf](4-configuring-icinga-2.md#services-conf).
172 * define notification types (`mail`) and set the groups attribute. This
173 will be used by notification apply rules in [notifications.conf](notifications-conf).
174
175 If you've installed [Icinga Web 2](2-getting-started.md#setting-up-icingaweb2) you can
176 uncomment the http vhost attributes and relaod Icinga 2. The apply
177 rules in [services.conf](4-configuring-icinga-2.md#services-conf) will automatically
178 generate a new service checking the `/icingaweb2` URI using the `http`
179 check.
180
181     /*
182      * Host definitions with object attributes
183      * used for apply rules for Service, Notification,
184      * Dependency and ScheduledDowntime objects.
185      *
186      * Tip: Use `icinga2 object list --type Host` to
187      * list all host objects after running
188      * configuration validation (`icinga2 daemon -C`).
189      */
190
191     /*
192      * This is an example host based on your
193      * local host's FQDN. Specify the NodeName
194      * constant in `constants.conf` or use your
195      * own description, e.g. "db-host-1".
196      */
197
198     object Host NodeName {
199       /* Import the default host template defined in `templates.conf`. */
200       import "generic-host"
201
202       /* Specify the address attributes for checks e.g. `ssh` or `http`. */
203       address = "127.0.0.1"
204       address6 = "::1"
205
206       /* Set custom attribute `os` for hostgroup assignment in `groups.conf`. */
207       vars.os = "Linux"
208
209       /* Define http vhost attributes for service apply rules in `services.conf`. */
210       vars.http_vhosts["http"] = {
211         http_uri = "/"
212       }
213       /* Uncomment if you've sucessfully installed Icinga Web 2. */
214       //vars.http_vhosts["Icinga Web 2"] = {
215       //  http_uri = "/icingaweb2"
216       //}
217
218       /* Define disks and attributes for service apply rules in `services.conf`. */
219       vars.disks["disk"] = {
220         /* No parameters. */
221       }
222       vars.disks["disk /"] = {
223         disk_partitions = "/"
224       }
225
226       /* Define notification mail attributes for notification apply rules in `notifications.conf`. */
227       vars.notification["mail"] = {
228         /* The UserGroup `icingaadmins` is defined in `users.conf`. */
229         groups = [ "icingaadmins" ]
230       }
231     }
232
233 This is only the host object definition. Now we'll need to make sure that this
234 host and your additional hosts are getting [services](4-configuring-icinga-2.md#services-conf) applied.
235
236 > **Tip**
237 >
238 > If you don't understand all the attributes and how to use [apply rules](13-language-reference.md#apply)
239 > don't worry - the [monitoring basics](3-monitoring-basics.md#monitoring-basics) chapter will explain
240 > that in detail.
241
242 ### <a id="services-conf"></a> services.conf
243
244 These service [apply rules](13-language-reference.md#apply) will show you how to monitor
245 the local host, but also allow you to re-use or modify them for
246 your own requirements.
247
248 You should define all your service apply rules in `services.conf`
249 or any other central location keeping them organized.
250
251 By default, the local host will be monitored by the following services
252
253 Service(s)                                  | Applied on host(s)
254 --------------------------------------------|------------------------
255 `load`, `procs`, `swap`, `users`, `icinga`  | The `NodeName` host only
256 `ping4`, `ping6`                            | All hosts with `address` resp. `address6` attribute
257 `ssh`                                       | All hosts with `address` and `vars.os` set to `Linux`
258 `http`, optional: `Icinga Web 2`            | All hosts with custom attribute `http_vhosts` defined as dictionary
259 `disk`, `disk /`                            | All hosts with custom attribute `disks` defined as dictionary
260
261 The Debian packages also ship an additional `apt` service check applied to the local host.
262
263 The command object `icinga` for the embedded health check is provided by the
264 [Icinga Template Library (ITL)](16-icinga-template-library.md#icinga-template-library) while `http_ip`, `ssh`, `load`, `processes`,
265 `users` and `disk` are all provided by the [Plugin Check Commands](16-icinga-template-library.md#plugin-check-commands)
266 which we enabled earlier by including the `itl` and `plugins` configuration file.
267
268
269 Example `load` service apply rule:
270
271     apply Service "load" {
272       import "generic-service"
273
274       check_command = "load"
275
276       /* Used by the ScheduledDowntime apply rule in `downtimes.conf`. */
277       vars.backup_downtime = "02:00-03:00"
278
279       assign where host.name == NodeName
280     }
281
282 The `apply` keyword can be used to create new objects which are associated with
283 another group of objects. You can `import` existing templates, define (custom)
284 attributes.
285
286 The custom attribe `backup_downtime` is defined to a specific timerange string.
287 This variable value will be used for applying a `ScheduledDowntime` object to
288 these services in [downtimes.conf](4-configuring-icinga-2.md#downtimes-conf).
289
290 In this example the `assign where` condition is a boolean expression which is
291 evaluated for all objects of type `Host` and a new service with name "load"
292 is created for each matching host. [Expression operators](13-language-reference.md#expression-operators)
293 may be used in `assign where` conditions.
294
295 Multiple `assign where` condition can be combined with `AND` using the `&&` operator
296 as shown in the `ssh` example:
297
298     apply Service "ssh" {
299       import "generic-service"
300
301       check_command = "ssh"
302
303       assign where host.address && host.vars.os == "Linux"
304     }
305
306 In this example, the service `ssh` is applied to all hosts having the `address`
307 attribute defined `AND` having the custom attribute `os` set to the string
308 `Linux`.
309 You can modify this condition to match multiple expressions by combinding `AND`
310 and `OR` using `&&` and `||` [operators](13-language-reference.md#expression-operators), for example
311 `assign where host.address && (vars.os == "Linux" || vars.os == "Windows")`.
312
313
314 A more advanced example is shown by the `http` and `disk` service apply
315 rules. While one `apply` rule for `ssh` will only create a service for matching
316 hosts, you can go one step further: Generate apply rules based on array items
317 or dictionary key-value pairs.
318
319 The idea is simple: Your host in [hosts.conf](4-configuring-icinga-2.md#hosts-conf) defines the
320 `disks` dictionary as custom attribute in `vars`.
321
322 Remember the example from [hosts.conf](4-configuring-icinga-2.md#hosts-conf):
323
324     ...
325
326       /* Define disks and attributes for service apply rules in `services.conf`. */
327       vars.disks["disk"] = {
328         /* No parameters. */
329       }
330       vars.disks["disk /"] = {
331         disk_partition = "/"
332       }
333     ...
334
335
336 This dictionary contains multiple service names we want to monitor. `disk`
337 should just check all available disks, while `disk /` will pass an additional
338 parameter `disk_partition` to the check command.
339
340 You'll recognize that the naming is important - that's the very same name
341 as it is passed from a service to a check command argument. Read about services
342 and passing check commands in [this chapter](3-monitoring-basics.md#command-passing-parameters).
343
344 Using `apply Service for` omits the service name, it will take the key stored in
345 the `disk` variable in `key => config` as new service object name.
346
347 The `for` keyword expects a loop definition, for example `key => value in dictionary`
348 as known from Perl and other scripting languages.
349
350 Once defined like this, the `apply` rule defined below will do the following:
351
352 * only match hosts with `host.vars.disks` defined through the `assign where` condition
353 * loop through all entries in the `host.vars.disks` dictionary. That's `disk` and `disk /` as keys.
354 * call `apply` on each, and set the service object name from the provided key
355 * inside apply, the `generic-service` template is imported
356 * defining the [disk](16-icinga-template-library.md#plugin-check-command-disk) check command requiring command arguments like `disk_partition`
357 * adding the `config` dictionary items to `vars`. Simply said, there's now `vars.disk_partition` defined for the
358 generated service
359
360 Configuration example:
361
362     apply Service for (disk => config in host.vars.disks) {
363       import "generic-service"
364
365       check_command = "disk"
366
367       vars += config
368
369       assign where host.vars.disks
370     }
371
372 A similar example is used for the `http` services. That way you can make your
373 host the information provider for all apply rules. Define them once, and only
374 manage your hosts.
375
376 Look into [notifications.conf](4-configuring-icinga-2.md#notifications-conf) how this technique is used
377 for applying notifications to hosts and services using their type and user
378 attributes.
379
380 Don't forget to install the [check plugins](2-getting-started.md#setting-up-check-plugins) required by
381 the hosts and services and their check commands.
382
383 Further details on the monitoring configuration can be found in the
384 [monitoring basics](3-monitoring-basics.md#monitoring-basics) chapter.
385
386 ### <a id="users-conf"></a> users.conf
387
388 Defines the `icingaadmin` User and the `icingaadmins` UserGroup. The latter is used in
389 [hosts.conf](4-configuring-icinga-2.md#hosts-conf) for defining a custom host attribute later used in
390 [notifications.conf](4-configuring-icinga-2.md#notifications-conf) for notification apply rules.
391
392     object User "icingaadmin" {
393       import "generic-user"
394
395       display_name = "Icinga 2 Admin"
396       groups = [ "icingaadmins" ]
397
398       email = "icinga@localhost"
399     }
400
401     object UserGroup "icingaadmins" {
402       display_name = "Icinga 2 Admin Group"
403     }
404
405
406 ### <a id="notifications-conf"></a> notifications.conf
407
408 Notifications for check alerts are an integral part or your
409 Icinga 2 monitoring stack.
410
411 The shipped example defines two notification apply rules for hosts and services.
412 Both `apply` rules match on the same condition: They are only applied if the
413 nested dictionary attribute `notification.mail` is set.
414
415 Please note that the `to` keyword is important in [notification apply rules](3-monitoring-basics.md#using-apply-notifications)
416 defining whether these notifications are applies to hosts or services.
417 The `import` keyword imports the specific mail templates defined in [templates.conf](4-configuring-icinga-2.md#templates-conf).
418
419 The `interval` attribute is not explicitly set - it [defaults to 30 minutes](15-object-types.md#objecttype-notification).
420
421 By setting the `user_groups` to the value provided by the
422 respective [host.vars.notification.mail](4-configuring-icinga-2.md#hosts-conf) attribute we'll
423 implicitely use the`icingaadmins` UserGroup defined in [users.conf](4-configuring-icinga-2.md#users-conf).
424
425     apply Notification "mail-icingaadmin" to Host {
426       import "mail-host-notification"
427
428       user_groups = host.vars.notification.mail.groups
429
430       assign where host.vars.notification.mail
431     }
432
433     apply Notification "mail-icingaadmin" to Service {
434       import "mail-service-notification"
435
436       user_groups = host.vars.notification.mail.groups
437
438       assign where host.vars.notification.mail
439     }
440
441 More details on defining notifications and their additional attributes such as
442 filters can be read in [this chapter](3-monitoring-basics.md#notifications).
443
444 ### <a id="commands-conf"></a> commands.conf
445
446 This is the place where your own command configuration can be defined. By default
447 only the notification commands used by the notification templates defined in [templates.conf](4-configuring-icinga-2.md#templates-conf).
448
449 > **Tip**
450 >
451 > Icinga 2 ships the most common command definitions already in the
452 > [Plugin Check Commands](16-icinga-template-library.md#plugin-check-commands) definitions. More details on
453 > that topic in the [troubleshooting section](10-troubleshooting.md#check-command-definitions).
454
455 You can freely customize these notification commands, and adapt them for your needs.
456 Read more on that topic [here](3-monitoring-basics.md#notification-commands).
457
458 ### <a id="groups-conf"></a> groups.conf
459
460 The example host defined in [hosts.conf](hosts-conf) already has the
461 custom attribute `os` set to `Linux` and is therefore automatically
462 a member of the host group `linux-servers`.
463
464 This is done by using the [group assign](13-language-reference.md#group-assign) expressions similar
465 to previously seen [apply rules](3-monitoring-basics.md#using-apply).
466
467     object HostGroup "linux-servers" {
468       display_name = "Linux Servers"
469
470       assign where host.vars.os == "Linux"
471     }
472
473     object HostGroup "windows-servers" {
474       display_name = "Windows Servers"
475
476       assign where host.vars.os == "Windows"
477     }
478
479 Service groups can be grouped together by similar pattern matches.
480 The [match() function](13-language-reference.md#function-calls) expects a wildcard match string
481 and the attribute string to match with.
482
483     object ServiceGroup "ping" {
484       display_name = "Ping Checks"
485
486       assign where match("ping*", service.name)
487     }
488
489     object ServiceGroup "http" {
490       display_name = "HTTP Checks"
491
492       assign where match("http*", service.check_command)
493     }
494
495     object ServiceGroup "disk" {
496       display_name = "Disk Checks"
497
498       assign where match("disk*", service.check_command)
499     }
500
501
502 ### <a id="templates-conf"></a> templates.conf
503
504 All shipped example configuration objects use generic global templates by
505 default. Be it setting a default `check_command` attribute in the `generic-host`
506 templates for your hosts defined in [hosts.conf](4-configuring-icinga-2.md#hosts-conf), or defining
507 the default `states` and `types` filters for notification apply rules defined in
508 [notifications.conf](4-configuring-icinga-2.md#notifications-conf).
509
510
511     template Host "generic-host" {
512       max_check_attempts = 5
513       check_interval = 1m
514       retry_interval = 30s
515
516       check_command = "hostalive"
517     }
518
519     template Service "generic-service" {
520       max_check_attempts = 3
521       check_interval = 1m
522       retry_interval = 30s
523     }
524
525 The `hostalive` check command is shipped with Icinga 2 in the
526 [Plugin Check Commands](16-icinga-template-library.md#plugin-check-commands).
527
528
529     template Notification "mail-host-notification" {
530       command = "mail-host-notification"
531
532       states = [ Up, Down ]
533       types = [ Problem, Acknowledgement, Recovery, Custom,
534                 FlappingStart, FlappingEnd,
535                 DowntimeStart, DowntimeEnd, DowntimeRemoved ]
536
537       period = "24x7"
538     }
539
540     template Notification "mail-service-notification" {
541       command = "mail-service-notification"
542
543       states = [ OK, Warning, Critical, Unknown ]
544       types = [ Problem, Acknowledgement, Recovery, Custom,
545                 FlappingStart, FlappingEnd,
546                 DowntimeStart, DowntimeEnd, DowntimeRemoved ]
547
548       period = "24x7"
549     }
550
551 More details on `Notification` object attributes can be found [here](15-object-types.md#objecttype-notification).
552
553
554 ### <a id="downtimes-conf"></a> downtimes.conf
555
556 The `load` service apply rule defined in [services.conf](4-configuring-icinga-2.md#services-conf) defines
557 the `backup_downtime` custom attribute.
558
559 The [ScheduledDowntime](15-object-types.md#objecttype-scheduleddowntime) apply rule uses this attribute
560 to define the default value for the time ranges required for recurring downtime slots.
561
562     apply ScheduledDowntime "backup-downtime" to Service {
563       author = "icingaadmin"
564       comment = "Scheduled downtime for backup"
565
566       ranges = {
567         monday = service.vars.backup_downtime
568         tuesday = service.vars.backup_downtime
569         wednesday = service.vars.backup_downtime
570         thursday = service.vars.backup_downtime
571         friday = service.vars.backup_downtime
572         saturday = service.vars.backup_downtime
573         sunday = service.vars.backup_downtime
574       }
575
576       assign where service.vars.backup_downtime != ""
577     }
578
579
580 ### <a id="timeperiods-conf"></a> timeperiods.conf
581
582 This file ships the default timeperiod definitions for `24x7`, `9to5`
583 and `never`. Timeperiod objects are referenced by `*period`
584 objects such as hosts, services or notifications.
585
586
587 ### <a id="satellite-conf"></a> satellite.conf
588
589 Ships default templates and dependencies for [monitoring remote clients](5-monitoring-remote-systems.md#icinga2-remote-client-monitoring)
590 using service discovery and [config generation](5-monitoring-remote-systems.md#icinga2-remote-monitoring-master-discovery-generate-config)
591 on the master. Can be ignored/removed on setups not using this features.
592
593
594 Further details on the monitoring configuration can be found in the
595 [monitoring basics](3-monitoring-basics.md#monitoring-basics) chapter.