Enabling SMTP email alerts

Send alerts to multiple email addresses. Customize the email template for the subject and body of the message.

OpsCenter can send alerts to multiple email addresses. To enable email alerts, edit the config_location/event-plugins/email.conf file and provide valid SMTP server host and port information.

Multiple instances of the email.conf file results in multiple instances of an event plugin. The email configuration file can have any name provided the file has the .conf file extension, contains the valid event plugin identifier [email], and resides in the event-plugins directory location. All configuration files are loaded, so differentiate the file names such as email1.conf, email2.conf, and so on. Multiple plugin instances facilitate flexibility when setting up alerts to different email recipients for development and production clusters. All OpsCenter event plugins support multiple configurations files and subsequent plugin instances.

Prerequisites

Make sure that you have valid SMTP mail accounts to send and receive alerts.

Procedure

  1. On the OpsCenter daemon host, open the email.conf file for editing.
  2. Set enabled to 1.
  3. Provide valid values for your SMTP host, port (25, or 465 if using SSL), user, and password.
  4. For secure communications, enable Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol on your system. Typically, SSL is required.
  5. Provide valid values for the to_addr and from_addr email addresses. The to_addr value is the account that will receive alerts.
    To send alerts to multiple email addresses, enter the email addresses as a comma-delimited list.
  6. Optional: Set the specific levels of alerts to send. The default is to listen for all levels.
  7. Optional: Specify the clusters for which the email alert config will run. The default is to call the alert for events on all clusters.
  8. Optional: Customize the template for the email subject and message body as desired. Available options are described in the config file comments.
  9. Save the configuration file and restart the OpsCenter daemon.

Example

For a configuration with email alerts to multiple recipients enabled for warning and error levels to all clusters, with SSL enabled, the email.conf looks like:

[email]
# set to 1 to enable email
enabled=1

# levels can be comma-delimited list of any of the following: 
# DEBUG,INFO,WARN,ERROR,CRITICAL,ALERT 
# If left empty, will listen for all levels 
levels=WARN,ERROR

# clusters is a comma-delimited list of cluster names for which
# this alert config will be eligible to run.
# If left empty, this alert will be called for events on all clusters
clusters=

smtp_host=smtp.gmail.com
smtp_port=465
smtp_user=mercury@gmail.com
smtp_pass=*********
smtp_use_ssl=1
smtp_use_tls=0
smtp_retries=1
smtp_timeout=5

to_addr=dse_admin@acme.com,devOps@acme.com,opsc_admin@acme.com
from_addr=mercury@gmail.com

# Customizable templates for subject and body. The key specified in {}'s must map to the items provided in json map at the end of
# the emails. For example, some available keys are:
#     node, cluster, datetime, level_str, message, target_node, event_source, success, api_source_ip, user, source_node
# more advanced formatting options explained here: https://docs.python.org/2/library/string.html#formatspec
subject=[{level_str}] OpsCenter Event on {cluster} - {message}

template=Message: {message}  
  Time:    {datetime}  
  Level:   {level_str}  
  Cluster: {cluster}  
  Node:    {node}  
  User:    {user}

Example

A custom email template example:

template=Hey support staff! Wanted to let you know that {cluster} says, {message} This is
{level_str} level, and you may want to check out http://support.lan/opscenter_alerts_guide for further information.

An example email alert:

Example email alert output