Time periods not working for night-time email alerts

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
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Time periods not working for night-time email alerts

Post by Ulfandu »

Hello,

I've been tasked to set up email alerting to our internal administrator team during daytime (06:00-22:00) and to our MSP at night-time (22:00-06:00). Regarding the alerts to the MSP, this only affects a single hostgroup - our VMWare ESXi hosts. I've tested the alerts without the timeperiod-settings configured in the contacts.cfg and both email types were delivered successfully.

However, yesterday at around 21:00 I created a test service for an ESXi host that went critical; our internal team got an alert - which means it works. But when I created a similar alert after 22:00 the MSP email did not receive any messages. I've been going through and through the configuration files but for my life I can't figure out the problem.

The MSP wants a very spesific type of email alert and our internal team is happy with the default message, so I've set up two types of email alert commands:

commands.cfg

Code: Select all

# email alert for company.com admins
define command{
	command_name	notify-service-by-email
	command_line	/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -r nagios@company.com -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
	}


# email alert for msp
define command{
    command_name    notify-service-by-email-msp
    command_line    /usr/bin/printf "%b" "***** Company *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nDescription: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info: $SERVICEDESC$ $SERVICEOUTPUT$\nComment:$SERVICEACKCOMMENT$\nAuthor:$SERVICEACKAUTHOR$\nURL: http://server/nagios/" | /usr/bin/mailx -r nagios@company.com -s "company-Yhtiöt $NOTIFICATIONTYPE$ $SERVICEDESC$ on $HOSTNAME$ is $SERVICESTATE$" $CONTACTEMAIL$
}
Here is the contacts configuration file in which you'll find our internal team and the MSP:
contacts.cfg

Code: Select all

define contact{
		contact_name					john
		use								generic-contact
		email							john@company.com
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
	}

define contact{
        contact_name            		paul
        use                     		generic-contact
        email                   		paul@company.com
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        }

define contact{
        contact_name            		george
        use                     		generic-contact
        email                   		george@company.com
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        }

define contact{
        contact_name	            	msp
        use	                    		generic-contact
		host_notification_period    	22-06
        service_notification_period 	22-06
        email                       	alerts@msp.com
        service_notification_commands   notify-service-by-email-msp
        }

# CONTACT GROUPS

# company.com administrators
define contactgroup {
     contactgroup_name       admins
     alias                   Nagios Administrators
     members                 john,paul,george
     }

# msp 
define contactgroup {
     contactgroup_name       msp
     members		     	 msp
     }
Here are the two different timeperiods I configured:
timeperiods.cfg

Code: Select all

# notification timeperiod for company.com administrators
define timeperiod {

    name                    22-06
    timeperiod_name         22-06
    alias                   8 Hours A Day, 7 Days A Week

    sunday                  22:00-06:00
    monday                  22:00-06:00
    tuesday                 22:00-06:00
    wednesday               22:00-06:00
    thursday                22:00-06:00
    friday                  22:00-06:00
    saturday                22:00-06:00
}

# notification timeperiod for msp
define timeperiod {

    name                    06-22
    timeperiod_name         06-22
    alias                   8 Hours A Day, 7 Days A Week

    sunday                  06:00-22:00
    monday                  06:00-22:00
    tuesday                 06:00-22:00
    wednesday               06:00-22:00
    thursday                06:00-22:00
    friday                  06:00-22:00
    saturday                06:00-22:00
}
Here is the VMWare hostgroup in question:
vmware.cfg

Code: Select all

define host{
        use             vmware-template
        host_name       vmware1
        address         vmware1.company.com
        hostgroups      vmware
        }

define host{
        use             vmware-template
        host_name       vmware2
        address         vmware2.company.com
        hostgroups      vmware
        }

# HOSTGROUP DEFINITIONS

define hostgroup{
       hostgroup_name  vmware
       }

# SERVICE DEFINITIONS

define service{
       use                     generic-service-vmware-nagiosgraph
       host_name               vmware1,vmware2
       service_description     CPU Status
       check_command           check_vmware_api_host_cpu
       }

