Nagios 5.6.2 on CentOS 7 using RPM install.
This command seems to work fine and adds the user with all settings:
"http://<REDACTED>/nagiosxi/api/v1/config/contact?apikey=<REDACTED>&pretty=1" -d "contact_name=pagerduty&host_notifications_enabled=1&service_notifications_enabled=1&host_notification_period=24x7&service_notification_period=24x7&host_notification_options=d,r&service_notification_options=w,u,c,f,r&host_notification_commands=notify-host-by-pagerduty&service_notification_commands=notify-service-by-pagerduty&applyconfig=1"
I tried to send this from Ansible and the contact is created but set to disabled so the rest of the configuration is not applied. I tried splitting the command into 2 parts to create the user first then configure but the user is still not enabled so the settings task does not work.
- name: Create pagerduty contact in Nagios XI
uri:
url: http://{{ ansible_host }}/nagiosxi/api/v1/config/command?apikey={{ API_Key }}&pretty=1
body: 'contact_name=pagerduty&applyconfig=1'
method: POST
validate_certs: no
timeout: 30
- name: Assign configurations to pagerduty contact in Nagios XI
uri:
url: http://{{ ansible_host }}/nagiosxi/api/v1/config/command?apikey={{ API_Key }}&pretty=1
body: 'contact_name=pagerduty&host_notifications_enabled=1&service_notifications_enabled=1&host_notification_period=24x7&service_notification_period=24x7&host_notification_options=d,r&service_notification_options=w,u,c,f,r&host_notification_commands=notify-host-by-pagerduty&service_notification_commands=notify-service-by-pagerduty&applyconfig=1'
method: POST
validate_certs: no
timeout: 30
How can I create and ENABLE a user from Ansible using the API?
API not working as expected in Ansible
Re: API not working as expected in Ansible
I tried adding a contact in Nagios XI 5.6.4 (CentOS 7) via Ansible, and didn't have any issues. My contact is enabled, and configuration applied. I didn't use variables for the IP and the API key in my playbook, and used otify-host-by-email and notify-service-by-email commands as I don't have pagerduty commands defined. Anyway, here is my playbook:
More info:
You may want to upgrade your Nagios XI to 5.6.4 and give it a try. You are entitled to a test server, so try it first in a test environment before applying it to production.
https://support.nagios.com/kb/article/n ... s-145.html
Code: Select all
---
- name: Test
hosts: xicentos
connection: ssh
gather_facts: True
tasks:
- name: Add contact
uri:
url: http://192.168.18.1/nagiosxi/api/v1/config/contact?apikey=xxx&pretty=1
body: 'contact_name=pagerduty&host_notifications_enabled=1&service_notifications_enabled=1&host_notification_period=24x7&service_notification_period=24x7&host_notification_options=d,r&service_notification_options=w,u,c,f,r&host_notification_commands=notify-host-by-email&service_notification_commands=notify-service-by-email&applyconfig=1'
method: POST
validate_certs: no
timeout: 30You may want to upgrade your Nagios XI to 5.6.4 and give it a try. You are entitled to a test server, so try it first in a test environment before applying it to production.
https://support.nagios.com/kb/article/n ... s-145.html
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API not working as expected in Ansible
I will push out a test instance and see where it goes from there.
Re: API not working as expected in Ansible
Sure. You can also try "hard-coding" the IP and the API key, just to rule out an issue with the way variables are used in the playbook. Let us know how it goes.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API not working as expected in Ansible
A fresh RPM build on 5.6.3 is failing to update to 5.6.5 so I have an open ticket for that.
Re: API not working as expected in Ansible
Noted. Do you have any further questions on the original (API) issue or it's ok to close this topic?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API not working as expected in Ansible
I want to revisit this as soon as we get updated to the version you say is working. Please hold this open.
Thanks!
Thanks!
Re: API not working as expected in Ansible
Sounds good. We will keep the topic open for the time being.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: API not working as expected in Ansible
Version update is working so I ran the play again and the contact is still showing up as inactive. Here is the play:
- name: Create pagerduty contact in Nagios XI
uri:
url: http://{{ ansible_host }}/nagiosxi/api/v1/config/command?apikey={{ NagiosAPIKey }}&pretty=1
body: 'contact_name=pagerduty&applyconfig=1'
method: POST
validate_certs: no
timeout: 30
The user is created but left inactive.
- name: Create pagerduty contact in Nagios XI
uri:
url: http://{{ ansible_host }}/nagiosxi/api/v1/config/command?apikey={{ NagiosAPIKey }}&pretty=1
body: 'contact_name=pagerduty&applyconfig=1'
method: POST
validate_certs: no
timeout: 30
The user is created but left inactive.
Re: API not working as expected in Ansible
First off, I am not sure if this is a typo, but you have this:
In the "body", you have:
I showed you my playbook, which is working. Can you try using it as I showed you?
but you should have this:url: http://{{ ansible_host }}/nagiosxi/api/v1/config/command?apikey={{ NagiosAPIKey }}&pretty=1
Second, you cannot add a contact successfully, when you are NOT passing ALL of the required options...url: http://{{ ansible_host }}/nagiosxi/api/v1/config/contact?apikey={{ NagiosAPIKey }}&pretty=1
In the "body", you have:
but you should have a lot more than that...body: 'contact_name=pagerduty&applyconfig=1'
I showed you my playbook, which is working. Can you try using it as I showed you?
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!