Hi
I need to get and assign labels through REST API and powershell in Checkmk Enterprise 2.3.0p35.
But when I get labels I dont get all labels even through “REST API interactive GUI”
So is there difference in labels, have 2 differnt host with differnt labels, one I can get the labels:
the other server I have created a new host label and assigned though a Host label rule with start Patch, but I dont get any of the labels, not event the “cmk/”
The REST API endpoint you are using is for the configuration of a host. It will only be able to get and set labels that are directly set in the host properties. It will not show labels set by the agent (e.g. the ones starting with cmk/) and not the labels set by rules.
If you want to see all labels currently active on a host you need to use the API endpoint for the monitoring state of a host. The URL is {API_URL}/objects/host/{HOSTNAME}. For some reason it is not available in the Swagger web app.
just in case someone stumbles over this and wants to know how to simply get the labels of a host:
{API_URL}/objects/host/{HOSTNAME}?columns=labels
For people knowing their way around REST API it might be obvious, for me it was not and since I did not find it in the Checkmk REST API documentation, I had to google it.