API not working as expected in Ansible
Posted: Thu Jul 11, 2019 9:50 am
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?
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?