Listing all hosts in one file? Need help with Hosts and Serv


#1

I have about 50 hosts I am trying to configure to use with Nagios right now. The problem I am having is that every time I add a host I have to create the host in hosts.cfg and then add their service for Nagios to monitor in the services.cfg file. So for example I want to check PING, HTTP, and HTTPS for 50 hosts, do I have to add each host in hosts.cfg and then add 3 entries in services.cfg for all 50 hosts? I was hoping there would be an easy way I could just put all the hosts in one file and not have to make the 3 entries in services.cfg. Any help is greatly appreciated. Thanks guys!!


#2

You can do it by hostgroup. You add the hosts to the hostgroups.cfg file then add an entry to services.cfg that is for the entire hostgroup. An example from ours:

------------------ Local LINUX GLOBAL Services definition ------------------

define service{
use generic-service
hostgroup_name 05-local-linux-servers
service_description # PING
contact_groups ux-admins, noc-op
check_command check_tcp!22
}

This will do a ping (actually check_tcp which isn’t exactly the same as ping but has a similar purpose - to let you know the IP is reachable). It does it on all the hosts in the hostgroup 05-local-linux-servers which is defined in the hostgroups.cfg file. Note all the hosts there have to have been configured in hosts.cfg.

I’d recommend you separate out the types of servers (Linux, Windows, HP-UX, Solaris etc…) into separate hostgroups. This way as you add services later you can make sure they are accessible from the specific type you are doing. Some commands will work on all OSs but some are OS specific.


#3

Gee, I didn’t know you could define a services.cfg entry like that. Is that for v1.2 also? I don’t see in the docs that there is a directive called “hostgroup_name” for servcies.cfg? How did you find this out?

But notice, he did have to define each and every host in hosts.cfg though, just not a service for each one, but for a whole group.