Werk #16149: New OrderBy header in livestatus

Component Livestatus
Title New OrderBy header in livestatus
Date Jan 29, 2024
Level Trivial Change
Class New Feature
Compatibility Compatible - no manual interaction needed
Checkmk versions & editions
2.4.0b1
Not yet released
Checkmk Raw (CRE), Checkmk Enterprise (CEE), Checkmk Cloud (CCE), Checkmk MSP (CME)
2.3.0b1 Checkmk Raw (CRE), Checkmk Enterprise (CEE), Checkmk Cloud (CCE), Checkmk MSP (CME)

We provide a new header for livestatus that returns the rows in sorted order.

For example, to sort host names in descending order

$ lq 'GET hosts\nColumns: name\nOrderBy: name desc'
zhost
yhost
xhost
...

in ascending order

$ lq 'GET hosts\nColumns: name\nOrderBy: name asc'
ahost
bhost
...

or, alternatively without asc,

$ lq 'GET hosts\nColumns: name\nOrderBy: name'
ahost
bhost
...

The OrderBy header can be combined with the Limit header to limit the number of results as expected.

$ lq 'GET hosts\nColumns: name\nOrderBy: name\nLimit: 1'
ahost

Furthermore, it is possible to sort on dictionary keys with the following syntax

$ lq << EOF
GET services
Columns: host_name description performance_data
OrderBy: performance_data.user_time
EOF
...

To the list of all Werks