CMK version: 2.1.0p8
OS version: Ubuntu 20.04.4 LTS
Hello,
I have a host monitored via checkmk and i want to change a service “target_phase” using the API.
When i call the update_discovery_phase
API i get the following error:
{'detail': "Failed to get host from folder ''.",
'status': 500,
'title': 'An exception occurred.'}
In order to call the API i’m using the following code:
#!/usr/bin/env python3
import pprint
import requests
HOST_NAME = "localhost"
SITE_NAME = "trademonitor"
API_URL = f"http://{HOST_NAME}/{SITE_NAME}/check_mk/api/1.0"
USERNAME = "automation"
PASSWORD = "test123"
session = requests.session()
session.headers['Authorization'] = f"Bearer {USERNAME} {PASSWORD}"
session.headers['Accept'] = 'application/json'
resp = session.put(
f"{API_URL}/objects/host/example.com/actions/update_discovery_phase/invoke",
headers={
"Content-Type": 'application/json',
},
json={
'check_type': 'df',
'service_item': '/home',
'target_phase': 'monitored'
},
)
if resp.status_code == 200:
pprint.pprint(resp.json())
elif resp.status_code == 204:
print("Done")
else:
raise RuntimeError(pprint.pformat(resp.json()))
It doesn’t seem there is a way to specify the folder with the API looking at the documentation .
It works only if the host is not in a folder.
Is it a bug? Is there a way to specify the folder?