Automated Nagios Registering and Service Setup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
tsalata
Posts: 1
Joined: Mon Mar 25, 2019 5:04 pm

Automated Nagios Registering and Service Setup

Post by tsalata »

Hello,

I'm working on a project with Ansible and Nagios. The goal is to automated the registering of servers and services of all the servers in our Ansible cluster and have them report in Nagios XI. We are running Nagios XI 5.5.11 (offline install), on RHEL 7.5 (64 bit) minimal.

So far I have found the example ansible automation provided in the XI installation:

Code: Select all

vim /usr/local/nagiosxi/scripts/automation/ansible/ncpa_autoregister/
I have managed to register the servers themselves in Nagios via the rest endpoint:

Code: Select all

    - name: Register Host With XI
      uri:
        url: http://<hostname.domain.of.XI.host>/nagiosxi/api/v1/config/host?apikey=APIKEYHERE&pretty=1
        body: 'host_name={{ ansible_fqdn }}&address={{ ansible_default_ipv4.address }}&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1'
        method: POST
        validate_certs: no
        timeout: 120
However, when I try and actual register services I am told that the service worked (CCM doesn't show a failure in the config, but the service doesn't show up in the Services UI):

Code: Select all

Successfully added <HOSTNAME.DOMAIN>:: Test Service: Apache to the system. Config applied, Nagios Core was restarted.
The rest call that I'm trying to make is:

Code: Select all

    - name: Register Service example
      uri:
        url: https://<hostname.domain.of.XI.host>/nagiosxi/api/v1/config/service?apikey=APIKEYHERE&pretty=1
        body: 'host_name={{ ansible_fqdn }}&address={{ ansible_default_ipv4.address }}&service_description=Testing&check_command=check_xi_service_status\-t COMMUNITY-STRING-HERE -P 5693 -M services -q service=NetworkManager,status=running%&check_interval=5&retry_interval=5&max_check_attempts=3&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1'
        method: POST
        validate_certs: no
        timeout: 120
I have a two immediate questions:
1. Am I missing something very easy with the check_xi_service_status module?
2. Should I be using a different module rather than the check_xi_service_status module?

Thank you!
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Automated Nagios Registering and Service Setup

Post by cdienger »

You would want to use the check_xi_ncpa command and &address isn't needed. Try this:

Code: Select all

    - name: Register Service example
      uri:
        url: https://<hostname.domain.of.XI.host>/nagiosxi/api/v1/config/service?apikey=APIKEYHERE&pretty=1
        body: 'host_name={{ ansible_fqdn }}&service_description=Testing&check_command=check_xi_ncpa\!-t COMMUNITY-STRING-HERE -P 5693 -M services -q service=NetworkManager,status=running%&check_interval=5&retry_interval=5&max_check_attempts=3&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1'
        method: POST
        validate_certs: no
        timeout: 120
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Automated Nagios Registering and Service Setup

Post by npolovenko »

@tsalata, Not sure if you've seen the video we have explaining how to use this Ansible script:
https://www.youtube.com/watch?v=Vkwf5Rp3Kj4

Which version of XI are you running? Can you go to the Help menu, click on the Config Reference menu and try to submit a POST config/host command and see if the host gets added to the GUI.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked