API add contact to contact group

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
btayl
Posts: 131
Joined: Mon Aug 24, 2020 8:51 am

API add contact to contact group

Post by btayl »

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
}'
User avatar
lgute
Posts: 410
Joined: Mon Apr 06, 2020 2:49 pm

Re: API add contact to contact group

Post by lgute »

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.

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"
Response...

Code: Select all

{"success":"Updated <CONTACTGROUP NAME> in the system. Config applied, Nagios Core was restarted."}
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.

Code: Select all

curl -XGET "http://<XI IP ADDRESS>/nagiosxi/api/v1/config/contactgroup?apikey=<TOKEN>&pretty=1"
Which should give you a result like this.

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 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
Please let us know if you have any other questions or concerns.

-Laura
Post Reply