Having Problems with mailer.rb

Hi All,

I wonder if anyone can help me. I am trying to setup mailer.rb as per this document: http://sensuapp.org/docs/0.16/adding_a_handler

Configuration

OS: CentOS 7 x86_64

SENSU VERSION 0.17.0

I have followed the steps but cant seem to get it to work without an error. I have set sensu to use the embedded ruby version in /etc/sensu/default and dowloaded the mail gem to embedded ruby.

I have created a test log entry and am seeing the following:

[root@ln01 ~]# cat ./test.log | /opt/sensu/embedded/bin/ruby -d/etc/sensu/handlers/mailer.rb
Exception RuntimeError' at /opt/sensu/embedded/bin/ruby - invalid option -/ (-h will show valid options) /opt/sensu/embedded/bin/ruby: invalid option -/ (-h will show valid options) (RuntimeError) [root@ln01 ~]# cat ./test.log | /opt/sensu/embedded/bin/ruby -d /etc/sensu/handlers/mailer.rb Exception LoadError’ at /opt/sensu/embedded/lib/ruby/2.0.0/rubygems.rb:1087 - cannot load such file – rubygems/defaults/operating_system
Exception LoadError' at /opt/sensu/embedded/lib/ruby/2.0.0/rubygems.rb:1096 - cannot load such file -- rubygems/defaults/ruby Exception LoadError’ at /opt/sensu/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53 - cannot load such file – sensu-handler
Using Ext extension for JSON.
Exception LoadError' at /opt/sensu/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53 - cannot load such file -- mail Exception NameError’ at /opt/sensu/embedded/lib/ruby/2.0.0/psych/core_ext.rb:16 - method to_yaml' not defined in Object Exception NameError’ at /opt/sensu/embedded/lib/ruby/2.0.0/psych/core_ext.rb:29 - method yaml_as' not defined in Module Exception NameError’ at /opt/sensu/embedded/lib/ruby/2.0.0/psych/deprecated.rb:80 - undefined method to_yaml_properties' for class Object’
/etc/sensu/handlers/mailer.rb:26: warning: method redefined; discarding old call
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/exim.rb:44: warning: previous definition of call was here
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/mixlib-cli-1.5.0/lib/mixlib/cli.rb:50: warning: instance variable @separate_default_options not initialized
Exception Errno::ENOENT' at /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-plugin/utils.rb:14 - No such file or directory - /etc/sensu/config.json Exception TypeError’ at /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125 - no implicit conversion of nil into String
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125:in +': no implicit conversion of nil into String (TypeError) from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125:in filter_silenced’
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:31:in filter' from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:54:in block in class:Handler

I hope someone can help as this is driving me up the wall. I am also not overly familiar with Ruby. Thanks for any replies in advance!

The -d debug flag is giving you (probably) more information than you
want. Most of that is red-herrings.

But the test.log file probably doesn't have valid event data to
operate on. The handler isn't doing good input validation at this
stage, so it is blowing up on the lack of @event['client']['name']

Can you pastebin your test.log? Better yet can you paste an error
"closer" to the real-life working of the handler, like from the
sensu-server log?

···

On Fri, Mar 20, 2015 at 1:14 PM, Tony <tonyintermodesystems@gmail.com> wrote:

Hi All,

I wonder if anyone can help me. I am trying to setup mailer.rb as per this
document: http://sensuapp.org/docs/0.16/adding_a_handler

Configuration
OS: CentOS 7 x86_64
SENSU VERSION 0.17.0

I have followed the steps but cant seem to get it to work without an error.
I have set sensu to use the embedded ruby version in /etc/sensu/default and
dowloaded the mail gem to embedded ruby.

I have created a test log entry and am seeing the following:

[root@ln01 ~]# cat ./test.log | /opt/sensu/embedded/bin/ruby
-d/etc/sensu/handlers/mailer.rb
Exception `RuntimeError' at /opt/sensu/embedded/bin/ruby - invalid option
-/ (-h will show valid options)
/opt/sensu/embedded/bin/ruby: invalid option -/ (-h will show valid
options) (RuntimeError)
[root@ln01 ~]# cat ./test.log | /opt/sensu/embedded/bin/ruby -d
/etc/sensu/handlers/mailer.rb
Exception `LoadError' at
/opt/sensu/embedded/lib/ruby/2.0.0/rubygems.rb:1087 - cannot load such file
-- rubygems/defaults/operating_system
Exception `LoadError' at
/opt/sensu/embedded/lib/ruby/2.0.0/rubygems.rb:1096 - cannot load such file
-- rubygems/defaults/ruby
Exception `LoadError' at
/opt/sensu/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53 -
cannot load such file -- sensu-handler
Using Ext extension for JSON.
Exception `LoadError' at
/opt/sensu/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53 -
cannot load such file -- mail
Exception `NameError' at
/opt/sensu/embedded/lib/ruby/2.0.0/psych/core_ext.rb:16 - method `to_yaml'
not defined in Object
Exception `NameError' at
/opt/sensu/embedded/lib/ruby/2.0.0/psych/core_ext.rb:29 - method `yaml_as'
not defined in Module
Exception `NameError' at
/opt/sensu/embedded/lib/ruby/2.0.0/psych/deprecated.rb:80 - undefined method
`to_yaml_properties' for class `Object'
/etc/sensu/handlers/mailer.rb:26: warning: method redefined; discarding
old call

/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/exim.rb:44:
warning: previous definition of call was here

/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/mixlib-cli-1.5.0/lib/mixlib/cli.rb:50:
warning: instance variable @separate_default_options not initialized
Exception `Errno::ENOENT' at
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-plugin/utils.rb:14
- No such file or directory - /etc/sensu/config.json
Exception `TypeError' at
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125
- no implicit conversion of nil into String

/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125:in
`+': no implicit conversion of nil into String (TypeError)
from
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:125:in
`filter_silenced'
from
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:31:in
`filter'
from
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugin-1.1.0/lib/sensu-handler.rb:54:in
`block in <class:Handler>'

I hope someone can help as this is driving me up the wall. I am also not
overly familiar with Ruby. Thanks for any replies in advance!