Hello there,
I’m currently trying to automate the host creation process with the integrated REST-API. I run the python3 script with the request library.
I copy pasted myself a mashup-script that creates a host, performs a service discovery and activates the changes, but I ran into a problem with the service discovery part. It doesn’t work for me!
The example script for the service discovery is as follows:
`#!/usr/bin/env python3
import pprint
import requests
HOST_NAME = “ip.adress:port”
SITE_NAME = “sitename”
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.post(
f"{API_URL}/objects/host/example.com/actions/discover_services/invoke",
headers={
“Content-Type”: ‘application/json’, # (required) A header specifying which type of content is in the request/response body.
},
json={‘mode’: ‘fix_all’},
)
if resp.status_code == 200:
pprint.pprint(resp.json())
elif resp.status_code == 204:
print(“Done”)
else:
raise RuntimeError(pprint.pformat(resp.json()))`
The problem is, that this script doesn’t do anything. Nothing at all!
If I add “print(resp.status_code)” at the end, I get 200, so it should work fine, but there is nothing changing in CheckMK, no services are added to monitored. But the official definition of the fix_all mode in the ReDoc is:
“fix_all - Add unmonitored services and new host labels, remove vanished services”
I really don’t understand why it’s not working, thanks in advance