Email Notification question
Posted: Mon Aug 04, 2014 12:46 pm
Hi All,
I am trying to separate the notification emails for prod and stage servers/services. What I did was to define notification commands fore each environment, separate contact definitions,separate host/service template for each environment.
But for some reason when I get an alert notification for prod server/service, there is a duplicate email for the same server/service alert with a different email heading that points to stage definition. It's very weird, this is what I have
commands
Prod
------
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $LONGHOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s " $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nComment: $SERVICEACKCOMMENT$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}
Stage
-------
# 'notify-host-by-email-stage' command definition
define command{
command_name notify-host-by-email-stage
command_line /usr/bin/printf "%b" "***** Nagios Stage Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $LONGHOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s " $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}
# 'notify-service-by-email-stage' command definition
define command{
command_name notify-service-by-email-stage
command_line /usr/bin/printf "%b" "***** Nagios Stage Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nComment: $SERVICEACKCOMMENT$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}
Contact definitions
----------------------
prod
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
stage
define contact{
name stage-generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email-stage ; send service notifications via email
host_notification_commands notify-host-by-email-stage ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
prod
#######################################################
################# ALERTS SYSTEM #####################
#######################################################
define contact{
use generic-contact
contact_name alerts_system
alias Alerts System
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
email [email protected]
}
stage
#######################################################
################# ALERTS SYSTEM STAGING ##############
#######################################################
define contact{
use stage-generic-contact
contact_name stage-alerts_system
alias Stage-Alerts System
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
email [email protected]
}
define contactgroup{
contactgroup_name apps
alias Application Server Administrators
members alerts_system
}
define contactgroup{
contactgroup_name stage-apps
alias Stage Application Server Administrators
members stage-alerts_system
}
For service I have this template and service defintion
define service{
name mniv-services
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 0
check_freshness 0
notifications_enabled 1
notification_interval 60
notification_period 24x7
notification_options w,u,c,r
contact_groups apps
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
max_check_attempts 3
check_period 24x7
normal_check_interval 3
retry_check_interval 1
action_url /graphs/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/graphs/popup?host=$HOSTNAME$&srv=$SERVICEDESC$'
register 0
}
define service {
use mniv-services
hostgroup_name MNIV
service_description LOAD
check_command check_nrpe!check_load
}
Contact group is set for apps.
So when there is an alert in one of the servers of this MNIV group, I get the following emails, one with stage header, the one without. But since this is a prod server, I shouldn't see the one with Stage in the header.
***** Nagios Stage Alert*****
Notification Type: PROBLEM
Comment:
Service: LOAD
Host: us1map03
Address: xx.xx.4.103
State: WARNING
Date/Time: Mon Aug 4 10:25:15 PDT 2014
Additional Info:
WARNING - load average: 9.58, 10.41, 10.31
***** Nagios*****
Notification Type: PROBLEM
Comment:
Service: LOAD
Host: us1map03
Address: xx.xx.4.103
State: WARNING
Date/Time: Mon Aug 4 10:25:15 PDT 2014
Additional Info:
WARNING - load average: 9.58, 10.41, 10.31
I am trying to separate the notification emails for prod and stage servers/services. What I did was to define notification commands fore each environment, separate contact definitions,separate host/service template for each environment.
But for some reason when I get an alert notification for prod server/service, there is a duplicate email for the same server/service alert with a different email heading that points to stage definition. It's very weird, this is what I have
commands
Prod
------
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $LONGHOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s " $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nComment: $SERVICEACKCOMMENT$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}
Stage
-------
# 'notify-host-by-email-stage' command definition
define command{
command_name notify-host-by-email-stage
command_line /usr/bin/printf "%b" "***** Nagios Stage Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $LONGHOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s " $HOSTNAME$ is $HOSTSTATE$ " $CONTACTEMAIL$
}
# 'notify-service-by-email-stage' command definition
define command{
command_name notify-service-by-email-stage
command_line /usr/bin/printf "%b" "***** Nagios Stage Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\nComment: $SERVICEACKCOMMENT$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /bin/mail -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ " $CONTACTEMAIL$
}
Contact definitions
----------------------
prod
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
stage
define contact{
name stage-generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email-stage ; send service notifications via email
host_notification_commands notify-host-by-email-stage ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
prod
#######################################################
################# ALERTS SYSTEM #####################
#######################################################
define contact{
use generic-contact
contact_name alerts_system
alias Alerts System
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
email [email protected]
}
stage
#######################################################
################# ALERTS SYSTEM STAGING ##############
#######################################################
define contact{
use stage-generic-contact
contact_name stage-alerts_system
alias Stage-Alerts System
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
email [email protected]
}
define contactgroup{
contactgroup_name apps
alias Application Server Administrators
members alerts_system
}
define contactgroup{
contactgroup_name stage-apps
alias Stage Application Server Administrators
members stage-alerts_system
}
For service I have this template and service defintion
define service{
name mniv-services
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 0
check_freshness 0
notifications_enabled 1
notification_interval 60
notification_period 24x7
notification_options w,u,c,r
contact_groups apps
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
max_check_attempts 3
check_period 24x7
normal_check_interval 3
retry_check_interval 1
action_url /graphs/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/graphs/popup?host=$HOSTNAME$&srv=$SERVICEDESC$'
register 0
}
define service {
use mniv-services
hostgroup_name MNIV
service_description LOAD
check_command check_nrpe!check_load
}
Contact group is set for apps.
So when there is an alert in one of the servers of this MNIV group, I get the following emails, one with stage header, the one without. But since this is a prod server, I shouldn't see the one with Stage in the header.
***** Nagios Stage Alert*****
Notification Type: PROBLEM
Comment:
Service: LOAD
Host: us1map03
Address: xx.xx.4.103
State: WARNING
Date/Time: Mon Aug 4 10:25:15 PDT 2014
Additional Info:
WARNING - load average: 9.58, 10.41, 10.31
***** Nagios*****
Notification Type: PROBLEM
Comment:
Service: LOAD
Host: us1map03
Address: xx.xx.4.103
State: WARNING
Date/Time: Mon Aug 4 10:25:15 PDT 2014
Additional Info:
WARNING - load average: 9.58, 10.41, 10.31