API not working as expected in Ansible

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Re: API not working as expected in Ansible

Post by dfmco »

I had broken out the creation of the user because I thought that maybe I had to have it existing BEFORE applying config but that was only a test and I forgot to restore the check back. Sorry for the confusion!

I re-read your ansible config and I must have looked at it 10 times and COMPLETELY MISSED the command vs contact! That was the issue!

Looks like it works well now!

Now that it is working I have 2 related followup questions if you could assist.

1. the documentation shows adding a user looking like this:

Code: Select all

- name: Add sns_critical user to OnShoreITNotificationGroup contact group in Nagios XI
  uri:
   url: http://{{ ansible_host }}/nagiosxi/api/v1/config/contactgroup/testcontactgroup?apikey={{ NagiosAPIKey }}&pretty=1&contactgroup_name=OnshoreITNotificationGroup&members=sns_critical
   method: PUT
   validate_certs: no
   timeout: 30
But I think it should look like this:

Code: Select all

- name: Add sns_critical user to OnShoreITNotificationGroup contact group in Nagios XI
  uri:
   url: http://{{ ansible_host }}/nagiosxi/api/v1/config/contactgroup/testcontactgroup?apikey={{ NagiosAPIKey }}&pretty=1
   body: contactgroup_name=OnshoreITNotificationGroup&members=sns_critical
   method: PUT
   validate_certs: no
   timeout: 30
Can you confirm?

2. Is there a way to check to see if the API call was successful and update to "changed" if I see a "success" to the API call? Unless it totally bombs, I am not sure if it worked or not unless I check it in the GUI. I was hoping you may have an example.

Thanks!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: API not working as expected in Ansible

Post by lmiltchev »

I don't think adding "contactgroup_name=OnshoreITNotificationGroup&members=sns_critical" to the body would work with the PUT method... You should be using:

Code: Select all

- name: Add sns_critical user to OnShoreITNotificationGroup contact group in Nagios XI
  uri:
   url: http://{{ ansible_host }}/nagiosxi/api/v1/config/contactgroup/testcontactgroup?apikey={{ NagiosAPIKey }}&pretty=1&contactgroup_name=OnshoreITNotificationGroup&members=sns_critical&applyconfig=1
   method: PUT
   validate_certs: no
   timeout: 30
You can verify that the contact group was added by running the following command:

Code: Select all

curl -XGET "http://<nagios xi server's ip address>/nagiosxi/api/v1/objects/contactgroup?apikey=<api key>&pretty=1&contactgroup_name=OnshoreITNotificationGroup"
To see the members:

Code: Select all

curl -XGET "http://<nagios xi server's ip address>/nagiosxi/api/v1/objects/contactgroupmembers?apikey=<api key>&pretty=1&contactgroup_name=OnshoreITNotificationGroup"
Be sure to check out our Knowledgebase for helpful articles and solutions!
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Re: API not working as expected in Ansible

Post by dfmco »

Thanks! I did not see applyconfig=1 as an option in the docs but I will add that!

Please close the case. You have been VERY helpful. Off to do some coding!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: API not working as expected in Ansible

Post by scottwilkerson »

dfmco wrote:Thanks! I did not see applyconfig=1 as an option in the docs but I will add that!

Please close the case. You have been VERY helpful. Off to do some coding!
Great!

Locking
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked