Multiple Services with the same Template

I have a template called generic-service that MOST of my services use. When defining my services I’m using the “use generic-service” definition on the majority of services.

I would like to abstract my configurations as much as possible, is there a way to group my services so that I don’t need to put in “use generic-service” in almost every single service definition. I assumed it was what service groups were for, but they just seem to be for better grouping in the GUI.

Here is an example of what I would like to accomplish (DISCLAIMER, I know this won’t work):

;template definition
service{
name generic-service

max_check_attempts 4
normal_check_interval 5
retry_check_interval 1

register 0
}

;service definitions, not that the two services are not using the “use” definition, they should inherit it by being in the service group.
service{
name serviceA
host_name myhost
check_command check_ping
}

service{
name serviceB
host_name myhost
check_command check_email
}

; my two services should inherit definitions in the generic-service template.
servicegroup
{
name myservicegroup
use generic-service
service-name serviceA,serviceB
}

Then if I want to change the name of generic-service, I don’t have to change a gazillion service definition, I just need to change it in the service group.

Any way to accomplish this?

I don’t know of any way to do what you’re asking, but unless you have a lot of differences in your services, there shouldn’t be all that many service stanzas. What I do is apply a service to a hostgroup instead of individual hosts. So, you can create some hostgroup like “basic-services” and then apply all your basic services to that hostgroup.

I think you have to have the use generic-service in there because you need to define where nagios is to start. Generic-service is just a name it could be my-default, because nagios doesn’t know what it means. For the smallest config I found that stacking them is the easiest.

Here is a template that I use. Then I just add more hosts and individual checks for specific servers and at the bottom default checks that apply to all the servers.

Note that generic-host and generic-service contain most of the settings not shown here.

define hostgroup{
hostgroup_name _misc_servers
alias misc_servers
}
#host template for this group
define host {
use generic-host
name misc_group
parents someswitch
check_command check-host-alive
hostgroups misc_servers, other_servers
contact_groups admin-email
register 0
}
#service template for this group
define service {
use generic-service
name misc_svc
hostgroup_name misc_servers
contact_groups admin-email
register 0
}
#actual hosts
define host {
use misc_group
host_name misc_1
address 10.0.0.1
}
#specific check for this host
define service {
use generic-service
service_description serv
check_command check_serv
host_name misc_1
contact_groups admin-email
}

#default checks for all hosts in group, definitions are really small now.
define service {
use misc_svc
service_description ping
check_command check_ping!100.0,20%!500.0,60%
}

define service {
use misc_svc
service_description disk_c
check_command check_nrpe!check_disk_c
}

Hope this helps you make a smaller config and easier to implement one.

Another way to do it if you don’t want to use the host groups is is just by specifying multiple hosts on the same line as follows…

define service {
use generic-service
service_description service1
check_command check_service1
host_name host1,host2,host3,host4,…
contact_groups admin-email
}