Adding a new host for monitoring

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
ets_user
Posts: 78
Joined: Mon Mar 30, 2020 2:50 am

Adding a new host for monitoring

Post by ets_user »

Hi,

We would like to write an automated script to add any new hosts to Nagios for monitoring.

This helps when we have huge number of servers to be added at once, takes time if we use Nagios XI.

Could you please let us know if we can do this way, if so how can we ?

Add a host to nagios monitoring by backend in nagios server and not through Nagios XI.
Map the host to the host group by backend in nagios server and not through Nagios XI.


We already have services mapped to hostgroup so it will work from there on.

Thanks.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Adding a new host for monitoring

Post by ssax »

You can use the API, that's the best method that you can use. See the API section under the Help menu for working examples. See here specifically:

Code: Select all

http://YOURXISERVER/nagiosxi/help/api-config-reference.php#add-host
Or you can manually manage them (they won't be listed in the CCM then):

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Technically, you can create the configs and then import them as well:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Let us know if you have any questions.
ets_user
Posts: 78
Joined: Mon Mar 30, 2020 2:50 am

Re: Adding a new host for monitoring

Post by ets_user »

Thanks for the link, it helped us.

We were able to add new host using the command.

Could you please let us know if we can add the host to a particular host group using command line.

We didn't find such thing in the link, though we were able to create host group using command line.

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

Re: Adding a new host for monitoring

Post by scottwilkerson »

Yes, if using the API you would add the following to the string after -d &hostgroups=YOURHOSTGROUP

In the other scenarios you would add it inside the host define like

Code: Select all

hostgroups               YOURHOSTGROUP
In both cases the hostgroup must previously exist
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ets_user
Posts: 78
Joined: Mon Mar 30, 2020 2:50 am

Re: Adding a new host for monitoring

Post by ets_user »

Hi,

This command is not working.

curl -XPOST "https://10.106.93.70/nagiosxi/api/v1/co ... y&pretty=1" -d "host_name=testapihost1&address=127.0.0.1&hostgroups=Linux_server_VM&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" -k

It is not adding the host to the hostgroup.

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

Re: Adding a new host for monitoring

Post by scottwilkerson »

Hmm, I just tested this on a 5.7.1 system and it worked as expected. Do you have a host group named Linux_server_VM specifically with underscores and case sensitive?
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ets_user
Posts: 78
Joined: Mon Mar 30, 2020 2:50 am

Re: Adding a new host for monitoring

Post by ets_user »

Yes we do have it with same name.

But still host is not getting added to the hostgroup.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Adding a new host for monitoring

Post by scottwilkerson »

ets_user wrote:Yes we do have it with same name.

But still host is not getting added to the hostgroup.
What version of Nagios XI are you running?
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ets_user
Posts: 78
Joined: Mon Mar 30, 2020 2:50 am

Re: Adding a new host for monitoring

Post by ets_user »

It is Nagios XI 5.5.6 .
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Adding a new host for monitoring

Post by scottwilkerson »

Adding hostgroups and servicegroups was not added until 5.6.0
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked