3

i'm switching over from nagios to sensu. i'm using chef to automated the process. everything is working great except the mailer or actually, i narrowed it down to the "pipe" that is suppose to redirect the json output from the check to the handler. it doesn't. when i use

{
  "handlers": {
    "email": {
      "type": "pipe",
      "command": "mail -s \"sensu alert\" alert@example.com",
      "severities": [
        "ok",
        "critical"
      ]
    }
  }
}

i get a blank email. when i use the mailer.rb handler, i get no email whatsoever. i made sure to include mail to and mail from in the mailer.json. i see the logs have the correct information for the handler and email parameters.

so i've concluded the "pipe" isn't working. can anybody help with that? i would greatly appreciate it. i wish there was a sensu community, but it may be too new to have one.

user2608740
  • 39
  • 1
  • 4

6 Answers6

2

With regards to the mailer.rb, have you checked the server logs (by default in /var/log/sensu/sensu-server.log) for errors? If there is an error in any of the handlers, they will show up in those logs.

mailer.rb requires several gems in order to run. To find out if you are using sensu's embedded ruby or not, check /etc/default/sensu for EMBEDDED_RUBY. If that is false, you will need to make sure your system ruby has all those gems (sensu-handler, mail, timeout) installed. If it is set to true, do the same with sensu's embedded ruby:

/opt/sensu/embedded/bin/gem list

Make sure the gems are installed, try again, and check the sensu-server.log for errors.

If you have more issues, there is in fact a community - check out #sensu on Freenode.

2

You can write you own event data JSON and pass it through a PIPE as follows:

cat event.json | /opt/sensu/embedded/bin/ruby mailer.rb

The easiest way to get the event.json file is from the sensu-server.log.

frommelmak
  • 169
  • 3
1

To use mailer.rb you need your own mail server ! if you'll post sensu server logs i think i can help you.

Onbayev Kanat
  • 303
  • 3
  • 9
0

I've done some testing and the mail into pipe does not with GNU mail/mailx (assume you're using Ubuntu or something?).

Two solutions:

1) install BSD mail:

sudo apt-get install bsd-mailx

2) Or modify the command slightly get mail to read from stdin you'll need to do something like:

{
  "handlers": {
    "email": {
      "type": "pipe",
      "command": " echo $(cat) > /tmp/mail.txt;  mail -s \"sensu alert\" alert@example.com < /tmp/mail.txt"
    }
  }
}

The idea is normally that you read the event json from stdin within a scripting language and then pull out bits of the event.json that you want to send. The above will e-mail out the entire json file.

0

You can use sensu mailer handler. Please find below steps to setup:-

  1. sensu-install -p sensu-plugins-mailer
  2. apt-get install postifx
  3. /etc/init.d/postfix start
  4. cd /etc/sensu/conf.d/

when we install this plugin will get 3 ruby files.

This time we are using this file:- handler-mailer.rb

First we need to creat handler file in this location /etc/sensu/conf.d/ :-

  1. vim handler-mailer.json

    { "mailer": { "admin_gui": "http://127.0.0.1:3000/", "mail_from": "localhost", "mail_to": ["yourmailid-1","yourmailid-2"], "smtp_address": "localhost", "smtp_port": "25" } }

Now we need to create one mail handler file in this location /etc/sensu/conf.d/:-

  1. { "handlers": { "mymailer": { "type": "pipe", "command": "/opt/sensu/embedded/bin/handler-mailer.rb", "severities": [ "critical", "unknown" ] } } }

in above file handler name is mymailer we need to use this handler name in our checks.

Pengyy
  • 37,383
  • 15
  • 83
  • 73
0

Use bin/handler-mailer-mailgun.rb or bin/handler-mailer-ses.rb or bin/handler-mailer.rb

Example:

echo '{
"id": "ef6b87d2-1f89-439f-8bea-33881436ab90",
"action": "create",
"timestamp": 1460172826,
"occurrences": 2,
"check": {
  "type": "standard",
  "total_state_change": 11,
  "history": ["0", "0", "1", "1", "2", "2"],
  "status": 2,
  "output": "No keepalive sent from client for 230 seconds (>=180)",
  "executed": 1460172826,
  "issued": 1460172826,
  "name": "keepalive",
  "thresholds": {
    "critical": 180,
    "warning": 120
  }
},
"client": {
  "timestamp": 1460172596,
  "version": "1.0.0",
  "socket": {
    "port": 3030,
    "bind": "127.0.0.1"
  },
  "subscriptions": [
    "production"
  ],
  "environment": "development",
  "address": "127.0.0.1",
  "name": "client-01"
} }' | /opt/sensu/embedded/bin/handler-mailer-mailgun.rb

Output:

mail -- sent alert for client-01/keepalive to your.email@example.com
artamonovdev
  • 2,260
  • 1
  • 29
  • 33