Is there a way I can get a list of hosts from CLI for a specific folder within Main directory? Example:
I have a couple hundred hosts and they all sit nicely in their own folders:
Main Directory -
loc1
loc2
loc3
loc4
…and so on.
from the GUI, I can go into each folder and export the list of hosts in CSV with a click. Is there a way to get that CSV (or a plain text file will do) from CLI as well? We need this to feed this information to another more centralized portal.
there are several ways to to that depending on your monitoring infrastructure.
I would like to prefer a python script using APT to get all host. The JSON result now can parsed based on the folder. If you have a distributed site, you can order your host additionally on the manged site.
Ig you have a single site, you can use lq with the the following filter:
GET hosts
Columns: hostname
Filters: folder = linux/db
Thanks for the valuable information. I was able to get a list of all the hosts using printf and unixcat per https://docs.checkmk.com/latest/en/livestatus.html but I am not able to filter based on “Filters: folder = linux/db”. Does ‘linux’ in this case is the main directory and is there a way to get the hierarchy from some file?
About python and APT, I am sorry I did not get that part. On what file I’d need to wrap the script around to get that JSON file?
We are using single instance of omd (single site) and Version: Checkmk Raw 1.6.0p11
Your folder hierarchy is visible under /omd/sites/~site/etc/check_mk/conf.d/wato/ and matches your wato folder structure if you never renamed a folder inside wato GUI.
Livestatus has an export format option to get the data in different formats, just check the web page you wrote.
Thanks everyone for the comments. I ended up using lql for this purpose and directed the output to a file. For anyone like me looking for answers, use something similar to the following:
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.