Issue with Host Deletion via API

CMK version: 2.0.0p18 CEE
OS version: RHEL 7.9

Hi,
we have a very strange problem deleting hosts via API. We call the API call inside an ansible playbook like this:

uri:
url: “{{ check_mk_agent_monitoring_host_url }}check_mk/api/1.0/objects/host_config/{ inventory_hostname }}”
method: DELETE
return_content: yes
status_code: [200,204]
headers:
Content-Type: "application/json
Accept: “application/json”
Authorization: bearer {{ check_mk_agent_monitoring_host_wato_username }} {{ check_mk_agent_monitoring_host_wato_secret }}

After that, we currently have to manually activate the resulting changes. The strange thing now is that not all hosts are deleted completely. For example, if I delete three hosts via the playbook, the three changes appear in the GUI, but after activating them, there is often one host left in a half-baked state. Only the Active Checks and the checkmk services are still visible there. Everything else is missing (e.g. file systems, CPU, etc.). I then have to delete this host again via the GUI.
Has anyone had similar problems deleting hosts via the API?

VG
Christian

Maybe you could try adding a time.sleep(x) in Python or the sleep command in Bash, between the API requests. I would also consider using the bulk deletion option instead.

1 Like

Hi, I’ll check this.
Thank you so far.

Regards
Christian

When you activate you mean you activate changes? And are all changes ok? No errors?
I have never seen this before. Are you running your Ansible jobs in parallel? Perhaps your server is not fast enough and strange things happened?
Perhaps you could try to sleep a while between your hosts?

1 Like

Hello,
thank you very much for the answers so far. So my guess is that the parallel deletion via the API is causing the checkmk server to misbehave. I have now serialized the api call with “throttle: 1” in my Ansible playbook. Since then I don’t have this problem anymore.

I’ll do some further testing.
Regards
Christian

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.