NagiosXi Add host to hostgroup using api

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

NagiosXi Add host to hostgroup using api

Post 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
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NagiosXi Add host to hostgroup using api

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi Add host to hostgroup using api

Post by Bala.Mutyam »

Thanks benjaminsmith, hostgroups are working now.

I have attached screenshot of UI, please have a look.
You do not have the required permissions to view the files attached to this post.
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: NagiosXi Add host to hostgroup using api

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi Add host to hostgroup using api

Post by Bala.Mutyam »

@benjaminsmith: Thanks.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NagiosXi Add host to hostgroup using api

Post by scottwilkerson »

Bala.Mutyam wrote:@benjaminsmith: Thanks.
Bala.Mutyam May we lock the thread?
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Bala.Mutyam
Posts: 97
Joined: Wed Apr 29, 2020 12:18 pm

Re: NagiosXi Add host to hostgroup using api

Post by Bala.Mutyam »

Yes,please.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: NagiosXi Add host to hostgroup using api

Post by scottwilkerson »

Bala.Mutyam wrote:Yes,please.
Great

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