Page 1 of 2

Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 11:55 am
by mastermindg
I have a particular host that has daily downtime. I want to disable notification during this period. I have a timeperiod setup for this purpose and I've assigned it to the host:

Code: Select all

define host {
  use server
  address 192.168.1.34
  host_name myserver
  hostgroups linux,database
  notification_period downtime
}
However, I'm still getting alerts for this hosts' services during the downtime window. How can I suppress all notifications for this host during time period downtime?

Re: Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 1:42 pm
by bwallace
To further assist, we'll need to see your 'timeperiods.cfg' file. Could you post that so we can take a look?

It is found under:
/usr/local/nagios/etc/objects

Re: Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 2:19 pm
by mastermindg
I set downtime to 02:00-03:00 so that I can test this. Once I get the notifications to stop coming I'll change it to the correct time.

Code: Select all

define timeperiod {
  timeperiod_name 24x7
  alias           24 Hours A Day, 7 Days A Week
  sunday          00:00-24:00
  monday          00:00-24:00
  tuesday         00:00-24:00
  wednesday       00:00-24:00
  thursday        00:00-24:00
  friday          00:00-24:00
  saturday        00:00-24:00
}

define timeperiod {
  timeperiod_name downtime
  alias           Downtime
  sunday          02:00-03:00
  monday          02:00-03:00
  tuesday         02:00-03:00
  wednesday       02:00-03:00
  thursday        02:00-03:00
  friday          02:00-03:00
  saturday        02:00-03:00
}

Re: Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 3:02 pm
by rkennedy
Let us know how your test goes.

Also - can you post your contact definition as well?

Re: Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 3:08 pm
by bwallace
You could use what you have in conjunction with the 'exclude' directive but that has been unstable. So I would instead opt for method #1, outlined here in this article:
http://www.thegeekstuff.com/2013/09/nagios-timeperiod/

Re: Set Notification Period for Hosts Services

Posted: Fri Mar 04, 2016 8:31 pm
by mastermindg
So the test isn't going well...I'm still getting alerts. I've seen all of the articles on setting timeframes and exclusions but they all deal directly with services. How do I disable notifications for ALL services for a host? My host has quite a few basic services that are are shared with other servers.

Re: Set Notification Period for Hosts Services

Posted: Sun Mar 06, 2016 7:37 pm
by Box293
In the Nagios Core web interface, click the Host.
Under Host Commands click "Disable notifications for all services on this host"

Re: Set Notification Period for Hosts Services

Posted: Sun Mar 06, 2016 8:26 pm
by mastermindg
Box293: Manually selecting "Disable notifications for all services on this host" everyday for eternity is really not a good option for me unless you are volunteering.

Re: Set Notification Period for Hosts Services

Posted: Sun Mar 06, 2016 9:52 pm
by Box293
A service cannot inherit the time period from a host because the documentation states that the "check_period" directive is required.

Because you have shared services, you are running into this problem.

You could:

1) Create dedicated services for this specific host that have a specific check_period defined.

2) Create a cron job that daily schedules the downtime for the host and it's services (run it at 00:05 every day perhaps).
This can be done from the cli.
Following the documentation from:
https://old.nagios.org/developerinfo/ex ... ndlist.php
https://old.nagios.org/developerinfo/ex ... and_id=118
https://old.nagios.org/developerinfo/ex ... and_id=122

We need a command for the host and another command for all of the host's services.
We need three time values in epoch format (the time we are submitting the command, the start time, the end time).

These two commands will do what I have explained for the host "centos01" from 15:00 to 16:00.

Code: Select all

now_epoch=$(eval date +%s); start_epoch=$(date +'%F 15:00:00' | xargs -0 date +%s -d); end_epoch=$(date +'%F 16:00:00' | xargs -0 date +%s -d); printf "[$now_epoch] SCHEDULE_HOST_DOWNTIME;centos01;$start_epoch;$end_epoch;1;0;;nagiosadmin;Daily Donwtime\n" > /usr/local/nagios/var/rw/nagios.cmd

now_epoch=$(eval date +%s); start_epoch=$(date +'%F 15:00:00' | xargs -0 date +%s -d); end_epoch=$(date +'%F 16:00:00' | xargs -0 date +%s -d); printf "[$now_epoch] SCHEDULE_HOST_SVC_DOWNTIME;centos01;$start_epoch;$end_epoch;1;0;;nagiosadmin;Daily Donwtime\n" > /usr/local/nagios/var/rw/nagios.cmd

Re: Set Notification Period for Hosts Services

Posted: Sat Mar 12, 2016 7:56 pm
by mastermindg
I ended up creating custom services for the host. However, this seems like a counter-intuitive way to go about doing what needs to be done here. Is there no way to override the default behavior and have services inherit a hosts notification settings?