Custom sensu extension logs settings every time an event is filtered

#1

Here’s my simple extension:

require ‘sensu/extension’

module Sensu
module Extension
class ServiceAlert < Handler

  def name
    "service-alert"
  end

  def description
    "Extension/handler that relays alerts of services"
  end

  def definition
    {
      :type => "extension",
      :name => name,
      :filters => ["filter_refresh"]
    }
  end

  def run(event)
    message = Response.prepare(event)
    yield "#{message}", 0
  end
end

class Response
  def self.prepare(event)
    {
      service: self.check_alias(event),
      status: self.action_status(event),
      output: self.check_output(event)
    }
  end
  ...
end

end
end

This works great and as advertised. The problem is that every time an event is filtered, my sensu-server log outputs the entire settings to the log file.

{“timestamp”:“2019-02-13T13:31:07.260314+0100”,“level”:“info”,“message”:“event was filtered”, … ,“settings”: <this objects, although a single line, actually spans about 100 lines.>

It logs my entire settings every time an even is filtered. This consists of rabbitmq config, all of my checks, handlers, relays, filters, etc. This is annoying specially when filtering hundreds of events in a small space of time.

When the handler does need to fire, it works fine and just outputs what I want and some extra info:

{“timestamp”:“2019-02-13T13:44:13.603596+0100”,“level”:“info”,“message”:“handler extension output”,“extension”:{“type”:“extension”,“name”:“service-alert”,“filters”:[“filter_refresh”],“severities”:[“unknown”,“critical”,“warning”,“ok”]},“event”:{“id”:“977ec44d-f3ad-4129-b516-68fa82cd6858”},“output”:"…",“status”:0}

Is there a way I can avoid logging settings everytime the event is filtered?

Note, this does not happen when using a plugin handler where the log line does not output settings and as a consequence the log output is reasonable.

Sensu: 0.29

#2

Hi @t-sawyer, thanks for raising this issue.

I believe the behavior you are experiencing is described in sensu/sensu#1872, fixed in sensu/sensu#1873 and released in Sensu 1.4.3. As such, I expect that upgrading to the latest version of Sensu should resolve the problem you’re experiencing.

Will you please let us know if you are able to replicate this behavior on the latest version Sensu?

#3

Yes of course. Will do. And thanks for pointing me to the issue. I agree in that it looks like the same behavior.

#4

Hi @t-sawyer,

Did upgrading help here?

#5

@cwjohnston @aaronsachs-sensu Yep. After upgrading to 1.7.0, this was no longer a problem.