sensu-plugins / sensu-plugins-mailer

This plugin is an email handler for Sensu.
http://sensu-plugins.io
MIT License
17 stars 37 forks source link

Custom attributes in email? #26

Closed kobbe closed 8 years ago

kobbe commented 8 years ago

Hi, It does not seem like any other attributes other than host, timestamp, address, check-name, status, output and occurences are sent with the email. I would be great if all other attributes of the check also would be emailed. I would suggest that all other attributes that are not any of the above mentioned are still included, maybe at the at bottom of the email.

My suggestion is to list all attributes of the check bellow the most important ones (those that are already in the email)

Evesy commented 8 years ago

Hey @kobbe,

If there are extra attributes you want to be included in your emails you could create your own template with those attributes included and have that template be used for sending mails.

In order to do this you can create a .erb file somewhere on your server which would contain something like the below:

Host: <%= @event['client']['name'] %>
Timestamp: <%= Time.at(@event['check']['issued']) %>
Address:  <%= @event['client']['address'] %>
Check Name:  <%= @event['check']['name'] %>
Command:  <%= command %>
Status:  <%= status_to_string %>
Occurrences:  <%= @event['occurrences'] %>

So for example if you wanted to include the duration from the event JSON you'd add:

Event ID: <% @event['check']['duration'] %>

Then it's just a case of pointing to that template in your mailer config as per the example provided in the docs:

{
  "mailer": {
    "mail_from": "sensu@example.com",
    "mail_to": "monitor@example.com",
    "smtp_address": "smtp.example.org",
    "smtp_port": "25",
    "smtp_domain": "example.org",
    "template": "/optional/path/to/template.erb",
    "subscriptions": {
      "subscription_name": {
        "mail_to": "teamemail@example.com"
      }
    }
  }
}

I suppose you could also just dump the entire event JSON at the bottom of the email too if you wanted to include absolutely everything for reference.

kobbe commented 8 years ago

Thanks! Yes, including the whole JSON in that way would be nice and is essentially what I wanted :)