Use handler-mailer.rb to build email handlers for sensu go

I’m building the sensu go email handler, with the ruby 2.3.1, sensu-plugin(4.0.0) and sensu-plugins-mailer(4.0.0).

this handler-mailer.rb script working the day before yesterday, and without any change when yesterday I login to the server and trying the same command (event.json is an event in sensu go schema), it returns the error:

$ cat event.json | /usr/local/lib/ruby/gems/2.3.0/gems/sensu-plugins-mailer-4.0.0/bin/handler-mailer.rb -j mailer -c html -s ‘[Sensu]’ --map-go-event-into-ruby

/usr/local/lib/ruby/gems/2.3.0/gems/sensu-plugins-mailer-4.0.0/bin/handler-mailer.rb:213:in `build_body': undefined method `[]' for nil:NilClass (NoMethodError)
	from /usr/local/lib/ruby/gems/2.3.0/gems/sensu-plugins-mailer-4.0.0/bin/handler-mailer.rb:240:in `handle'
	from /usr/local/lib/ruby/gems/2.3.0/gems/sensu-plugin-4.0.0/lib/sensu-handler.rb:89:in `block in <class:Handler>'

I’ve checked with couple files:
The mailer config json file exists here defining the smtp_domain and mail_from, mail_to, admin_gui. etc: /etc/sensu/conf.d/sensu-plugins-mailer.json

{
"mailer": {
"smtp_domain": "xxx.com",
"mail_from": "sensu@xxx.com",
"mail_to": "xxx@xxx.com",
"admin_gui": "http://sensu.xxx.com:3000",
"template": "/etc/sensu/plugins/mail-template.erb",
"smtp_address": "xxxx",
"smtp_port": 2525
}
}

mail templates exists here: /etc/sensu/plugins/mail-template.erb

Does anyone meet with this issue? What changes make this issue happen suddenly and how can I solve it

Hey,

give me a few minutes, let me see if I can sort this out locally.

Hi jspaleta,

Thanks for the fast reply, I just get this issue solved, probably is caused by the version issue or some config issue I guess

Hey,

my best guess is its a permissions issue with your /etc/sensu/conf.d/sensu-plugins-mailer.json file.
Maybe the conf.d directory isn’t readable by the user running the handler command?

Using your sensu-plugins-mailer.json file I’m able to use the repository master branch to build and install the plugin using ruby 2.4.1.

If you are comfortable working with the repository, I’ve created a new branch that has the new diagnostic option that might help you sort out the problem further. I’m going to work on spinning up a new release with a diagnostic option that will report back config settings so you can help troubleshoot.

I should add…
While the Ruby based sensu-plugins-mailer handler should still work, you might want to try the golang email handler, which is available as a Sensu asset in Bonsai.