Sensu Plugin - Mailer
This handler formats alerts as e-mails and sends them off to a pre-defined recipient. [1]
Basic information
License: MIT License
Installation
Note
The entire process of installation and configuration has to be executed only in the Sensu Server.
The handler is a Ruby script that can be downloaded from the official repository: https://github.com/sensu-plugins/sensu-plugins-mailer/blob/master/bin/handler-mailer.rb.
It can be located in /etc/sensu/handlers/mailer.rb
Configuration
Add the Mailer configuration file and set correctly which will be the SMTP server, the sender, the mail recipients, etc:
Example: /etc/sensu/conf.d/handlers/mailer.json
{ "mailer": { "mail_from": "sensu@example.com", "mail_to": [ "mail1@example.com", "mail2@example.com" ], "smtp_address": "smtp.server.host.example.com", "smtp_port": "25", "smtp_domain": "example.com" }, "handlers": { "mailer": { "type": "pipe", "filter": "state-change-only", "command": "/opt/sensu/embedded/bin/handler-mailer.rb" } } }
In this example, the handler definition has the filter state-change-only associated. This filter executes the mailer handler to send mail only when there is a change in the state, that means, in the first occurrence of the state. When a check is in state OK, it doesn’t count occurrences, that’s why it’s necessary to have both conditions in the conditional.
That filter is defined as follows:
Example: /etc/sensu/conf.d/filters.json
{ "filters": { "state-change-only": { "negate": false, "attributes": { "occurrences": "eval: value == 1 || ':::action:::' == 'resolve'" } } } }
Usage
Follow these steps to add mailer as a handler that will send a mail when there is a state change in a specific monitoring check:
Add Mailer as a handler in the check definition:
{ "checks": { "check_example": { "command": "check-example.rb", "subscribers": ["examples"], "interval": 60, "handlers": ["mailer"] } } }
Restart sensu-server and sensu-api services.