[SOLVED]NXI 5.5.2 - Working with API and Ansible

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Aezox
Posts: 25
Joined: Fri Feb 09, 2018 9:31 am

[SOLVED]NXI 5.5.2 - Working with API and Ansible

Post by Aezox »

Hi everyone !

I'm working on a project to automatically deploy Nagios agent and declare new hosts to Nagios using Ansible.

For the declaration part I'm working with APIs using POST method (as defined in the "Help" part of Nagios XI)
I've found one blocking point that someone may have the answer.
When assigning hostgroups to my host I want to automatically set inherit option ("+" ticked in the Manage hostgroups) but I cannot handle myself.
I've try hardcoding "+" on the POST method but nothing works with.
Anyone has a clue please ?

Code: Select all

---
- name: Sending host configuration into Nagios without restarting
  uri:
    url: https://MyNagiosAddress/nagiosxi/api/v1/config/host?apikey=MyAPIKey&pretty=1
    body: 'host_name={{ ansible_hostname }}&alias={{ ansible_fqdn }}&address={{ ansible_default_ipv4.address }}&use={{ nagios_host_template.azure[ansible_local.vdc.location] }}&hostgroups={{ nagios_hostgroup.azure[ansible_local.vdc.location] }}&display_name={{ nagios_host_dp.azure.other }}&max_check_attempts=2&check_period={{ nagios_host_chk_period.azure[ansible_local.vdc.location] }}&contacts=contact_info&notification_interval=1440&notification_period={{ nagios_host_not_period.azure[ansible_local.vdc.location] }}&applyconfig=0'
    method: POST
    validate_certs: no
    timeout: 30
It's not a real blocking point but I would like to find a solution to it

Thank you for your help in avance !
Last edited by Aezox on Wed Apr 10, 2019 2:43 am, edited 1 time in total.
swolf

Re: NXI 5.5.2 - Working with API and Ansible

Post by swolf »

Hi @Aezox,

How exactly did you try to encode the '+'? Following the object inheritance document ("Additive Inheritance of String Values"), you should be able to do what you describe by adding the '+' onto the front of the "hostgroups" specification. I'm not sure if this would work using the config/host endpoint, but it should work using config/import.
Aezox
Posts: 25
Joined: Fri Feb 09, 2018 9:31 am

Re: NXI 5.5.2 - Working with API and Ansible

Post by Aezox »

Hi @swolf,

I did try to put '+' in both below ways :
set '+' after '=' -> &hostgroups=+{{ nagios_hostgroup.azure[ansible_local.vdc.location] }}
set '+' in my "nagios_hostgroup.azure" variable -> nagios_hostgroup.azure = +NameOfMyHostgroup

In both cases it didn't work as expect
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NXI 5.5.2 - Working with API and Ansible

Post by ssax »

Try using %2B (url encoded) instead of the +.

https://meyerweb.com/eric/tools/dencoder/
Aezox
Posts: 25
Joined: Fri Feb 09, 2018 9:31 am

Re: NXI 5.5.2 - Working with API and Ansible

Post by Aezox »

Hi @ssax !
ssax wrote:Try using %2B (url encoded) instead of the +.

https://meyerweb.com/eric/tools/dencoder/
It works ! Thank you !
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NXI 5.5.2 - Working with API and Ansible

Post by scottwilkerson »

Aezox wrote:Hi @ssax !
ssax wrote:Try using %2B (url encoded) instead of the +.

https://meyerweb.com/eric/tools/dencoder/
It works ! Thank you !
Great!

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