define service{
       use                     generic-service-vmware-nagiosgraph
       host_name               vmware1,vmware2
       service_description     Memory Status
       check_command           check_vmware_api_host_mem
       }
And lastly, here is templates.cfg for the templates used by the VMware-hostgroup:

Code: Select all

# VMware host definition template

define host{
        name                            vmware-template
        check_period                    24x7            
        check_interval                  5               
        retry_interval                  1               
        max_check_attempts              10              
        check_command                   check-host-alive
        notifications_enabled           1
        event_handler_enabled           1
        flap_detection_enabled          1
        process_perf_data               1
        retain_status_information       1
        retain_nonstatus_information    1
        notification_period             24x7       
        notification_interval           0             
        notification_options            d,u         
        contact_groups                  admins
        first_notification_delay        1
        register                        0
        icon_image                      vmware.png
        }

# VMware generic service
define service{
        name                            generic-service-vmware
        active_checks_enabled           1
        passive_checks_enabled          1
        parallelize_check               1
        obsess_over_service             1
        check_freshness                 0
        notifications_enabled           1
        event_handler_enabled           1
        flap_detection_enabled          1
        process_perf_data               1
        retain_status_information       1
        retain_nonstatus_information    1
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              10
        check_interval                  5
        retry_interval                  1
        contact_groups                  admins,msp
        first_notification_delay        1
        notification_options            u,c
        notification_interval           0
        notification_period             24x7
        register                        0
        process_perf_data               1         
        }

# VMWarelle generic service with PNP4Nagios graphing 
define service{
        name                            generic-service-vmware-pnp4nagios
        active_checks_enabled           1
        passive_checks_enabled          1
        parallelize_check               1
        obsess_over_service             1
        check_freshness                 0
        notifications_enabled           1
        event_handler_enabled           1
        flap_detection_enabled          1
        process_perf_data               1
        retain_status_information       1
        retain_nonstatus_information    1
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              10
        check_interval                  5
        retry_interval                  1
        contact_groups                  admins,msp
        first_notification_delay        1
        notification_options            u,c
        notification_interval           0
        notification_period             24x7
        register                        0
        process_perf_data               1         
		action_url              		/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
        }
Any help will be very much appreciated!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Time periods not working for night-time email alerts

Post by scottwilkerson »

This timeperiod is the problem because they cannot cross the 24:00 boundry as it is the next day

Code: Select all

# notification timeperiod for company.com administrators
define timeperiod {

    name                    22-06
    timeperiod_name         22-06
    alias                   8 Hours A Day, 7 Days A Week

    sunday                  22:00-06:00
    monday                  22:00-06:00
    tuesday                 22:00-06:00
    wednesday               22:00-06:00
    thursday                22:00-06:00
    friday                  22:00-06:00
    saturday                22:00-06:00
}
I would suggest changing it to

Code: Select all

# notification timeperiod for company.com administrators
define timeperiod {

    name                    22-06
    timeperiod_name         22-06
    alias                   8 Hours A Day, 7 Days A Week

    sunday                  22:00-24:00,00:00-06:00
    monday                  22:00-24:00,00:00-06:00
    tuesday                 22:00-24:00,00:00-06:00
    wednesday               22:00-24:00,00:00-06:00
    thursday                22:00-24:00,00:00-06:00
    friday                  22:00-24:00,00:00-06:00
    saturday                22:00-24:00,00:00-06:00
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Time periods not working for night-time email alerts

Post by Ulfandu »

Thank you very much! This must be what was wrong.

I will be testing this tonight, and I'll report back if it worked.
User avatar
Ulfandu
Posts: 26
Joined: Thu Jun 14, 2018 4:53 am

Re: Time periods not working for night-time email alerts

Post by Ulfandu »

Everything worked just as planned. Thank you!

Thread can be marked as solved.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Time periods not working for night-time email alerts

Post by scottwilkerson »

Ulfandu wrote:Everything worked just as planned. Thank you!

Thread can be marked as solved.
Great!

Locking
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked