Code

sysdbql(7): Document IS [NOT] TRUE / FALSE.
[sysdb.git] / doc / sysdbql.7.txt
1 sysdbql(7)
2 ==========
3 :doctype: manpage
5 NAME
6 ----
7 sysdbql - the SysDB query language (SysQL)
9 SYNOPSIS
10 --------
12   LIST hosts;
13   LIST services;
15   FETCH host 'some.host.name';
17   LOOKUP hosts MATCHING attribute['architecture'] = 'amd64'
18                    AND 'backend::collectd::unixsock' in backend
19                FILTER age < 5 * interval;
21   STORE host attribute 'some.host.name'.'key' 123.45
22                        LAST UPDATE 2001-02-03 04:05:06;
24 DESCRIPTION
25 -----------
26 include::sysdb-description.txt[]
28 The SysDB query language (SysQL) is a human-readable format for describing a
29 request to retrieve data from a SysDB daemon. It is very remotely similar to
30 the Standard Query Language (SQL) supported by relational database management
31 systems (RDBMS) but specialized for SysDB's use-case.
33 Besides querying data, SysQL may also be used to store or update objects in
34 SysDB.
36 QUERY COMMANDS
37 --------------
38 Each command is terminated by a semicolon. The following commands are
39 available to retrieve information from SysDB:
41 *LIST* hosts|services|metrics [*FILTER* '<filter_condition>']::
42 Retrieve a sorted (by name) list of all objects of the specified type
43 currently stored in SysDB. The return value is a list of objects including
44 their names, the timestamp of the last update and an approximation of the
45 interval with which the host was updated. When listing services or metrics,
46 the respective objects will be grouped by host. If a filter condition is
47 specified, only objects matching that filter will be included in the reply.
48 See the section "FILTER clause" for more details about how to specify the
49 search and filter conditions.
51 *FETCH* host '<hostname>' [*FILTER* '<filter_condition>']::
52 *FETCH* service|metric '<hostname>'.'<name>' [*FILTER* '<filter_condition>']::
53 Retrieve detailed information about the specified object. The return value
54 includes the full object including all of its attributes and child objects.
55 If the named object does not exist, an error is returned. If a filter
56 condition is specified, only objects matching that filter will be included in
57 the reply. See the section "FILTER clause" for more details about how to
58 specify the search and filter conditions.
60 *LOOKUP* hosts|services|metrics [*MATCHING* '<search_condition>'] [*FILTER* '<filter_condition>']::
61 Retrieve detailed information about all objects matching the specified search
62 condition. The return value is a list of detailed information for each
63 matching object providing the same details as returned by the *FETCH* command.
64 If no object matches the search criteria, it's not considered an error.
65 Instead, an empty list is returned. If a filter condition is specified, only
66 objects matching that filter will be included in the reply. See the sections
67 "MATCHING clause" and "FILTER clause" for more details about how to specify
68 the search and filter conditions.
70 *TIMESERIES* '<hostname>'.'<metric>' [START '<datetime>'] [END '<datetime>']::
71 Retrieve a time-series for the specified host's metric. The data is retrieved
72 from a backend data-store based on information provided by the respective
73 query plugin. The return value includes the actual start and end time of the
74 time-series and one or multiple sequences of time-stamp / value pairs. If the
75 metric does not exist or if the backend data-store is not supported, an error
76 is returned.
78 MATCHING clause
79 ~~~~~~~~~~~~~~~
80 The *MATCHING* clause in a query specifies a boolean expression which is used
81 to match objects based on their fields, attributes, or child objects. Any
82 object for which the expression evaluates to true will be included in the
83 result set according to the rules set by the actual query.
85 FILTER clause
86 ~~~~~~~~~~~~~
87 The *FILTER* clause in a query specifies a boolean expression which is used to
88 filter objects included in the query's response. The filter is applied to
89 hosts, services, and attributes alike and, thus, will usually be based on the
90 core properties of the stored objects. The basic syntax for filter clauses is
91 the same as for matching clauses.
93 Expressions
94 ~~~~~~~~~~~
95 Expressions form the basic building block for all queries. Boolean expressions
96 select objects based on the values of arithmetic expressions which operate on
97 object specific values (fields) or constant values.
99 Boolean expressions may use the following operators:
101 '<expression>' *AND* '<expression>'::
102 '<expression>' *OR* '<expression>'::
103         Evaluates to the logical AND or logical OR of the specified
104         subexpressions.
106 *NOT* '<expression>'::
107         Invert the boolean result of the specified subexpression.
109 '<expression>' '<cmp>' '<expression>'::
110         Compare the values of two expressions using any compare operator (see
111         below). Evaluates to either true or false. Comparing any value with a NULL
112         value always evaluates to false. The data types of the two values have to
113         match except for a few cases as noted in the documentation of the
114         respective operator.
116 *ANY* '<iterable>' '<cmp>' '<expression>'::
117         Compares each element of an iterable using any compare operator. Evaluates
118         to true if any of the elements matches or false if no such elements exist.
119         Otherwise, the same rules as for other comparison operations apply.
120         Attributes, a host's services and metrics, and arrays are iterables.
122 *ALL* '<iterable>' '<cmp>' '<expression>'::
123         *ALL* is similar to the *ANY* operator but matches if all elements match
124         or if no elements exist.
126 '<expression>' *IS NULL*::
127 '<expression>' *IS NOT NULL*::
128         Check whether an expression evaluates to a NULL value (or not). An
129         expression evaluates to NULL if the queried object does not exist (e.g.,
130         when accessing an attribute value).
132 '<expression>' *IS TRUE*::
133 '<expression>' *IS NOT TRUE*::
134 '<expression>' *IS FALSE*::
135 '<expression>' *IS NOT FALSE*::
136         Check whether an expression evaluates to a boolean *true* or *false* value
137         (or not).
139 '<expression>' *IN* '<expression>'::
140 '<expression>' *NOT IN* '<expression>'::
141         Checks whether the value of the first expression is included in the value
142         of the second expression (or not). The second value has to be an array
143         value (e.g., *backend* field) and the type of the first value has to match
144         the array's element type. The first value may also be an array. In this
145         case, the expression evaluates to true if all elements of that array are
146         included in the second array where order does not matter.
148 Parentheses ('()') may be used around subexpressions to group them and enforce
149 precedence.
151 The following fields may be queried:
153 *name*::
154         The canonicalized name of the object. The type of this field is string.
156 *last_update*::
157         The timestamp of the last update of the object. This value is based on
158         information provided by the queried backend if possible. The type of this
159         field is date-time.
161 *age*::
162         The amount of time since the last update of the object. The type of this
163         field is date-time.
165 *interval*::
166         The interval with which the object gets updated. This value is determined
167         automatically based on a moving average determined from the update
168         timestamps of an object. It depends on the update timestamps as provided
169         by the backend (if available) and SysDB's query interval. The type of this
170         field is date-time.
172 *backend*::
173         The name of the backend (plugin) providing the data. The type of this
174         field is array of strings.
176 *attribute[*'<name>'*]*::
177         The value of the object's named attribute. If an attribute of the
178         specified name does not exist, each comparison is treated as if the value
179         does not match. See the documentation for the *IS NULL* and *IS NOT NULL*
180         operators for ways to check if an attribute exists. The value of an
181         attribute may be of any of the supported data types. There is no schema
182         specifying each attribute's data type which means that the parser cannot
183         do any type checks. Thus, in case the data types mismatch when comparing
184         an attribute value with some other value, the two values will be cast to
185         strings before comparing them.
187 Field expressions may be applied to parent or child nodes. For example, a
188 host's services are child objects and the host is the parent of the service
189 objects. This is done using typed expressions:
191 host|service|metric.'<field>'::
192         Evaluate the field in the context of the respective parent or child.
193         Currently, this is limited to services or metrics referencing their parent
194         host.
196 The following logical operators are supported by SysDB. Unless otherwise
197 noted, the data types of the left hand and right hand side have to match.
199 *=*::
200         Checks two values for equality.
202 *!=*::
203         Checks two values for inequality.
205 *=~*::
206         Checks if a value matches a regular expression. The regex pattern has to
207         be specified as a string but the value may be of any type and will be cast
208         to a string before evaluating the regular expression. SysDB uses POSIX
209         extended regular expressions.
211 *!~*::
212         Checks if a value does not match a regular expression. The same rules
213         apply as for the *=~* operator.
215 *<*, *\<=*, *>=*, *>*::
216         Checks whether a value compares less than, less than or equal to, greater
217         than or equal, or greater than some other value.
219 The following arithmetic operators are supported by SysDB. Unless otherwise
220 noted, the data types of the left hand and right hand side have to match.
222 *+*::
223 *-*::
224         Add or subtract two numeric or date-time values.
226 ***::
227 */*::
228         Multiple or divide two numeric or data-time values. A date-time value may
229         be multiplied with a numeric value or divided by a numeric value. The
230         result will then be a date-time value.
232 *%*::
233         Modulo operator (remainder of division). Same rules for data types apply
234         as for division.
236 *||*::
237         Concatenate string or array values.
239 STORING DATA
240 ------------
241 The *STORE* command may be used to store or update an object in SysDB. Each
242 command is terminated by a semicolon. The following variants are available for
243 storing the different data types:
245 *STORE* host '<name>' [*LAST UPDATE* '<datetime>']::
246 *STORE* service|metric '<hostname>'.'<name>' [*LAST UPDATE* '<datetime>']::
247 *STORE* host attribute '<hostname>'.'<key>' '<value>' [*LAST UPDATE* '<datetime>']::
248 *STORE* service|metric attribute '<hostname>'.'<name>'.'<key>' '<value>' [*LAST UPDATE* '<datetime>']::
249         Store an object of the specified type and name. For services, metrics, and
250         attributes, the name is prepended with the parent object name separated by
251         a dot ('.'). Optionally, the time-stamp of the object's last update may be
252         provided as well. If omitted, the current time on the server will be used
253         instead.
255 *STORE* metric '<hostname>'.'<name>' STORE '<type>' '<id>' [*LAST UPDATE* '<datetime>']::
256         Store a metric and provide information about the metric store associated
257         with it. A metric store describes how to access a metric's data and can be
258         used to retrieve time-series information associated with the metric. See
259         the manpage:sysdb[7] manpage for details.
261         Note that the metric store information will be forwarded to the server
262         unmodified. That is, they need to be specified in a way such that the
263         server can make sense out of them. Else, retrieval of time-series data
264         will fail.
266 DATA TYPES
267 ----------
268 The SysDB query language natively supports various data-types. Constants of
269 all types may be used in any place where a value is expected.
271 *String constants*::
272         A string constant is an arbitrary sequence of characters enclosed in
273         single quotes ('''). Single quotes may be included in a string constant by
274         specifying two adjacent single quotes.
276 *Integer constants*::
277         An integer constant may be specified either as a sequence of digits or in
278         scientific notation written in the form "'a' E 'b'" (without spaces) where
279         'a' and 'b' are integers. A leading plus or minus sign specifies the sign
280         of the constant.
282 *Floating-point constants*::
283         A floating-point constant is a sequence of digits containing a decimal
284         point. Digits before or after the decimal point (but not both) are
285         optional. Floating-point constants may also be specified in scientific
286         notation by appending the letter "E" and a positive or negative integer
287         exponent. A leading plus or minus sign specifies the sign of the constant.
289 *Date and time constants*::
290         A date constant may be specified as 'YYYY-MM-DD' and time constants may be
291         specified as 'HH:MM:SS.nnnnnnnnn' where seconds and nanoseconds are
292         optional.
294 *Interval constants*::
295         An interval may be specified by one or multiple quantity and unit pairs.
296         The quantity may be any integer constant and the unit may be any of the
297         following: *Y* (years), *M* (months), *D* (days), *h* (hours), *m*
298         (minutes), *s* (seconds), *ms* (milliseconds), *us* (microseconds), or
299         *ns* (nanoseconds). Note that years and months are approximations.
301 *Array constants*::
302         An array stores of one or more values of the same type. It may be
303         specified as a comma-separated list of constant values enclosed in square
304         brackets ('[<elem1>,<elem2>,...]'). For each value, the same rules apply
305         as for a regular constant value of that type.
307 RESPONSE FORMAT
308 ---------------
309 The JavaScript Object Notation (JSON) format, as specified in RFC 4627, is
310 used in all query replies from the server. http://www.ietf.org/rfc/rfc4627.txt
312 For all other commands, the reply will be a message string.
314 EXAMPLES
315 --------
316 The following examples illustrate the use of the commands and what their
317 replies look like. The replies are pretty-printed to more easily follow them.
319   LIST hosts;
320   [{
321       "name": "host1.example.com",
322       "last_update": "2001-02-03 04:05:06 +0700",
323       "update_interval": "5m4s",
324       "backend": ['backend::mk-livestatus']
325     },{
326       "name": "host2.example.com",
327       "last_update": "2001-02-03 04:05:06 +0700",
328       "update_interval": "10s",
329       "backend": ['backend::mk-livestatus','backend::collectd::unixsock']
330     }]
332   FETCH host 'host1.example.com';
333   {
334       "name": "host1.example.com",
335       "last_update": "2001-02-03 04:05:06 +0700",
336       "update_interval": "5m4s",
337       "backend": ['backend::mk-livestatus'],
338       "attributes": [{
339           "name": "architecture",
340           "value": "amd64",
341           "last_update": "2001-02-03 04:05:06 +0700",
342           "update_interval": "5m4s",
343           "backend": ['backend::mk-livestatus']
344         },{
345           ...
346         }],
347       "services": [{
348           "name": "some service",
349           "last_update": "2001-02-03 04:05:06 +0700",
350           "update_interval": "5m4s",
351           "backend": ['backend::mk-livestatus']
352         },{
353           ...
354         }]}
356   LOOKUP hosts MATCHING attribute['architecture'] = 'amd64';
357   [{
358       "name": "host1.example.com",
359       "last_update": "2001-02-03 04:05:06 +0700",
360       "update_interval": "5m4s",
361       "backend": ['backend::mk-livestatus'],
362       "attributes": [{
363           "name": "architecture",
364           "value": "amd64",
365           "last_update": "2001-02-03 04:05:06 +0700",
366           "update_interval": "5m4s",
367           "backend": ['backend::mk-livestatus']
368         },{
369           ...
370         }],
371       "services": [{
372           "name": "some service",
373           "last_update": "2001-02-03 04:05:06 +0700",
374           "update_interval": "5m4s",
375           "backend": ['backend::mk-livestatus']
376         },{
377           ...
378     }]},{
379       ...
380     }]
382 SEE ALSO
383 --------
384 manpage:sysdb[1], manpage:sysdb[7]
386 RFC 4627 (JSON): http://www.ietf.org/rfc/rfc4627.txt
388 The SysDB homepage: https://sysdb.io/
390 AUTHOR
391 ------
392 SysDB was written by Sebastian "tokkee" Harl <sh@tokkee.org>.
394 COPYRIGHT
395 ---------
396 Copyright (C) 2012-2014 Sebastian "tokkee" Harl <sh@tokkee.org>
398 This is free software under the terms of the BSD license, see the source for
399 copying conditions. There is NO WARRANTY; not even for MERCHANTABILITY or
400 FITNESS FOR A PARTICULAR PURPOSE.
402 // vim: set tw=78 sw=4 ts=4 noexpandtab spell spelllang=en_us :