Hi,
I am following this documentation: Checkmk REST-API
I am trying to extract metrics (e.g CPU load info) from a host, a snippet of my code is
#!/usr/bin/env python3
import pprint
import requests
HOST_NAME = "hostsite"
SITE_NAME = "sitname"
API_URL = f"http://{HOST_NAME}/{SITE_NAME}/check_mk/api/1.0"
USERNAME = "user"
PASSWORD = "password"
session = requests.session()
session.headers['Authorization'] = f"Bearer {USERNAME} {PASSWORD}"
session.headers['Accept'] = 'application/json'
resp = session.get(
f"{API_URL}/domain-types/service/collections/all",
params={ # goes into query string
"host_name": 'hostname', # A hostname.
"query": '{"op": "and", "expr": [{"op": "=", "left": "host_name", "right": "hostname"},{"op": "=", "left":"description", "right": "CPU load"}, {"op": "=", "left":"metrics", "right": "CPU load"}]}',
},
)
if resp.status_code == 200:
pprint.pprint(resp.json())
elif resp.status_code == 204:
print("Done")
else:
raise RuntimeError(pprint.pformat(resp.json()))
This code above is not fetching me the metrics I need for a particular service.
I thought from the “services” table, I could use for example the “metrics” function defined as:
metrics list A list of all metrics of this object that historically existed
But how do I use this in the rest-API query? So I could extract actual values from the services I want, like CPU load, CPU utilization, etc. Thank you!
Best,
Jem