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

`build_body': undefined method `[]' for nil:NilClass #39

Closed christopherdriscoll closed 8 years ago

christopherdriscoll commented 8 years ago

Using sensu version 0.25.6 and sensu-plugins-mailer version 1.0.0. My mailer config is located in /etc/sensu/conf.d and reads as follows (sensitive information changed):

{
    "rubymailer": {
      "admin_gui": "http://127.0.0.1:3001/",
      "mail_from": "noreply@mydomain.com",
      "mail_to": "email@mydomain.com",
      "smtp_address": "127.0.0.1",
      "smtp_port": "25",
      "smtp_domain": "mydomain.com",
      "delivery_method": "smtp"
    },
    "handlers": {
      "rubymailer": {
        "type": "pipe",
        "command": "/opt/sensu/embedded/bin/ruby /opt/sensu/embedded/bin/handler-mailer.rb"
      }
    }
}

I don't receive any emails, but I do see this in the logs:

{"timestamp":"2016-08-01T09:10:07.567878-0500","level":"info","message":"handler output","handler":{"type":"pipe","command":"/opt/sensu/embedded/bin/ruby /opt/sensu/embedded/bin/handler-mailer.rb","name":"rubymailer"},"output":["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-mailer-1.0.0/bin/handler-mailer.rb:141:in build_body': undefined method[]' for nil:NilClass (NoMethodError)\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-mailer-1.0.0/bin/handler-mailer.rb:169:in handle'\n\tfrom /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.0/lib/sensu-handler.rb:81:inblock in class:Handler'\nwarning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\nwarning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin\n"]}

Evesy commented 8 years ago

Can you try updating the handler command to the below to specify the json key that your configuration resides in:

/opt/sensu/embedded/bin/ruby /opt/sensu/embedded/bin/handler-mailer.rb -j rubymailer

christopherdriscoll commented 8 years ago

@Evesy - That worked, thanks!