Rest-API Show all monitored services "columns" defining problem

CMK version:2.1.0p25
OS version:RHEL 8.7

Hello everyone,

i have a few problems with the new RestAPI and maybe y’all here can help me.
I try to get a service from a host, using the request “Show all monitored services”.
The problem here is, that it seems that i can’t change the displayed columns, because if i try, all i get is "Unknown column: services.[...]"

I already fixed my broken query, but can’t seem to find the problem in my columns-definition.
My script is written in python3. I already wrote a new API-Class for the RestAPI and trying to understand the referenced input, which is descriped in the “ReDoc” of Check_MK.

The columns aren’t complicated or something, just:
["host_name", "host_address", "state", "plugin_output", "host_contact_groups", "tags"]
All my inputs are correctly parsed into the url.

I heared, there are some problems with this specific request, but i need it for my future automation scripts (i want all Services of a name, not just form one host).

This is the example code in the “ReDoc” documentation:

query_string = urllib.parse.urlencode({
    "host_name": 'example.com',  # A hostname.
    "query": '{"op": "=", "left": "host_name", "right": "example.com"}',  # An query expression of the Livestatus 'services' table in nested dictionary form.
    "columns": ['host_name', 'description'],  # The desired columns of the `services` table.
})

My columns-definition are also a list-type, but maybe there is an undocumentated change i’m not seeing?
The interactive Rest-API GUI sadly has no example for this request, that’s why i hope i can get help here.
All i can find are examples for bash-curl requests, but i specific want an urllib-request type. That way my coworkers also can use it.

Can someone relate or given me a soluation to that problem? Giving code-examples will be hard, because it’s separated into a class and execute-script, but if wished, i can try to migrate them to an example script.

Regards, Kruzgoth

Would be nice if someone from the Rest-API devs could comment on this what exactly i’m doing wrong or what is wrong in the documentation.
I followed the ReDoc documentation for urllib, but still can’t get this value right, it seems different.

You can find the column names of the table service here: checkmk/cmk/utils/livestatus_helpers/tables/services.py at master · Checkmk/checkmk · GitHub

“service” is not a valid column name and hence the error. Either use “decscription” or “display_name”.

“service” is the responsed error output from the server from me trying to get the “columns” “[…]”.
I did not write “service”, it’s part of the error code the RestAPI returns.

Just like "get all service from ‘bla’ ", give me column “kids”:
Response: Unknown column: services.[‘kids’]

This seems to be one of the more complicated Rest-API calls. In case others encounter this problem, here’s some related information:

  1. urllib vs. requests - Usually the newer requests module should be preferred over the older and more complicated urllib1/2/3 modules. Examples for requests usually work as documented in ReDoc.

  2. doseq option for urllib - In case you cannot or do not want to use requests in your environment, you need to know that some ReDoc examples for urllib might currently be incomplete: To urlencode a list like
    "columns": ['host_name', 'description'], you need to add the option doseq=True

query_string = urllib.parse.urlencode({
    "host_name": "localhost",
    "query": '{"op": "=", "left": "host_name", "right": "localhost"}',
    "columns": ["host_name", "description", "check_command", "contacts"],
}, doseq=True)

(Thanks to checkmk support for pointing this out!)

And you need to know valid column names, which you can find in the github-link that was mentioned above.

  1. columns: Do not confuse this parameter with LQL queries (as I initially did). It can be used to request additional columns from the API, because by default you only get host_name and description, while in LQL you usually use Columns: it to filter out some desired columns from the full default list.

Have fun! Kind regards and a nice weekend! Dirk.

That’s what i was looking for. Thanks.