Page 1 of 1

NagiosXi Add host to hostgroup using api

Posted: Fri Jun 05, 2020 9:01 am
by Bala.Mutyam
Hi,

1) I'm trying to register and add to the host using below Ansible automation but it's not working, please help?

- name: Register Host With XI
uri:
url: http://{{ xi_ip }}/nagiosxi/api/v1/config/host?apikey={{ xi_api_key }}
body: 'host_name={{ ansible_hostname }}&address={{ ansible_hostname }}&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&icon_image=redhat.png&statusmap_image=redhat.png&hostgroup_name=linux-servers'
method: POST
validate_certs: no
timeout: 120

2) Is it possible to remove all alerts for a host from the backend? Currently Nagiosxi keep adding all the old,new checks on to the NCPA UI.

Thanks
Bala

Re: NagiosXi Add host to hostgroup using api

Posted: Fri Jun 05, 2020 2:23 pm
by benjaminsmith
Hi Bala,

A couple of suggestions, as I'm not familiar with how the Ansible Automation is setup, but make sure the apply configuration is called at some point. By default, this does not happen when you create objects form the API, you can simply add the applyconfig=1 parameter to the end of the string.

Next, to add the host to an existing hostgoup, add in the hostrgroups parameter, for example hostgroups=linux-servers, so in curl format, it would like this:

Code: Select all

curl -XPOST "https://192.168.0.11/nagiosxi/api/v1/config/host?apikey=myapikey&pretty=1" -d "host_name=testapihost4&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&hostgroups=linux-servers&applyconfig=1" 
For the second question, could you provide a screenshot of the UI. All of the alerts are stored in the nagios log files, so it's not currently possible to completely delete historical data for a host from the UI. However, we can try to correct the issue, it maybe caused by duplicate services

Re: NagiosXi Add host to hostgroup using api

Posted: Mon Jun 08, 2020 4:46 am
by Bala.Mutyam
Thanks benjaminsmith, hostgroups are working now.

I have attached screenshot of UI, please have a look.

Re: NagiosXi Add host to hostgroup using api

Posted: Mon Jun 08, 2020 3:14 pm
by benjaminsmith
Hi,

Perfect. I appreciate the screenshot. So, NCPA will maintain a local log from check results. You have the option to turn this off completely or reduce the number to days store these checks locally.

To change these settings, navigate to the ncpa.cfg file on the remote host. On Linux systems, it's in the following directory:

Code: Select all

/usr/local/ncpa/etc/
For Windows, go to:

Code: Select all

C:\Program Files (x86)\Nagios\NCPA\etc\
NCPA Configuration

And then modify the settings below, set check_logging = 0 to disable. Be sure to re-start the NCPA listener after making any changes.

Code: Select all

[general]
#
# Check logging (in ncpa.db and the interface) is on by default, you can disable it
# if you do not want to record the check requests that are coming in or checks being
# sent over NRDP.
# Default: check_logging = 1
#
check_logging = 1

#
# Check logging time - how long in DAYS you'd like to keep checks in the database.
# Default: 30
#
check_logging_time = 30
Let me know if you need any assistance.

Benjamin

Re: NagiosXi Add host to hostgroup using api

Posted: Tue Jun 09, 2020 3:57 am
by Bala.Mutyam
@benjaminsmith: Thanks.

Re: NagiosXi Add host to hostgroup using api

Posted: Tue Jun 09, 2020 7:18 am
by scottwilkerson
Bala.Mutyam wrote:@benjaminsmith: Thanks.
Bala.Mutyam May we lock the thread?

Re: NagiosXi Add host to hostgroup using api

Posted: Tue Jun 09, 2020 9:28 am
by Bala.Mutyam
Yes,please.

Re: NagiosXi Add host to hostgroup using api

Posted: Tue Jun 09, 2020 9:38 am
by scottwilkerson
Bala.Mutyam wrote:Yes,please.
Great

Locking thread