I am using the Check_MK REST API in conjunction with our own internal CMDB, to populate hosts in Check_MK based on the information in our CMDB(which is automatically updated via a discovery mechanism). The following all works well;-
Add Hosts (including folder and label assignments)
Delete Hosts
Update Hosts (including folder and label assignments)
Perform Service Discovery
Activate Changes
What I cant seem to find is a way to add hosts to a host groups. I can create host groups with the REST API without issue, but there does not appear to be a way to add hosts to the host groups, or create/delete host group rules. Is this not possible with the V2 REST API?
Any suggestions on how I might achieve this, I need to create the rules in a script as they are dynamic in nature due to the information I extract from our CMDB.
With the REST API you can create rules in the ruleset âAssignment of hosts to host groupsâ. There you can assign X hosts to one host group per rule. If you want to delete a host from a group you then would need to edit the rule.
Thanks for the quick response, can you point me to the documentation for this, I cannot find anything in the REST API docs that allows me to create rules?..or have I lost the plot
You can just go to âHelpâ in the lower-left corner and go to REST API documentation. There you can find anything including âRulesâ under âSETUPâ.
FYI Iâm running 2.1.0p4 (if the documentation differs from yours)
What doc are you using? POST to create a rule is documented.
Just go to the i on the top left corner of your checkmk instance and click on REST API documentation
I used the checkmk built-in Swagger UI and also ReDoc but on rulesets there are no POST requests available. I can find POST only on rules but there is no âAssignment of hosts to host groupsâ possible like in the checkmk webfrontend (if you create a hostgroup rule manually).
Thanks
Martin
Edit: I have Checkmk Raw Edition 2.2.0b5, maybe this is only available on a higher tier level?
Well, you wonât find a POST in the rulesets - because you canât create rulesets, only rules.
The âinternalâ name you can use with the API for Assignment of Hosts to host groups is host_groups.
Sorry, i did this one a bit freestyle without testing. This is out of the interactive API:
{
"ruleset": "host_label_rules",
"folder": "~hosts~linux",
"properties": {
"disabled": false
},
"value_raw": "\"{'cmk/os_family': 'linux'}\"",
"conditions": {}
}
Place this in the json from above and edit the attributes to your needs.
The ruleset should be host_groups, your folder should be ~folder (at least I had the best experience doing it like that) and the value_raw should be your Hostgroup like you did. I would recommend you to create a rule in the UI and then make a GET request, look at the JSON structure and compare it with yours and edit it to your needs.