we have been using Ansible to manage our 100+ Linux Servers with the Ansible inventory being auto-generated via the CheckMK REST API and a Python script.
As we have used CheckMK some years already, we implemented some Ansible Inventory groups, which we otherwise couldn’t find via CheckMK API, in the form of Host-Tags, AUX-Tags, etc.
We currently use python to call the host_config/collections/all endpoint and scan for the necessary information.
After looking through some things again, we found that (at least in the Monitoring WebUI) you can find a list of every server with docker installed when searching Docker Nodes in the Monitoring search bar. This would be the perfect replacement for our dockerhosts group, which is still manually managed via per-host-settings.
I was also unable to find automatically discovered host-labels like cmk/docker_object:node, which otherwise would also be an easier way to manage our dockerhosts Ansible group.
Sadly, I was not able to find the corresponding API endpoint which would contain any of these information.
Did I miss something or is this information not available via REST API?
no the RestAPI is not mainly targeted to do filtering. you can use any view however and use the standard outpot_format parameters - or you could use livestatus
More information can be found in the API documentation (Help → REST API documentation)
under “Querying-Status-Data” and “Table definitions”.
A useful python example can be found under “Queries through the REST API”.
Complete example when you want to find all Docker nodes:
You can access almost everything from livestatus with the REST API. Sometimes it needs some time to understand how to build the query and how the columns are named.
Thank you very much, this was exactly what I needed.
I never got around to really understand the REST API and all of its features, especially how to query specific information.
Thanks to you and these examples, I have updated my python script already.
I’m definitely going to look through my whole ansible-inventory-generation script, because now that I know of and am able to use the query system, I feel like there might be a lot of other things I have not been doing in the most optimal way possible
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.