How to assign a service group to a host group.

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
nflores
Posts: 4
Joined: Wed Oct 09, 2013 7:24 pm

How to assign a service group to a host group.

Post by nflores »

Any help with my following question would be greatly appreciated.

I am trying to create a group of services that I hope to then assign to a group of hosts. I am not sure if I am going down the correct path by doing the following:

Create a service template that contains a service group as well as a host group

Code: Select all

define service {
  name            generic-web-service
  servicegroup    web-services
  hostgroup_name  web-servers
  .
  .
  .
  register        0
} 
Now I define a host group and a service group each with a few members with the same name as the ones mentioned in the template above.

Code: Select all

# my host group
define hostgroup {
  hostgroup_name   web-servers
  alias            Web Servers
  members          webserver1,webserver2,webserver3
}

# my service group
define servicegroup {
  servicegroup_name      web-services
  alias                  Web services
  members                service1,service2,service3
}
At this point I am confused, because when I go to define my services, it requires me to declare a host_name within it.

Code: Select all

define service {
  use                       generic-web-service
  host_name                 ??
  service_descriptioin      Service 1
  check_command             check_service1!70!90
}
How can I declare my service without giving it a specific host to apply itself to?
Since I have already made it a member of servicegroup web-services will it apply itself to the hostgroup web-servers?

Let me know if this question makes sense or you need more clarification.
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: How to assign a service group to a host group.

Post by jsmurphy »

You are sort of on the right path... Service groups are more for tasks like complex dependencies or SLA reporting.

Instead of attaching the services to a service group attach them directly to the host group, you can do this by using the hostgroup_name directive instead of host_name in your service definition. Example config:

Code: Select all

define service {
        service_description    Windows C: usage
        use                           main-service-template
        hostgroup_name        windowsgroup01,windowsgroup02
        check_command        check_nt!USEDDISKSPACE!-w 80 -c 90
        contact_groups          cg-main,cg-main-SMS
        register                     1
        }
nflores
Posts: 4
Joined: Wed Oct 09, 2013 7:24 pm

Re: How to assign a service group to a host group.

Post by nflores »

Hey jsmurphy thanks for replying.

What happens when I have a hundred+ services that all need to belong to the same host group? I then need to go and edit many service definitions with the hostgroup they should belong to. I'm hoping there was a better way to associate many services to many hosts using grouping.

Can you shed some light on this?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to assign a service group to a host group.

Post by lmiltchev »

I don't believe you can assign a service group to a host group.

http://nagios.sourceforge.net/docs/3_0/ ... tions.html

As jsmurphy said, you can add a service to a hostgroup. Since you have lots of service that you want to add to this hostgroup, you should look for some kind of scripting solution. Doing this manually doesn't seem like a good idea. :)
Be sure to check out our Knowledgebase for helpful articles and solutions!
scar4me
Posts: 2
Joined: Thu Dec 17, 2015 12:08 pm

Re: How to assign a service group to a host group.

Post by scar4me »

As stated above you can't directly assign a service group to host group.

BUT you can do what I've done....
define your hostgroups
define your servicegroups
Define your host template with hostgroup memberships.
Then define your service template with that hostgroup_name listed.
Then define your services from that service-template.

This achieves a centrally defined list of service monitors that apply to specified hostgroups.
Notification control is via the service template, so I leave the check_command line for when we define the service.
The only thing required to initialise a new server is specify the host template to use, and it auto picks up hostgroup, then servicegroup, and all related service monitors.


Host-Template{
name ad-server
use generic-host
hostgroups ad-servers
...}
Service-Template{
name ad-service
hostgroup_name ad-servers
...}
(done in services.cfg)
define service{
use ad-service
service_description CORE AD Services
check_command check_nrpe!check_ad
}


Scar
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: How to assign a service group to a host group.

Post by rkennedy »

Thanks for the contribution @scar4me!
Former Nagios Employee
scar4me
Posts: 2
Joined: Thu Dec 17, 2015 12:08 pm

Re: How to assign a service group to a host group.

Post by scar4me »

Hopefully it'll same other people some time :).
Only been 2weeks since I first installed, and started looking at it.
Using the above method I've just managed to rip out almost all host specific service monitors from my host config files.
Nothing like keeping the config simple, efficient and clutter free!

You can also use this method using the generic-service template to target multiple hostgroups.
(or any other service template which you aren't already specifying the hostgroup names on.)

Just specify then service like this:
define service{
use generic-service
hostgroup_names ad-servers, web-servers, windows-servers
service_description CORE AV Service
check_command check_nt!SERVICESTATE! -l showall -p AVSERVICENAME
}
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: How to assign a service group to a host group.

Post by hsmith »

Thanks again. I'll leave this open for now if anyone has anything else to add.
Former Nagios Employee.
me.
Locked