1 ## <a id="setting-up-livestatus"></a> Livestatus
3 The [MK Livestatus](http://mathias-kettner.de/checkmk_livestatus.html) project
4 implements a query protocol that lets users query their Icinga instance for
5 status information. It can also be used to send commands.
9 > Only install the Livestatus feature if your web interface or addon requires
10 > you to do so (for example, [Icinga Web 2](2-getting-started.md#setting-up-icingaweb2)).
11 > [Icinga Classic UI](8-alternative-frontends.md#setting-up-icinga-classic-ui) and [Icinga Web](8-alternative-frontends.md#setting-up-icinga-web)
12 > do not use Livestatus as backend.
14 The Livestatus component that is distributed as part of Icinga 2 is a
15 re-implementation of the Livestatus protocol which is compatible with MK
18 Details on the available tables and attributes with Icinga 2 can be found
19 in the [Livestatus Schema](17-appendix.md#schema-livestatus) section.
21 You can enable Livestatus using icinga2 feature enable:
23 # icinga2 feature enable livestatus
25 After that you will have to restart Icinga 2:
27 Debian/Ubuntu, RHEL/CentOS 6 and SUSE:
29 # service icinga2 restart
31 RHEL/CentOS 7 and Fedora:
33 # systemctl restart icinga2
35 By default the Livestatus socket is available in `/var/run/icinga2/cmd/livestatus`.
37 In order for queries and commands to work you will need to add your query user
38 (e.g. your web server) to the `icingacmd` group:
40 # usermod -a -G icingacmd www-data
42 The Debian packages use `nagios` as the user and group name. Make sure to change `icingacmd` to
43 `nagios` if you're using Debian.
45 Change `www-data` to the user you're using to run queries.
47 In order to use the historical tables provided by the livestatus feature (for example, the
48 `log` table) you need to have the `CompatLogger` feature enabled. By default these logs
49 are expected to be in `/var/log/icinga2/compat`. A different path can be set using the
50 `compat_log_path` configuration attribute.
52 # icinga2 feature enable compatlog
55 ### <a id="livestatus-sockets"></a> Livestatus Sockets
57 Other to the Icinga 1.x Addon, Icinga 2 supports two socket types
59 * Unix socket (default)
62 Details on the configuration can be found in the [LivestatusListener](15-object-types.md#objecttype-livestatuslistener)
65 ### <a id="livestatus-get-queries"></a> Livestatus GET Queries
69 > All Livestatus queries require an additional empty line as query end identifier.
70 > The `nc` tool (`netcat`) provides the `-U` parameter to communicate using
73 There also is a Perl module available in CPAN for accessing the Livestatus socket
74 programmatically: [Monitoring::Livestatus](http://search.cpan.org/~nierlein/Monitoring-Livestatus-0.74/)
77 Example using the unix socket:
79 # echo -e "GET services\n" | /usr/bin/nc -U /var/run/icinga2/cmd/livestatus
81 Example using the tcp socket listening on port `6558`:
83 # echo -e 'GET services\n' | netcat 127.0.0.1 6558
85 # cat servicegroups <<EOF
90 (cat servicegroups; sleep 1) | netcat 127.0.0.1 6558
93 ### <a id="livestatus-command-queries"></a> Livestatus COMMAND Queries
95 A list of available external commands and their parameters can be found [here](17-appendix.md#external-commands-list-detail)
97 $ echo -e 'COMMAND <externalcommandstring>' | netcat 127.0.0.1 6558
100 ### <a id="livestatus-filters"></a> Livestatus Filters
104 Operator | Negate | Description
105 ----------|------------------------
108 =~ | !=~ | Equality ignoring case
109 ~~ | !~~ | Regex ignoring case
112 <= | | Less than or equal
113 >= | | Greater than or equal
116 ### <a id="livestatus-stats"></a> Livestatus Stats
118 Schema: "Stats: aggregatefunction aggregateattribute"
120 Aggregate Function | Description
121 -------------------|--------------
126 std | standard deviation
127 suminv | sum (1 / value)
128 avginv | suminv / count
129 count | ordinary default for any stats query if not aggregate function defined
134 Filter: has_been_checked = 1
135 Filter: check_type = 0
136 Stats: sum execution_time
138 Stats: sum percent_state_change
139 Stats: min execution_time
141 Stats: min percent_state_change
142 Stats: max execution_time
144 Stats: max percent_state_change
146 ResponseHeader: fixed16
148 ### <a id="livestatus-output"></a> Livestatus Output
152 CSV output uses two levels of array separators: The members array separator
153 is a comma (1st level) while extra info and host|service relation separator
154 is a pipe (2nd level).
156 Separators can be set using ASCII codes like:
158 Separators: 10 59 44 124
164 ### <a id="livestatus-error-codes"></a> Livestatus Error Codes
167 ----------|--------------
169 404 | Table does not exist
170 452 | Exception on query
172 ### <a id="livestatus-tables"></a> Livestatus Tables
174 Table | Join |Description
175 --------------|-----------|----------------------------
176 hosts | | host config and status attributes, services counter
177 hostgroups | | hostgroup config, status attributes and host/service counters
178 services | hosts | service config and status attributes
179 servicegroups | | servicegroup config, status attributes and service counters
180 contacts | | contact config and status attributes
181 contactgroups | | contact config, members
182 commands | | command name and line
183 status | | programstatus, config and stats
184 comments | services | status attributes
185 downtimes | services | status attributes
186 timeperiods | | name and is inside flag
187 endpoints | | config and status attributes
188 log | services, hosts, contacts, commands | parses [compatlog](15-object-types.md#objecttype-compatlogger) and shows log attributes
189 statehist | hosts, services | parses [compatlog](15-object-types.md#objecttype-compatlogger) and aggregates state change attributes
191 The `commands` table is populated with `CheckCommand`, `EventCommand` and `NotificationCommand` objects.
193 A detailed list on the available table attributes can be found in the [Livestatus Schema documentation](17-appendix.md#schema-livestatus).