REST-API issue regarding service discovery

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 :wink:

So I found out that by using the “refresh” mode, everything works as planned. But that doesn’t answer the question for me, has anyone an idea what could be wrong in that case?

I’m trying to transition to the REST API and seeing similar. Fix_all does nothing. Refresh appears to work but the GUI doesn’t actually pick up the change until I open service discovery there as well. The Web API py still works as expected.

Hi,

I’m in Checkmk Free Edition 2.1.0b9 and i have the exact same problem but for me refresh doesn’t work either…
I copy paste the examples of the checkmk official doc but i ran into the same issue : nothing happen.
Do you know if they are working on it currently, if my version is bugged ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.