Email

ENTERPRISE: Built-in integrations are available for Sensu Enterprise users only.

Overview

Send email notifications for events, using SMTP.

Custom email templates

As of Sensu Enterprise version 2.3, the Sensu Enterprise email integration provides support for creating custom email templates using ERB (a templating language based on Ruby). Sensu Enterprise makes an @event variable available to the ERB template containing the complete event data payload.

NOTE: the Puppet reference documentation provides a helpful introduction to ERB templating syntax.

Example(s)

The following examples demonstrate how to access the Sensu @event variable from custom ERB templates.

NOTE: The body template example includes the datacenter attribute, which is only available to be used in a template when defined as a client custom attribute

/etc/sensu/email/subject_template.erb

<%= ["ok","warning","critical","unknown"][@event[:check][:status]] %> - <%= @event[:client][:name] %>/<%= @event[:check][:name] %>: <%= @event[:check][:output] %>

/etc/sensu/email/body_template.erb

Hi there,

Sensu has detected a <%= @event[:check][:name] %> monitoring event.
Please note the following details:

Client: <%= @event[:client][:name] %>

Check: <%= @event[:check][:name] %>

Output: <%= @event[:check][:output] %>

For more information, please consult the Sensu Enterprise dashboard:

https://sensu.example.com/#/client/<%= @event[:client][:datacenter] %>/<%= @event[:client][:name] %>?check=<%= @event[:check][:name] %>

#monitoringlove,
Team Sensu

Configuration

Example(s)

The following is an example configuration for the email enterprise event handler (integration).

{
  "email": {
    "smtp": {
      "address": "smtp.example.com",
      "port": 587,
      "openssl_verify_mode": "none",
      "enable_starttls_auto": true,
      "authentication": "plain",
      "user_name": "postmaster@example.com",
      "password": "SECRET"
    },
    "to": "support@example.com",
    "from": "noreply@example.com",
    "content_type": "text/plain",
    "timeout": 10
  }
}

Integration specification

email attributes

The following attributes are configured within the {"email": {} } configuration scope.

smtp
description A set of attributes that provides SMTP connection information to the email event handler.
required false
type Hash
default
"smtp": {
  "address": "127.0.0.1",
  "port": 25,
  "domain": "localhost.localdomain",
  "openssl_verify_mode": "none",
  "enable_starttls_auto": true,
  "user_name": null,
  "password": null,
  "authentication": "plain"
}
example
"smtp": {
  "address": "smtp.example.com",
  "port": 587
}
to
description The default email address to send notification to.
required false
type String
default root@localhost
example
"to": "support@example.com"
from
description The default email address to use as the sender.
required false
type String
default sensu@localhost
example
"from": "noreply@example.com"
content_type
description The email content type header. Can be used to enable HTML body content.
required false
type String
default text/plain
example
"content_type": "text/html"
templates
description A set of attributes that provides email templates configuration.
required false
type Hash
example
"templates": {
  "subject": "/etc/sensu/email/subject_template.erb",
  "body": "/etc/sensu/email/body_template.erb"
}
filters
description An array of Sensu event filters (names) to use when filtering events for the handler. Each array item must be a string. Specified filters are merged with default values.
required false
type Array
default
["handle_when", "check_dependencies"]
example
"filters": ["recurrence", "production"]
severities
description An array of check result severities the handler will handle. NOTE: event resolution bypasses this filtering.
required false
type Array
allowed values ok, warning, critical, unknown
default
["warning", "critical", "unknown"]
example
 "severities": ["critical", "unknown"]
timeout
description The handler execution duration timeout in seconds (hard stop).
required false
type Integer
default 10
example
"timeout": 30

smtp attributes

The following attributes are configured within the {"email": { "smtp": {} } } configuration scope.

EXAMPLE
{
  "email": {
    "smtp": {
      "address": "smtp.example.com",
      "port": 587,
      "...": "..."
    },
    "to": "support@example.com",
    "from": "noreply@example.com",
    "timeout": 10
  }
}
ATTRIBUTES
address
description The hostname or IP address of the SMTP server
type String
required false
default “127.0.0.1”
example
"address": "smtp.example.com"
port
description The SMTP sever port
type Integer
required false
default 25
example
"port": 25
domain
description The domain the SMTP server should use to send email from.
type String
required false
default localhost.localdomain
example
"domain": "localhost.localdomain"
openssl_verify_mode
description What SSL verification mode Sensu should use to establish a connection with the SMTP server.
type String
required false
default none
example
"openssl_verify_mode": "none"
enable_starttls_auto
description Whether Sensu should use STARTTLS (or “Opportunistic TLS”) to upgrade insecure connections with TLS encryption, when possible. Sensu Enterprise uses TLSv1.2, ONLY supporting TLSv1.0+.
type Boolean
required false
default true
example
"enable_starttls_auto": true
tls
description Whether Sensu should use TLS encryption for connections. Sensu Enterprise uses TLSv1.2, ONLY supporting TLSv1.0+.
type Boolean
required false
default false
example
"tls": true
user_name
description The username credential Sensu should use to authenticate to the SMTP server.
type String
required false
example
"username": "monitoring@example.com"
password
description The password credential Sensu should use to authenticate to the SMTP server.
type String
required false
example
"passsword": "PASSWORD"
authentication
description The authentication method should Sensu use when connecting to the SMTP server.
type String
required false
default plain
example
"authentication": "plain"

templates attributes

The following attributes are configured within the {"email": { "templates": {} } } configuration scope.

subject
description Path to the email subject ERB template file, which must be accessible by the sensu system user. If an email subject template is not provided, a built-in default template will be used.
type String
required false
example
"subject": "/etc/sensu/email/subject_template.erb"
body
description Path to the email body ERB template file, which must be accessible by the sensu system user. If an email body template is not provided, a built-in default template will be used.
type String
required false
example
"body": "/etc/sensu/email/body_template.erb"