Page 1 of 2
Time Period w/ Service Definitions using Hostgroup Name
Posted: Mon Nov 26, 2012 4:04 pm
by sgatepunk
I have a question.
I have several service definitions in place using the hostgroup name, so that we can simply add a host to the hostgroup and the host will automatically start using those service definitions.
My issue is as follows, not all of the hosts in that hostgroup will have the same maintenance window, so how can I set different notification periods for the hosts utilizing these service definitions?
Any help would be greatly appreciated.
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Mon Nov 26, 2012 4:12 pm
by slansing
To add or change notification time periods please see:
http://nagios.sourceforge.net/docs/3_0/timeperiods.html
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Mon Nov 26, 2012 4:52 pm
by sgatepunk
I have read through the documentation on time periods a couple of times, and I am still at a loss as to how apply a time period to a single service definition that uses a host group, when I only want that notification period to apply to one of the hosts in that host group. Maybe an example would clarify.
I have several separate MS Exchange 2010 environments I am monitoring. I have created a host group with all of the Exchange 2010 hosts in that group. I then created a set of service definitions for MS Exchange 2010 that use the MS Exchange 2010 host group in them, so that when a host is added to the host group it will get all of the checks automatically. My problem is that one Exchange 2010 environment will have a different maintenance window then another, so I can not think of a way to single out certain hosts in that group and apply a notification period on those services without doing the whole group.
define hostgroup {
hostgroup_name Application Exchange 2010
alias Application Exchange 2010
members HostA,HostB,HostC,HostD
}
define service {
service_description Services - Exchange 2010
use Generic Service No Warning
hostgroup_name Application Exchange 2010
check_command check_nrpe!CheckServiceState!ShowAll MSExchangeADTopology MSExchangeIS MSExchangeMailSubmission MSExchangeMailboxAssistants MSExchangeRepl MSExchangeRPC MSExchangeSearch MSExchangeServiceHost MSExchangeSA MSExchangeThrottling MSExchangeTransportLogSearch IISADMIN W3SVC LanmanServer LanmanWorkstation WinRM RMAgentPS RM_ExchangeInterface
}
With the setup above any host in the "Application Exchange 2010" hostgroup gets the "Services - Exchange 2010" service check. But say I wanted setup a notification period to suppress alerts for HostA and HostC, but NOT HostB and HostD. I am not sure of a way to accomplish this. I am thinking that maybe I might be able to pull it off with some sort of service dependency but am unsure as of right now.
Any help is greatly appreciated, thanks!
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Mon Nov 26, 2012 6:26 pm
by jsmurphy
With Nagios core and using your current methodology you can't actually achieve the result you are looking for. We use the same method for host/service relationships and we got caught out once or twice when we were using core and just had to separate the services out.
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Thu Dec 06, 2012 1:56 pm
by sgatepunk
So there is no way perhaps to define a notification period for the host and have all of the services inherit?
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Thu Dec 06, 2012 7:00 pm
by jsmurphy
I was about to say "no way, not possible, absolutely not"... though you may be a genius for phrasing the question exactly like that, I just had an idea on how you might actually be able to work around it:
define host {
host_name exchange-server
hostgroups Application Exchange 2010
_TIMEINTERVAL time_period_name1
}
define service {
service_description Services - Exchange 2010
use Generic Service No Warning
hostgroup_name Application Exchange 2010
check_command check_nrpe!CheckServiceState!ShowAll MSExchangeADTopology MSExchangeIS MSExchangeMailSubmission MSExchangeMailboxAssistants MSExchangeRepl MSExchangeRPC MSExchangeSearch MSExchangeServiceHost MSExchangeSA MSExchangeThrottling MSExchangeTransportLogSearch IISADMIN W3SVC LanmanServer LanmanWorkstation WinRM RMAgentPS RM_ExchangeInterface
notification_period $_HOSTTIMEINTERVAL$
}
define timeperiod {
name time_period_name1
... time info here ...
}
I'm not 100% sure this will work, but I don't see why it wouldn't. This is using a feature called custom macros:
http://nagios.sourceforge.net/docs/3_0/macros.html hopefully this helps

Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Tue May 26, 2015 4:08 pm
by OUberLord
Not to necro this thread, but I went about testing this idea in Nagios 4 as I am looking to find a means of doing the same thing that the OP was wanting. Unfortunately, and at least with Nagios 4, this does not seem to function. When it is attempted, it yields the following error:
Code: Select all
Error: notification_period '$_HOSTSVCNOTFINT$' for service 'servicename' on host 'hostname' could not be found!
Error: Could not register service (config file '/etc/nagios/objects/services/services.cfg', starting on line 121)
Error processing object config files!
Oddly, if I try to use the host custom macro for the service's notes value such as in the following...
Code: Select all
define service{
name workhours
use generic-service
check_period 24x7
notes $_HOSTSVCNOTFINT$
notification_period workhours
register 0
}
...it shows the contents of the host custom macro in the notes as expected. It just will not work if I try to use it to define the notification_period.
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Tue May 26, 2015 4:35 pm
by tgriep
Can you show how you defined the macro?
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Tue May 26, 2015 4:41 pm
by OUberLord
I have it defined as part of the templates file:
Code: Select all
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 0 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time
_SVCNOTFINT 24x7
max_check_attempts 3
check_command check-host-alive
check_interval 1
contacts pagerduty-nagios
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
define host{
name generic-host-workhours
use generic-host
notification_period workhours
_SVCNOTFINT workhours
register 0
}
Re: Time Period w/ Service Definitions using Hostgroup Name
Posted: Wed May 27, 2015 2:13 pm
by tmcdonald
Services will automatically pick up the notification_period of a host if one is not set on the service. It is called Implied Inheritance:
http://nagios.sourceforge.net/docs/3_0/ ... nheritance