Suppress all host notifications

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
ashykneecaps
Posts: 11
Joined: Thu Mar 05, 2015 3:05 am

Suppress all host notifications

Post by ashykneecaps »

Hi, I have a few servers monitored with nagios and among them I have a test server. I would like to know if there is an easy way to suppress all notifications (host and service) caused by this test server without having to double the entries in my services config file.
Perhaps something along the lines of? (which doesn't work btw)

Code: Select all

define host{
  name test-box
  use generic-host
  contact_groups admins
  
  host_notification_period never
  services_notification_period never
}
User avatar
rhassing
Posts: 412
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Suppress all host notifications

Post by rhassing »

Code: Select all

 #Disable notifications for this service 
   notifications_enabled           0
Rob Hassing
Image
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Suppress all host notifications

Post by jdalrymple »

You cannot modify the behavior of services assigned to a host from within the host definition. This would be the best read to understand how that all works:

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

I would probably create non-prod/test host and service templates and apply them to the appropriate hosts and services:

Code: Select all

define host{
     name					test-host-template
     register				0
     use					generic-host
     notifications_enabled	0  
}

define service{
     name					test-service-template
     register				0
     use					generic-service
     notifications_enabled	0  
}

Code: Select all

define host{
	name					test-box
	use						test-host-template
	contact_groups			admins
}

define service{
	name					test-box-service
	use						test-service-template
	contact_groups			admins
}
This would be the proper way to go about it if you have scalability in mind.
User avatar
rhassing
Posts: 412
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Suppress all host notifications

Post by rhassing »

Sorry, my answer was for a service. I didn't read it too well.
Rob Hassing
Image
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Suppress all host notifications

Post by ssax »

OP, let us know if jdalrymple's solution works for you.
ashykneecaps
Posts: 11
Joined: Thu Mar 05, 2015 3:05 am

Re: Suppress all host notifications

Post by ashykneecaps »

Sorry I failed to mention that this test server is set up in the exact same way as many other servers. My services config looks something like this for all my services

Code: Select all

define service {
  hostgroup_name         real-servers,test-servers
  service_description    Current Load
  check_command          check_nrpe_1arg!check_load_nrpe
  use                    generic-service
}
where my test server belongs to the hostgroup called test-servers.
Using a separate service template for what I'm trying to achieve will have me doubling the number of services in my config (unless Im missing something)

Code: Select all

define service {
  hostgroup_name         real-servers
  service_description    Current Load
  check_command          check_nrpe_1arg!check_load_nrpe
  use                    generic-service
}

Code: Select all

define service {
  hostgroup_name         test-servers
  service_description    Current Load
  check_command          check_nrpe_1arg!check_load_nrpe
  use                    test-service-template
}
Is there no other way to suppress notifications on a per host basis?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Suppress all host notifications

Post by jdalrymple »

What you're trying to achieve will work, but it will also be the potential cause for confusion down the road if you have a big environment. There is an implied inheritance builtin to Nagios where that a few host definition objects will be applied downstream to services. See the section in the link I sent you about "Implied Inheritance"

the reason your host definition didn't work is because there are no such directives:

Code: Select all

  host_notification_period never
  services_notification_period never
In order to achieve that implied inheritance you would instead just use:

Code: Select all

define host{
  name test-box
  use generic-host
  contact_groups admins
 
  notification_period none
}
"never" is not a builtin timeperiod, but "none" is so unless you've customized that's what you'll want. You'll also find that this will break if one of the upstream service templates you use defines a notification period - which most of the builtin defaults do.

If you want to do it in a fashion that is more logical and scales better though I'd still recommend sticking with my initial configuration outline. Properly done your "duplicate" service would be comprised of 6 lines:

Code: Select all

define service{
        name                    nonprod-service
        use                     prod-service
        notifications_enabled   0
        hostgroup_name          nonprod
        }
The idea being that later down the road you aren't pulling your hair out trying to identify why you're not getting notifications - in this instance it's very clear why.
ashykneecaps
Posts: 11
Joined: Thu Mar 05, 2015 3:05 am

Re: Suppress all host notifications

Post by ashykneecaps »

Thanks for your advice thus far @jdalrymple

Just out of curiosity, would using service dependencies not be a better solution? Reading up on them, I think I may have found a kind of hack to achieve what I need.
--> Set all services stemming from the test-servers host group to be dependent on a service from a real server, but configured to never notify regardless of the state of its own service or the service it "depends on"

Code: Select all

define servicedependency{
  host_name                      real-server
  service_description            some-service

  dependent_hostgroup_name       test-servers
  dependent_service_description  *

  execution_failure_criteria     n
  notification_failure_criteria  u,w,c,o,p
}
What's your take on this?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Suppress all host notifications

Post by jdalrymple »

Your logic is sound, it *should* work. Here are my observations:

1 - I'm not certain "dependant_hostgroup_name" is a valid directive for a servicedependency
2 - I'm not certain wildcards will expand in dependent_service_descriptions
3 - Doing this would be an edge case where you have 1 (or at least very few) different types of hosts since that's how you're cascading downward, if they're not similar you'll have to create this servicedependency for each different type of host that you have
4 - We're straying back towards the world of "why in the world is it behaving this way"

Unless you have a ridiculous number of services to deploy (and I don't mean service instances, but rather just types of services) the amount of added work to achieve your original goal using templates and hostgroups is truly negligible.

I will concede though that if points 1 & 2 don't prove to be showstoppers then your logic regarding using a servicedependency should create the services for you.
Locked