Hello,
I couldn't find an answer for this, but it seems that when creating a service (or updating one via put) the contact is only set as the last value given in a list. The following code creates the service:
body = {
"host_name": "edge",
"service_description": "PEERING_123",
"check_command": "bgp_edge_check!edge01!edge02!!!!1!100!snmp",
"max_check_attempts": "3",
"check_period": "24x7",
"check_interval": "3",
"retry_interval": 3,
"notification_period": "24x7",
"notification_interval": "60",
"contacts": ["slack_support", "support"],
}
requests.post(url="https://10.0.0.50/nagiosxi/api/v1/config/service/", data=body, params=params, verify=False)
But it only has one contact "support" when I open it in the GUI. Is it possible to set multiple contacts via the API?
[API] Possible to add multiple contacts when creating a service?
- jmichaelson
- Posts: 383
- Joined: Wed Aug 23, 2023 1:02 pm
Re: [API] Possible to add multiple contacts when creating a service?
The API reference documentation at /nagiosxi/help/ uses query parameters as its examples. While it doesn't document how to go about adding multiple contacts to a host in this way, I'd try using some of the examples from /nagiosxi/help/api-common-solutions.php as guides, and using something like &contacts[]=slack_support&contacts[]=support.
Please let us know if you have any other questions or concerns.
-Jason
-Jason
Re: [API] Possible to add multiple contacts when creating a service?
I do this a ton in Python...
Modify your list format
--SN
Modify your list format
Change to this and see what you get"contacts": ["slack_support", "support"],
Code: Select all
"contacts": ["slack_support, support"],Re: [API] Possible to add multiple contacts when creating a service?
Oh my word, this did the trick it looks like. Thank you!snapier3 wrote: ↑Mon May 20, 2024 2:56 pm I do this a ton in Python...
Modify your list formatChange to this and see what you get"contacts": ["slack_support", "support"],
--SNCode: Select all
"contacts": ["slack_support, support"],