CheckMK API in Python

CMK version:2.2.0p22

I’m trying to write up some Python code to interact with the REST-API of CheckMK.
I want to get a list of all unhandled service problems, but I can’t find a fitting command in the documentation? I’d be very surprised if it cant be done, since this seems incredibly basic to me.

Also, the documentation mentions an API Key, but I can’t find anything in the settings mentioning it.

I hope someone here can help me.

Hello P-Franke,

The query is also pretty simple.

The following query finds all services. You can refine this with “query”. In this example, all services are identified that have not been confirmed and that have an unequal OK status.

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={
        "query": '{"op": "and", "expr": [{"op": "=", "left": "acknowledged", "right": "0"},{"op": "!=", "left": "state", "right": "0"}]}',
        "columns": ['host_name', 'description'],
    },
)

Best regards

Alex

1 Like