Search code examples
ruby-on-railssensu

Sensu Emailer `parse_options': invalid option: -j (OptionParser::InvalidOption)


Trying to setup amazon ses for sensu

Setup 1 I have

handler-mailer.rb -j mailme_using_amazonses in my config.json

and handler-mailer.rb is in my /etc/sensu/plugins folder

When I run on command line, I get errors

ruby /etc/sensu/plugins/handler-mailer.rb -j mailme_using_amazonses
/var/lib/gems/1.9.1/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:230:in `parse_options': invalid option: -j (OptionParser::InvalidOption)
    from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:18:in `initialize'
    from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:78:in `new'
    from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:78:in `block in <class:Handler>'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- erubis (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /etc/sensu/plugins/handler-mailer.rb:20:in `<main>'

My mailme_using_amazonses has the following

{
    "handlers": {
        "mailer-ses": {
           "mail_from": "[email protected]",
           "mail_to": "[email protected]",
           "use_ami_role": true,
           "secret_key": "MyKey",
           "access_key": "MyAccess",
           "region": "us-west-2"
        }
    }
}

Setup 2 In config.json I have the following

{
.. other config ..
 "handlers": {
    "handler-ses": {  **HERE I ALSO TRIED "ses"**
      "mail_from": "[email protected]",
      "mail_to": "[email protected]",
      "use_ami_role": true,
      "access_key": "accesskey",
      "secret_key": "secretekey",
      "region": "us-west-2",
      "subscriptions": {
        "subscription_name": {
          "mail_to": "[email protected]"
        }
      }
    }
  }
}

When I restart sensu-server I get the following error

configuration is invalid
{
  "errors":[
    {
      "object":{
        "mail_from":"[email protected]",
        "mail_to":"[email protected]",
        "use_ami_role":true,
        "access_key":"accesskey",
        "secret_key":"secretkey",
        "region":"us-west-2",
        "subscriptions":{
          "subscription_name":{
            "mail_to":"[email protected]"
          }
        },
        "name":"handler-ses"
      },
      "message":"handler type must be a string"
    },
    {
      "object":{
        "mail_from":"[email protected]",
        "mail_to":"[email protected]",
        "use_ami_role":true,
        "access_key":"accesskey",
        "secret_key":"secretkey",
        "region":"us-west-2",
        "subscriptions":{
          "subscription_name":{
            "mail_to":"[email protected]"
          }
        },
        "name":"handler-ses"
      },
      "message":"unknown handler type"
    }
  ]
}

What am I missing here ?


Solution

  • I fixed the issue. I read the handler-ses.rb file. Here it was noted that the config should be in ses.json. I copied the Setup 2 ses configuration from config.json json into ses.json and placed it under /etc/sensu/handers folder. The error went away. I am yet to get the emails though.

    Will update this answer after I get ses email working.