API - Add Host to Contact Group

Im searching a way to add host to contact group. I have all hosts organized in folders and I have to associate them to a specific contact group. On standard API i cant find the correct call.

Below the page I have to replicate by API. I’ve tryed to replicate the POST call from this page but it doesn’t work.

Regards.

EmiSvil

Rule editing is available with the REST API of checkmk version 2.1.

1 Like

Rule creation is available in 2.0

I see a set of API’s endpoint about ruleset but nothing about single rule.
When calling get_rulesets I get a list of ruleset:

{
	"active_checks:ssh": {
		"title": "Check SSH service",
		"help": "This rulset allow you to configure a SSH check for a host",
		"number_of_rules": 0
	},
	"active_checks:icmp": {
		"title": "Check hosts with PING (ICMP Echo Request)",
		"help": "This ruleset allows you to configure explicit PING monitoring of hosts. Usually a PING is being used as a host check, so this is not neccessary. There are some situations, however, where this can be useful. One of them is when using the Check_MK Micro Core with SMART Ping and you want to track performance data of the PING to some hosts, nevertheless.",
		"number_of_rules": 0
	},
....

but nothing about the association of Hosts to ContactGroup.

get_rulesets is from the old and soon deprectaed WATO API.
You may be able to edit rules with that API but you will always need to read the complete ruleset, modify it on client side and write the complete ruleset again.

Okay.
I’ve found the solution.
I have to call set_ruleset with ruleset_name “host_contactgroups” and ruleset parameter with an array with this structure:

"<FOLDER_NAME>": [
			{
				"value": "<CONTACT_GROUP>",
				"condition": {},
				"options": {
					"description": "<DESCRIPTION>"
				}
			}
		],

The bad part is I have to send always ALL rules because this calls override completely. Is not an ADD but a TRUNCATE → INSERT.

Thats just how Checkmk works and no, there are no way around that.
And you should not use the WebAPI as you are on 2.x - Stop doing that.

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.