Page 1 of 2
Adding a new host for monitoring
Posted: Wed Jul 15, 2020 6:55 am
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.
Re: Adding a new host for monitoring
Posted: Wed Jul 15, 2020 5:45 pm
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.
Re: Adding a new host for monitoring
Posted: Tue Jul 21, 2020 2:31 pm
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.
Re: Adding a new host for monitoring
Posted: Tue Jul 21, 2020 2:40 pm
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
In both cases the hostgroup must previously exist
Re: Adding a new host for monitoring
Posted: Thu Jul 23, 2020 5:42 am
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¬ification_interval=5¬ification_period=24x7&applyconfig=1" -k
It is not adding the host to the hostgroup.
Kindly advise.
Re: Adding a new host for monitoring
Posted: Thu Jul 23, 2020 8:23 am
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?
Re: Adding a new host for monitoring
Posted: Mon Aug 03, 2020 2:15 am
by ets_user
Yes we do have it with same name.
But still host is not getting added to the hostgroup.
Re: Adding a new host for monitoring
Posted: Mon Aug 03, 2020 7:37 am
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?
Re: Adding a new host for monitoring
Posted: Tue Aug 11, 2020 2:56 am
by ets_user
It is Nagios XI 5.5.6 .
Re: Adding a new host for monitoring
Posted: Tue Aug 11, 2020 7:05 am
by scottwilkerson
Adding hostgroups and servicegroups was not added until 5.6.0