through the API add contact to contact group the following does not work
curl -k -XPUT "https://nagiosxi.med.umich.edu/nagiosxi ... JUkS03eQ5l" \
-H "Content-Type: application/json" \
-d '{
"contactgroup_name": "CDIS Team_all",
"members": "contact_to_add",
"applyconfig": 1
}'
API add contact to contact group
Re: API add contact to contact group
Hi @btayl,
It looks like the syntax is slightly off. The syntax for the contactgroup endpoints is singular, so contactgroup instead of contactgroups.
nagiosxi/api/v1/config/contactgroup/.
Since you want to add a contact to the contact group, all you need for the "Optional parameters" is members.
So the full statement to "Edit a ContactGroup" should look something like this.
Response...
IMPORTANT: to add a contact to a group, you do need to include the current contacts, as well as the new contact in the "members" list. For example, if the contact group contains 2 contacts (contact1 & contact2), "members=" needs to be members=contact1,contact2,contact_to_add.
To verify the change, you can list the contactgroups. "&pretty=1" is optional.
Which should give you a result like this.
The documentation for the API can be found at http://<XI IP ADDRESS>/nagiosxi/help/index.php#
The reference for this endpoint is http://<XI IP ADDRESS>/nagiosxi/help/api-config-reference.php#edit-contactgroup
It looks like the syntax is slightly off. The syntax for the contactgroup endpoints is singular, so contactgroup instead of contactgroups.
nagiosxi/api/v1/config/contactgroup/.
Since you want to add a contact to the contact group, all you need for the "Optional parameters" is members.
So the full statement to "Edit a ContactGroup" should look something like this.
Code: Select all
curl -XPUT "http://<XI IP ADDRESS>/nagiosxi/api/v1/config/contactgroup/<CONTACTGROUP NAME>?apikey=<TOKEN>&members=contact1,contact2,contact_to_add&applyconfig=1"
Code: Select all
{"success":"Updated <CONTACTGROUP NAME> in the system. Config applied, Nagios Core was restarted."}
To verify the change, you can list the contactgroups. "&pretty=1" is optional.
Code: Select all
curl -XGET "http://<XI IP ADDRESS>/nagiosxi/api/v1/config/contactgroup?apikey=<TOKEN>&pretty=1"
Code: Select all
[
{
"contactgroup_name": "admins",
"alias": "Nagios Administrators",
"members": [
"nagiosadmin"
]
},
{
"contactgroup_name": "test_group",
"alias": "TEST GROUP",
"members": [
"contact1",
"contact2",
"contact_to_add"
]
},
{
"contactgroup_name": "xi_contactgroup_all",
"alias": "All Contacts"
}
]
The reference for this endpoint is http://<XI IP ADDRESS>/nagiosxi/help/api-config-reference.php#edit-contactgroup
Please let us know if you have any other questions or concerns.
-Laura
-Laura