]> granicus.if.org Git - icinga2/blob - doc/14-features.md
Unify documentation code formatting
[icinga2] / doc / 14-features.md
1 # Icinga 2 Features <a id="icinga2-features"></a>
2
3 ## Logging <a id="logging"></a>
4
5 Icinga 2 supports three different types of logging:
6
7 * File logging
8 * Syslog (on Linux/UNIX)
9 * Console logging (`STDOUT` on tty)
10
11 You can enable additional loggers using the `icinga2 feature enable`
12 and `icinga2 feature disable` commands to configure loggers:
13
14 Feature  | Description
15 ---------|------------
16 debuglog | Debug log (path: `/var/log/icinga2/debug.log`, severity: `debug` or higher)
17 mainlog  | Main log (path: `/var/log/icinga2/icinga2.log`, severity: `information` or higher)
18 syslog   | Syslog (severity: `warning` or higher)
19
20 By default file the `mainlog` feature is enabled. When running Icinga 2
21 on a terminal log messages with severity `information` or higher are
22 written to the console.
23
24 Packages will install a configuration file for logrotate on supported
25 platforms. This configuration ensures that the `icinga2.log`, `error.log` and
26 `debug.log` files are rotated on a daily basis.
27
28 ## DB IDO <a id="db-ido"></a>
29
30 The IDO (Icinga Data Output) feature for Icinga 2 takes care of exporting all
31 configuration and status information into a database. The IDO database is used
32 by Icinga Web 2 as data backend.
33
34 Details on the installation can be found in the [Configuring DB IDO](02-getting-started.md#configuring-db-ido-mysql)
35 chapter. Details on the configuration can be found in the
36 [IdoMysqlConnection](09-object-types.md#objecttype-idomysqlconnection) and
37 [IdoPgsqlConnection](09-object-types.md#objecttype-idopgsqlconnection)
38 object configuration documentation.
39 The DB IDO feature supports [High Availability](06-distributed-monitoring.md#distributed-monitoring-high-availability-db-ido) in
40 the Icinga 2 cluster.
41
42 ### DB IDO Health <a id="db-ido-health"></a>
43
44 If the monitoring health indicator is critical in Icinga Web 2,
45 you can use the following queries to manually check whether Icinga 2
46 is actually updating the IDO database.
47
48 Icinga 2 writes its current status to the `icinga_programstatus` table
49 every 10 seconds. The query below checks 60 seconds into the past which is a reasonable
50 amount of time -- adjust it for your requirements. If the condition is not met,
51 the query returns an empty result.
52
53 > **Tip**
54 >
55 > Use [check plugins](05-service-monitoring.md#service-monitoring-plugins) to monitor the backend.
56
57 Replace the `default` string with your instance name if different.
58
59 Example for MySQL:
60
61 ```
62 # mysql -u root -p icinga -e "SELECT status_update_time FROM icinga_programstatus ps
63   JOIN icinga_instances i ON ps.instance_id=i.instance_id
64   WHERE (UNIX_TIMESTAMP(ps.status_update_time) > UNIX_TIMESTAMP(NOW())-60)
65   AND i.instance_name='default';"
66
67 +---------------------+
68 | status_update_time  |
69 +---------------------+
70 | 2014-05-29 14:29:56 |
71 +---------------------+
72 ```
73
74 Example for PostgreSQL:
75
76 ```
77 # export PGPASSWORD=icinga; psql -U icinga -d icinga -c "SELECT ps.status_update_time FROM icinga_programstatus AS ps
78   JOIN icinga_instances AS i ON ps.instance_id=i.instance_id
79   WHERE ((SELECT extract(epoch from status_update_time) FROM icinga_programstatus) > (SELECT extract(epoch from now())-60))
80   AND i.instance_name='default'";
81
82 status_update_time
83 ------------------------
84  2014-05-29 15:11:38+02
85 (1 Zeile)
86 ```
87
88 A detailed list on the available table attributes can be found in the [DB IDO Schema documentation](24-appendix.md#schema-db-ido).
89
90 ### DB IDO Cleanup <a id="db-ido-cleanup"></a>
91
92 Objects get deactivated when they are deleted from the configuration.
93 This is visible with the `is_active` column in the `icinga_objects` table.
94 Therefore all queries need to join this table and add `WHERE is_active=1` as
95 condition. Deleted objects preserve their history table entries for later SLA
96 reporting.
97
98 Historical data isn't purged by default. You can enable the least
99 kept data age inside the `cleanup` configuration attribute for the
100 IDO features [IdoMysqlConnection](09-object-types.md#objecttype-idomysqlconnection)
101 and [IdoPgsqlConnection](09-object-types.md#objecttype-idopgsqlconnection).
102
103 Example if you prefer to keep notification history for 30 days:
104
105 ```
106   cleanup = {
107      notifications_age = 30d
108      contactnotifications_age = 30d
109   }
110 ```
111
112 The historical tables are populated depending on the data `categories` specified.
113 Some tables are empty by default.
114
115 ### DB IDO Tuning <a id="db-ido-tuning"></a>
116
117 As with any application database, there are ways to optimize and tune the database performance.
118
119 General tips for performance tuning:
120
121 * [MariaDB KB](https://mariadb.com/kb/en/library/optimization-and-tuning/)
122 * [PostgreSQL Wiki](https://wiki.postgresql.org/wiki/Performance_Optimization)
123
124 Re-creation of indexes, changed column values, etc. will increase the database size. Ensure to
125 add health checks for this, and monitor the trend in your Grafana dashboards.
126
127 In order to optimize the tables, there are different approaches. Always keep in mind to have a
128 current backup and schedule maintenance downtime for these kind of tasks!
129
130 MySQL:
131
132 ```
133 mariadb> OPTIMIZE TABLE icinga_statehistory;
134 ```
135
136 > **Important**
137 >
138 > Tables might not support optimization at runtime. This can take a **long** time.
139 >
140 > `Table does not support optimize, doing recreate + analyze instead`.
141
142 If you want to optimize all tables in a specified database, there is a script called `mysqlcheck`.
143 This also allows to repair broken tables in the case of emergency.
144
145 ```
146 mysqlcheck --optimize icinga
147 ```
148
149 PostgreSQL:
150
151 ```
152 icinga=# vacuum;
153 VACUUM
154 ```
155
156 > **Note**
157 >
158 > Don't use `VACUUM FULL` as this has a severe impact on performance.
159
160
161 ## External Commands <a id="external-commands"></a>
162
163 > **Note**
164 >
165 > Please use the [REST API](12-icinga2-api.md#icinga2-api) as modern and secure alternative
166 > for external actions.
167
168 Icinga 2 provides an external command pipe for processing commands
169 triggering specific actions (for example rescheduling a service check
170 through the web interface).
171
172 In order to enable the `ExternalCommandListener` configuration use the
173 following command and restart Icinga 2 afterwards:
174
175 ```
176 # icinga2 feature enable command
177 ```
178
179 Icinga 2 creates the command pipe file as `/var/run/icinga2/cmd/icinga2.cmd`
180 using the default configuration.
181
182 Web interfaces and other Icinga addons are able to send commands to
183 Icinga 2 through the external command pipe, for example for rescheduling
184 a forced service check:
185
186 ```
187 # /bin/echo "[`date +%s`] SCHEDULE_FORCED_SVC_CHECK;localhost;ping4;`date +%s`" >> /var/run/icinga2/cmd/icinga2.cmd
188
189 # tail -f /var/log/messages
190
191 Oct 17 15:01:25 icinga-server icinga2: Executing external command: [1382014885] SCHEDULE_FORCED_SVC_CHECK;localhost;ping4;1382014885
192 Oct 17 15:01:25 icinga-server icinga2: Rescheduling next check for service 'ping4'
193 ```
194
195 A list of currently supported external commands can be found [here](24-appendix.md#external-commands-list-detail).
196
197 Detailed information on the commands and their required parameters can be found
198 on the [Icinga 1.x documentation](https://docs.icinga.com/latest/en/extcommands2.html).
199
200 ## Performance Data <a id="performance-data"></a>
201
202 When a host or service check is executed plugins should provide so-called
203 `performance data`. Next to that additional check performance data
204 can be fetched using Icinga 2 runtime macros such as the check latency
205 or the current service state (or additional custom attributes).
206
207 The performance data can be passed to external applications which aggregate and
208 store them in their backends. These tools usually generate graphs for historical
209 reporting and trending.
210
211 Well-known addons processing Icinga performance data are [PNP4Nagios](13-addons.md#addons-graphing-pnp),
212 [Graphite](13-addons.md#addons-graphing-graphite) or [OpenTSDB](14-features.md#opentsdb-writer).
213
214 ### Writing Performance Data Files <a id="writing-performance-data-files"></a>
215
216 PNP4Nagios and Graphios use performance data collector daemons to fetch
217 the current performance files for their backend updates.
218
219 Therefore the Icinga 2 [PerfdataWriter](09-object-types.md#objecttype-perfdatawriter)
220 feature allows you to define the output template format for host and services helped
221 with Icinga 2 runtime vars.
222
223 ```
224 host_format_template = "DATATYPE::HOSTPERFDATA\tTIMET::$icinga.timet$\tHOSTNAME::$host.name$\tHOSTPERFDATA::$host.perfdata$\tHOSTCHECKCOMMAND::$host.check_command$\tHOSTSTATE::$host.state$\tHOSTSTATETYPE::$host.state_type$"
225 service_format_template = "DATATYPE::SERVICEPERFDATA\tTIMET::$icinga.timet$\tHOSTNAME::$host.name$\tSERVICEDESC::$service.name$\tSERVICEPERFDATA::$service.perfdata$\tSERVICECHECKCOMMAND::$service.check_command$\tHOSTSTATE::$host.state$\tHOSTSTATETYPE::$host.state_type$\tSERVICESTATE::$service.state$\tSERVICESTATETYPE::$service.state_type$"
226 ```
227
228 The default templates are already provided with the Icinga 2 feature configuration
229 which can be enabled using
230
231 ```
232 # icinga2 feature enable perfdata
233 ```
234
235 By default all performance data files are rotated in a 15 seconds interval into
236 the `/var/spool/icinga2/perfdata/` directory as `host-perfdata.<timestamp>` and
237 `service-perfdata.<timestamp>`.
238 External collectors need to parse the rotated performance data files and then
239 remove the processed files.
240
241 ### Graphite Carbon Cache Writer <a id="graphite-carbon-cache-writer"></a>
242
243 While there are some [Graphite](13-addons.md#addons-graphing-graphite)
244 collector scripts and daemons like Graphios available for Icinga 1.x it's more
245 reasonable to directly process the check and plugin performance
246 in memory in Icinga 2. Once there are new metrics available, Icinga 2 will directly
247 write them to the defined Graphite Carbon daemon tcp socket.
248
249 You can enable the feature using
250
251 ```
252 # icinga2 feature enable graphite
253 ```
254
255 By default the [GraphiteWriter](09-object-types.md#objecttype-graphitewriter) feature
256 expects the Graphite Carbon Cache to listen at `127.0.0.1` on TCP port `2003`.
257
258 #### Current Graphite Schema <a id="graphite-carbon-cache-writer-schema"></a>
259
260 The current naming schema is defined as follows. The [Icinga Web 2 Graphite module](https://github.com/icinga/icingaweb2-module-graphite)
261 depends on this schema.
262
263 The default prefix for hosts and services is configured using
264 [runtime macros](03-monitoring-basics.md#runtime-macros)like this:
265
266 ```
267 icinga2.$host.name$.host.$host.check_command$
268 icinga2.$host.name$.services.$service.name$.$service.check_command$
269 ```
270
271 You can customize the prefix name by using the `host_name_template` and
272 `service_name_template` configuration attributes.
273
274 The additional levels will allow fine granular filters and also template
275 capabilities, e.g. by using the check command `disk` for specific
276 graph templates in web applications rendering the Graphite data.
277
278 The following characters are escaped in prefix labels:
279
280   Character     | Escaped character
281   --------------|--------------------------
282   whitespace    | _
283   .             | _
284   \             | _
285   /             | _
286
287 Metric values are stored like this:
288
289 ```
290 <prefix>.perfdata.<perfdata-label>.value
291 ```
292
293 The following characters are escaped in perfdata labels:
294
295   Character     | Escaped character
296   --------------|--------------------------
297   whitespace    | _
298   \             | _
299   /             | _
300   ::            | .
301
302 Note that perfdata labels may contain dots (`.`) allowing to
303 add more subsequent levels inside the Graphite tree.
304 `::` adds support for [multi performance labels](http://my-plugin.de/wiki/projects/check_multi/configuration/performance)
305 and is therefore replaced by `.`.
306
307 By enabling `enable_send_thresholds` Icinga 2 automatically adds the following threshold metrics:
308
309 ```
310 <prefix>.perfdata.<perfdata-label>.min
311 <prefix>.perfdata.<perfdata-label>.max
312 <prefix>.perfdata.<perfdata-label>.warn
313 <prefix>.perfdata.<perfdata-label>.crit
314 ```
315
316 By enabling `enable_send_metadata` Icinga 2 automatically adds the following metadata metrics:
317
318 ```
319 <prefix>.metadata.current_attempt
320 <prefix>.metadata.downtime_depth
321 <prefix>.metadata.acknowledgement
322 <prefix>.metadata.execution_time
323 <prefix>.metadata.latency
324 <prefix>.metadata.max_check_attempts
325 <prefix>.metadata.reachable
326 <prefix>.metadata.state
327 <prefix>.metadata.state_type
328 ```
329
330 Metadata metric overview:
331
332   metric             | description
333   -------------------|------------------------------------------
334   current_attempt    | current check attempt
335   max_check_attempts | maximum check attempts until the hard state is reached
336   reachable          | checked object is reachable
337   downtime_depth     | number of downtimes this object is in
338   acknowledgement    | whether the object is acknowledged or not
339   execution_time     | check execution time
340   latency            | check latency
341   state              | current state of the checked object
342   state_type         | 0=SOFT, 1=HARD state
343
344 The following example illustrates how to configure the storage schemas for Graphite Carbon
345 Cache.
346
347 ```
348 [icinga2_default]
349 # intervals like PNP4Nagios uses them per default
350 pattern = ^icinga2\.
351 retentions = 1m:2d,5m:10d,30m:90d,360m:4y
352 ```
353
354
355 ### InfluxDB Writer <a id="influxdb-writer"></a>
356
357 Once there are new metrics available, Icinga 2 will directly write them to the
358 defined InfluxDB HTTP API.
359
360 You can enable the feature using
361
362 ```
363 # icinga2 feature enable influxdb
364 ```
365
366 By default the [InfluxdbWriter](09-object-types.md#objecttype-influxdbwriter) feature
367 expects the InfluxDB daemon to listen at `127.0.0.1` on port `8086`.
368
369 Measurement names and tags are fully configurable by the end user. The InfluxdbWriter
370 object will automatically add a `metric` tag to each data point. This correlates to the
371 perfdata label. Fields (value, warn, crit, min, max, unit) are created from data if available
372 and the configuration allows it.  If a value associated with a tag is not able to be
373 resolved, it will be dropped and not sent to the target host.
374
375 Backslashes are allowed in tag keys, tag values and field keys, however they are also
376 escape characters when followed by a space or comma, but cannot be escaped themselves.
377 As a result all trailling slashes in these fields are replaced with an underscore.  This
378 predominantly affects Windows paths e.g. `C:\` becomes `C:_`.
379
380 The database is assumed to exist so this object will make no attempt to create it currently.
381
382 If [SELinux](22-selinux.md#selinux) is enabled, it will not allow access for Icinga 2 to InfluxDB until the [boolean](22-selinux.md#selinux-policy-booleans)
383 `icinga2_can_connect_all` is set to true as InfluxDB is not providing its own policy.
384
385 More configuration details can be found [here](09-object-types.md#objecttype-influxdbwriter).
386
387 #### Instance Tagging <a id="influxdb-writer-instance-tags"></a>
388
389 Consider the following service check:
390
391 ```
392 apply Service "disk" for (disk => attributes in host.vars.disks) {
393   import "generic-service"
394   check_command = "disk"
395   display_name = "Disk " + disk
396   vars.disk_partitions = disk
397   assign where host.vars.disks
398 }
399 ```
400
401 This is a typical pattern for checking individual disks, NICs, SSL certificates etc associated
402 with a host.  What would be useful is to have the data points tagged with the specific instance
403 for that check.  This would allow you to query time series data for a check on a host and for a
404 specific instance e.g. /dev/sda.  To do this quite simply add the instance to the service variables:
405
406 ```
407 apply Service "disk" for (disk => attributes in host.vars.disks) {
408   ...
409   vars.instance = disk
410   ...
411 }
412 ```
413
414 Then modify your writer configuration to add this tag to your data points if the instance variable
415 is associated with the service:
416
417 ```
418 object InfluxdbWriter "influxdb" {
419   ...
420   service_template = {
421     measurement = "$service.check_command$"
422     tags = {
423       hostname = "$host.name$"
424       service = "$service.name$"
425       instance = "$service.vars.instance$"
426     }
427   }
428   ...
429 }
430 ```
431
432 ### Elastic Stack Integration <a id="elastic-stack-integration"></a>
433
434 [Icingabeat](https://github.com/icinga/icingabeat) is an Elastic Beat that fetches data
435 from the Icinga 2 API and sends it either directly to [Elasticsearch](https://www.elastic.co/products/elasticsearch)
436 or [Logstash](https://www.elastic.co/products/logstash).
437
438 More integrations:
439
440 * [Logstash output](https://github.com/Icinga/logstash-output-icinga) for the Icinga 2 API.
441 * [Logstash Grok Pattern](https://github.com/Icinga/logstash-grok-pattern) for Icinga 2 logs.
442
443 #### Elasticsearch Writer <a id="elasticsearch-writer"></a>
444
445 This feature forwards check results, state changes and notification events
446 to an [Elasticsearch](https://www.elastic.co/products/elasticsearch) installation over its HTTP API.
447
448 The check results include parsed performance data metrics if enabled.
449
450 > **Note**
451 >
452 > Elasticsearch 5.x or 6.x are required. This feature has been successfully tested with
453 > Elasticsearch 5.6.7 and 6.3.1.
454
455
456
457 Enable the feature and restart Icinga 2.
458
459 ```
460 # icinga2 feature enable elasticsearch
461 ```
462
463 The default configuration expects an Elasticsearch instance running on `localhost` on port `9200
464  and writes to an index called `icinga2`.
465
466 More configuration details can be found [here](09-object-types.md#objecttype-elasticsearchwriter).
467
468 #### Current Elasticsearch Schema <a id="elastic-writer-schema"></a>
469
470 The following event types are written to Elasticsearch:
471
472 * icinga2.event.checkresult
473 * icinga2.event.statechange
474 * icinga2.event.notification
475
476 Performance data metrics must be explicitly enabled with the `enable_send_perfdata`
477 attribute.
478
479 Metric values are stored like this:
480
481 ```
482 check_result.perfdata.<perfdata-label>.value
483 ```
484
485 The following characters are escaped in perfdata labels:
486
487   Character   | Escaped character
488   ------------|--------------------------
489   whitespace  | _
490   \           | _
491   /           | _
492   ::          | .
493
494 Note that perfdata labels may contain dots (`.`) allowing to
495 add more subsequent levels inside the tree.
496 `::` adds support for [multi performance labels](http://my-plugin.de/wiki/projects/check_multi/configuration/performance)
497 and is therefore replaced by `.`.
498
499 Icinga 2 automatically adds the following threshold metrics
500 if existing:
501
502 ```
503 check_result.perfdata.<perfdata-label>.min
504 check_result.perfdata.<perfdata-label>.max
505 check_result.perfdata.<perfdata-label>.warn
506 check_result.perfdata.<perfdata-label>.crit
507 ```
508
509 ### Graylog Integration <a id="graylog-integration"></a>
510
511 #### GELF Writer <a id="gelfwriter"></a>
512
513 The `Graylog Extended Log Format` (short: [GELF](http://docs.graylog.org/en/latest/pages/gelf.html))
514 can be used to send application logs directly to a TCP socket.
515
516 While it has been specified by the [Graylog](https://www.graylog.org) project as their
517 [input resource standard](http://docs.graylog.org/en/latest/pages/sending_data.html), other tools such as
518 [Logstash](https://www.elastic.co/products/logstash) also support `GELF` as
519 [input type](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-gelf.html).
520
521 You can enable the feature using
522
523 ```
524 # icinga2 feature enable gelf
525 ```
526
527 By default the `GelfWriter` object expects the GELF receiver to listen at `127.0.0.1` on TCP port `12201`.
528 The default `source`  attribute is set to `icinga2`. You can customize that for your needs if required.
529
530 Currently these events are processed:
531 * Check results
532 * State changes
533 * Notifications
534
535
536 ### OpenTSDB Writer <a id="opentsdb-writer"></a>
537
538 While there are some OpenTSDB collector scripts and daemons like tcollector available for
539 Icinga 1.x it's more reasonable to directly process the check and plugin performance
540 in memory in Icinga 2. Once there are new metrics available, Icinga 2 will directly
541 write them to the defined TSDB TCP socket.
542
543 You can enable the feature using
544
545 ```
546 # icinga2 feature enable opentsdb
547 ```
548
549 By default the `OpenTsdbWriter` object expects the TSD to listen at
550 `127.0.0.1` on port `4242`.
551
552 The current naming schema is
553
554 ```
555 icinga.host.<metricname>
556 icinga.service.<servicename>.<metricname>
557 ```
558
559 for host and service checks. The tag host is always applied.
560
561 To make sure Icinga 2 writes a valid metric into OpenTSDB some characters are replaced
562 with `_` in the target name:
563
564 ```
565 \  (and space)
566 ```
567
568 The resulting name in OpenTSDB might look like:
569
570 ```
571 www-01 / http-cert / response time
572 icinga.http_cert.response_time
573 ```
574
575 In addition to the performance data retrieved from the check plugin, Icinga 2 sends
576 internal check statistic data to OpenTSDB:
577
578   metric             | description
579   -------------------|------------------------------------------
580   current_attempt    | current check attempt
581   max_check_attempts | maximum check attempts until the hard state is reached
582   reachable          | checked object is reachable
583   downtime_depth     | number of downtimes this object is in
584   acknowledgement    | whether the object is acknowledged or not
585   execution_time     | check execution time
586   latency            | check latency
587   state              | current state of the checked object
588   state_type         | 0=SOFT, 1=HARD state
589
590 While reachable, state and state_type are metrics for the host or service the
591 other metrics follow the current naming schema
592
593 ```
594 icinga.check.<metricname>
595 ```
596
597 with the following tags
598
599   tag     | description
600   --------|------------------------------------------
601   type    | the check type, one of [host, service]
602   host    | hostname, the check ran on
603   service | the service name (if type=service)
604
605 > **Note**
606 >
607 > You might want to set the tsd.core.auto_create_metrics setting to `true`
608 > in your opentsdb.conf configuration file.
609
610
611 ## Livestatus <a id="setting-up-livestatus"></a>
612
613 The [MK Livestatus](https://mathias-kettner.de/checkmk_livestatus.html) project
614 implements a query protocol that lets users query their Icinga instance for
615 status information. It can also be used to send commands.
616
617 The Livestatus component that is distributed as part of Icinga 2 is a
618 re-implementation of the Livestatus protocol which is compatible with MK
619 Livestatus.
620
621 > **Tip**
622 >
623 > Only install the Livestatus feature if your web interface or addon requires
624 > you to do so.
625 > [Icinga Web 2](02-getting-started.md#setting-up-icingaweb2) does not need
626 > Livestatus.
627
628 Details on the available tables and attributes with Icinga 2 can be found
629 in the [Livestatus Schema](24-appendix.md#schema-livestatus) section.
630
631 You can enable Livestatus using icinga2 feature enable:
632
633 ```
634 # icinga2 feature enable livestatus
635 ```
636
637 After that you will have to restart Icinga 2:
638
639 ```
640 # systemctl restart icinga2
641 ```
642
643 By default the Livestatus socket is available in `/var/run/icinga2/cmd/livestatus`.
644
645 In order for queries and commands to work you will need to add your query user
646 (e.g. your web server) to the `icingacmd` group:
647
648 ```
649 # usermod -a -G icingacmd www-data
650 ```
651
652 The Debian packages use `nagios` as the user and group name. Make sure to change `icingacmd` to
653 `nagios` if you're using Debian.
654
655 Change `www-data` to the user you're using to run queries.
656
657 In order to use the historical tables provided by the livestatus feature (for example, the
658 `log` table) you need to have the `CompatLogger` feature enabled. By default these logs
659 are expected to be in `/var/log/icinga2/compat`. A different path can be set using the
660 `compat_log_path` configuration attribute.
661
662 ```
663 # icinga2 feature enable compatlog
664 ```
665
666 ### Livestatus Sockets <a id="livestatus-sockets"></a>
667
668 Other to the Icinga 1.x Addon, Icinga 2 supports two socket types
669
670 * Unix socket (default)
671 * TCP socket
672
673 Details on the configuration can be found in the [LivestatusListener](09-object-types.md#objecttype-livestatuslistener)
674 object configuration.
675
676 ### Livestatus GET Queries <a id="livestatus-get-queries"></a>
677
678 > **Note**
679 >
680 > All Livestatus queries require an additional empty line as query end identifier.
681 > The `nc` tool (`netcat`) provides the `-U` parameter to communicate using
682 > a unix socket.
683
684 There also is a Perl module available in CPAN for accessing the Livestatus socket
685 programmatically: [Monitoring::Livestatus](http://search.cpan.org/~nierlein/Monitoring-Livestatus-0.74/)
686
687
688 Example using the unix socket:
689
690 ```
691 # echo -e "GET services\n" | /usr/bin/nc -U /var/run/icinga2/cmd/livestatus
692
693 Example using the tcp socket listening on port `6558`:
694
695 # echo -e 'GET services\n' | netcat 127.0.0.1 6558
696
697 # cat servicegroups <<EOF
698 GET servicegroups
699
700 EOF
701
702 (cat servicegroups; sleep 1) | netcat 127.0.0.1 6558
703 ```
704
705 ### Livestatus COMMAND Queries <a id="livestatus-command-queries"></a>
706
707 A list of available external commands and their parameters can be found [here](24-appendix.md#external-commands-list-detail)
708
709 ```
710 $ echo -e 'COMMAND <externalcommandstring>' | netcat 127.0.0.1 6558
711 ```
712
713 ### Livestatus Filters <a id="livestatus-filters"></a>
714
715 and, or, negate
716
717   Operator  | Negate   | Description
718   ----------|----------|-------------
719    =        | !=       | Equality
720    ~        | !~       | Regex match
721    =~       | !=~      | Equality ignoring case
722    ~~       | !~~      | Regex ignoring case
723    <        |          | Less than
724    >        |          | Greater than
725    <=       |          | Less than or equal
726    >=       |          | Greater than or equal
727
728
729 ### Livestatus Stats <a id="livestatus-stats"></a>
730
731 Schema: "Stats: aggregatefunction aggregateattribute"
732
733   Aggregate Function | Description
734   -------------------|--------------
735   sum                | &nbsp;
736   min                | &nbsp;
737   max                | &nbsp;
738   avg                | sum / count
739   std                | standard deviation
740   suminv             | sum (1 / value)
741   avginv             | suminv / count
742   count              | ordinary default for any stats query if not aggregate function defined
743
744 Example:
745
746 ```
747 GET hosts
748 Filter: has_been_checked = 1
749 Filter: check_type = 0
750 Stats: sum execution_time
751 Stats: sum latency
752 Stats: sum percent_state_change
753 Stats: min execution_time
754 Stats: min latency
755 Stats: min percent_state_change
756 Stats: max execution_time
757 Stats: max latency
758 Stats: max percent_state_change
759 OutputFormat: json
760 ResponseHeader: fixed16
761 ```
762
763 ### Livestatus Output <a id="livestatus-output"></a>
764
765 * CSV
766
767 CSV output uses two levels of array separators: The members array separator
768 is a comma (1st level) while extra info and host|service relation separator
769 is a pipe (2nd level).
770
771 Separators can be set using ASCII codes like:
772
773 ```
774 Separators: 10 59 44 124
775 ```
776
777 * JSON
778
779 Default separators.
780
781 ### Livestatus Error Codes <a id="livestatus-error-codes"></a>
782
783   Code      | Description
784   ----------|--------------
785   200       | OK
786   404       | Table does not exist
787   452       | Exception on query
788
789 ### Livestatus Tables <a id="livestatus-tables"></a>
790
791   Table         | Join      |Description
792   --------------|-----------|----------------------------
793   hosts         | &nbsp;    | host config and status attributes, services counter
794   hostgroups    | &nbsp;    | hostgroup config, status attributes and host/service counters
795   services      | hosts     | service config and status attributes
796   servicegroups | &nbsp;    | servicegroup config, status attributes and service counters
797   contacts      | &nbsp;    | contact config and status attributes
798   contactgroups | &nbsp;    | contact config, members
799   commands      | &nbsp;    | command name and line
800   status        | &nbsp;    | programstatus, config and stats
801   comments      | services  | status attributes
802   downtimes     | services  | status attributes
803   timeperiods   | &nbsp;    | name and is inside flag
804   endpoints     | &nbsp;    | config and status attributes
805   log           | services, hosts, contacts, commands | parses [compatlog](09-object-types.md#objecttype-compatlogger) and shows log attributes
806   statehist     | hosts, services | parses [compatlog](09-object-types.md#objecttype-compatlogger) and aggregates state change attributes
807   hostsbygroup  | hostgroups | host attributes grouped by hostgroup and its attributes
808   servicesbygroup | servicegroups | service attributes grouped by servicegroup and its attributes
809   servicesbyhostgroup  | hostgroups | service attributes grouped by hostgroup and its attributes
810
811 The `commands` table is populated with `CheckCommand`, `EventCommand` and `NotificationCommand` objects.
812
813 A detailed list on the available table attributes can be found in the [Livestatus Schema documentation](24-appendix.md#schema-livestatus).
814
815
816 ## Status Data Files <a id="status-data"></a>
817
818 > **Note**
819 >
820 > This feature is DEPRECATED and will be removed in Icinga 2 v2.11.
821
822 Icinga 1.x writes object configuration data and status data in a cyclic
823 interval to its `objects.cache` and `status.dat` files. Icinga 2 provides
824 the `StatusDataWriter` object which dumps all configuration objects and
825 status updates in a regular interval.
826
827 ```
828 # icinga2 feature enable statusdata
829 ```
830
831 If you are not using any web interface or addon which uses these files,
832 you can safely disable this feature.
833
834 ## Compat Log Files <a id="compat-logging"></a>
835
836 > **Note**
837 >
838 > This feature is DEPRECATED and will be removed in Icinga 2 v2.11.
839
840 The Icinga 1.x log format is considered being the `Compat Log`
841 in Icinga 2 provided with the `CompatLogger` object.
842
843 These logs are used for informational representation in
844 external web interfaces parsing the logs, but also to generate
845 SLA reports and trends.
846 The [Livestatus](14-features.md#setting-up-livestatus) feature uses these logs
847 for answering queries to historical tables.
848
849 The `CompatLogger` object can be enabled with
850
851 ```
852 # icinga2 feature enable compatlog
853 ```
854
855 By default, the Icinga 1.x log file called `icinga.log` is located
856 in `/var/log/icinga2/compat`. Rotated log files are moved into
857 `var/log/icinga2/compat/archives`.
858
859 ## Check Result Files <a id="check-result-files"></a>
860
861 > **Note**
862 >
863 > This feature is DEPRECATED and will be removed in Icinga 2 v2.11.
864
865 Icinga 1.x writes its check result files to a temporary spool directory
866 where they are processed in a regular interval.
867 While this is extremely inefficient in performance regards it has been
868 rendered useful for passing passive check results directly into Icinga 1.x
869 skipping the external command pipe.
870
871 Several clustered/distributed environments and check-aggregation addons
872 use that method. In order to support step-by-step migration of these
873 environments, Icinga 2 supports the `CheckResultReader` object.
874
875 There is no feature configuration available, but it must be defined
876 on-demand in your Icinga 2 objects configuration.
877
878 ```
879 object CheckResultReader "reader" {
880   spool_dir = "/data/check-results"
881 }
882 ```