Time Period w/ Service Definitions using Hostgroup Name

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.
sgatepunk
Posts: 3
Joined: Thu May 24, 2012 2:13 pm

Time Period w/ Service Definitions using Hostgroup Name

Post 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.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Time Period w/ Service Definitions using Hostgroup Name

Post by slansing »

To add or change notification time periods please see:

http://nagios.sourceforge.net/docs/3_0/timeperiods.html
sgatepunk
Posts: 3
Joined: Thu May 24, 2012 2:13 pm

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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!
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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.
sgatepunk
Posts: 3
Joined: Thu May 24, 2012 2:13 pm

Re: Time Period w/ Service Definitions using Hostgroup Name

Post by sgatepunk »

So there is no way perhaps to define a notification period for the host and have all of the services inherit?
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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 :)
OUberLord
Posts: 17
Joined: Wed Mar 25, 2015 8:31 am

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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.
Last edited by OUberLord on Tue May 26, 2015 4:40 pm, edited 1 time in total.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Time Period w/ Service Definitions using Hostgroup Name

Post by tgriep »

Can you show how you defined the macro?
Be sure to check out our Knowledgebase for helpful articles and solutions!
OUberLord
Posts: 17
Joined: Wed Mar 25, 2015 8:31 am

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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
        }
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Time Period w/ Service Definitions using Hostgroup Name

Post 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
Former Nagios employee
Locked