Extension is never being run


#1

Hello,

I am having dificulties on running an extension[1]

The check:
``
{
  "checks": {
    "load_metrics": {
      "command": "/etc/sensu/plugins/system/load-metrics.rb",
      "interval": 3,
      "type": "metric",
      "subscribers": ["all"],
      "handlers": ["metrics"]
    }
  }
}
``

The handler
``
{
  "handlers": {
    "metrics": {
    "type": "set",
    "handlers": ["influxdb", "debug"]
    }
  }
}
``

The logs:

``
{"timestamp":"2014-10-06T13:57:07.739508+0000","level":"warn","message":"loading
config file","file":"/etc/sensu/conf.d/influxdb.json"}
{"timestamp":"2014-10-06T13:57:07.739931+0000","level":"warn","message":"config
file applied
changes","file":"/etc/sensu/conf.d/influxdb.json","changes":{"database":[null,"test"],"host":[null,"192.168.33.1"],"pas
ssword":[null,"root"],"port":[null,8087],"user":[null,"root"]}}
{"timestamp":"2014-10-06T13:57:07.740419+0000","level":"warn","message":"loading
config file","file":"/etc/sensu/conf.d/checks.json"}
{"timestamp":"2014-10-06T13:57:07.740887+0000","level":"warn","message":"config
file applied
changes","file":"/etc/sensu/conf.d/checks.json","changes":{"checks":{"load_metrics":[null,{"command":"/etc/sensu/plugin
s/system/load-metrics.rb","interval":3,"type":"metric","subscribers":["all"],"handlers":["metrics"]}]}}}
{"timestamp":"2014-10-06T13:57:07.741406+0000","level":"warn","message":"loading
config file","file":"/etc/sensu/conf.d/handlers.json"}
{"timestamp":"2014-10-06T13:57:07.741478+0000","level":"warn","message":"config
file applied
changes","file":"/etc/sensu/conf.d/handlers.json","changes":{"handlers":{"metrics":[null,{"type":"set","handlers":["deb
ug","influxdb"]}]}}}
{"timestamp":"2014-10-06T13:57:07.825698+0000","level":"warn","message":"loading
extension files from directory","directory":"/etc/sensu/extensions"}
{"timestamp":"2014-10-06T13:57:07.826519+0000","level":"warn","message":"loading
extension file","file":"/etc/sensu/extensions/influxdb.rb"}
{"timestamp":"2014-10-06T13:57:07.826949+0000","level":"warn","message":"loaded
extension","type":"mutator","name":"json","description":"returns JSON
formatted event data"}
{"timestamp":"2014-10-06T13:57:07.827368+0000","level":"warn","message":"loaded
extension","type":"mutator","name":"ruby_hash","description":"returns
ruby hash event data"}
{"timestamp":"2014-10-06T13:57:07.827662+0000","level":"warn","message":"loaded
extension","type":"mutator","name":"only_check_output","description":"returns
check output"}
{"timestamp":"2014-10-06T13:57:07.827927+0000","level":"warn","message":"loaded
extension","type":"handler","name":"debug","description":"returns raw
event data"}
{"timestamp":"2014-10-06T13:57:07.828377+0000","level":"warn","message":"loaded
extension","type":"handler","name":"InfluxDB","description":"Outputs
metrics to InfluxDB"}
``

As you can see the extension is properly loaded and the check runs:
``
{"timestamp":"2014-10-06T13:57:57.940260+0000","level":"info","message":"publishing
check
request","payload":{"name":"load_metrics","issued":1412603877,"command":"/etc/sensu/plugins/system/load-metrics.rb"},"subs
cribers":["all"]}
``

But the data never gets there, writting a puts event_data on the start
of the run method shows that run function its never called.

Any help appreciatted!

[1] https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb

···

--
Regards,
Alfredo Palhares


#2

Hi Alfredo,

I noticed that you call EventMachine run() in your extension, you cannot do this, as the event loop is already started and managed by Sensu itself. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L50

You also do not want to stop the event loop on error, just log the error event. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L59

As of Sensu 0.13, the extension API does not pass a block to stop(), so you cannot yield, and the method does not need to return anything. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L65

Sean.

···

On Mon, Oct 6, 2014 at 7:00 AM, Alfredo Palhares masterkorp@masterkorp.net wrote:

Hello,

I am having dificulties on running an extension[1]

The check:

``

{

“checks”: {

"load_metrics": {

  "command": "/etc/sensu/plugins/system/load-metrics.rb",

  "interval": 3,

  "type": "metric",

  "subscribers": ["all"],

  "handlers": ["metrics"]

}

}

}

``

The handler

``

{

“handlers”: {

"metrics": {

"type": "set",

"handlers": ["influxdb", "debug"]

}

}

}

``

The logs:

``

{“timestamp”:“2014-10-06T13:57:07.739508+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/influxdb.json"}

{“timestamp”:“2014-10-06T13:57:07.739931+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/influxdb.json",“changes”:{“database”:[null,“test”],“host”:[null,“192.168.33.1”],"pas

ssword":[null,“root”],“port”:[null,8087],“user”:[null,“root”]}}

{“timestamp”:“2014-10-06T13:57:07.740419+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/checks.json"}

{“timestamp”:“2014-10-06T13:57:07.740887+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/checks.json",“changes”:{“checks”:{“load_metrics”:[null,{“command”:"/etc/sensu/plugin

s/system/load-metrics.rb",“interval”:3,“type”:“metric”,“subscribers”:[“all”],“handlers”:[“metrics”]}]}}}

{“timestamp”:“2014-10-06T13:57:07.741406+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/handlers.json"}

{“timestamp”:“2014-10-06T13:57:07.741478+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/handlers.json",“changes”:{“handlers”:{“metrics”:[null,{“type”:“set”,“handlers”:["deb

ug",“influxdb”]}]}}}

{“timestamp”:“2014-10-06T13:57:07.825698+0000”,“level”:“warn”,“message”:"loading

extension files from directory",“directory”:"/etc/sensu/extensions"}

{“timestamp”:“2014-10-06T13:57:07.826519+0000”,“level”:“warn”,“message”:"loading

extension file",“file”:"/etc/sensu/extensions/influxdb.rb"}

{“timestamp”:“2014-10-06T13:57:07.826949+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“json”,“description”:"returns JSON

formatted event data"}

{“timestamp”:“2014-10-06T13:57:07.827368+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“ruby_hash”,“description”:"returns

ruby hash event data"}

{“timestamp”:“2014-10-06T13:57:07.827662+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“only_check_output”,“description”:"returns

check output"}

{“timestamp”:“2014-10-06T13:57:07.827927+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“handler”,“name”:“debug”,“description”:"returns raw

event data"}

{“timestamp”:“2014-10-06T13:57:07.828377+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“handler”,“name”:“InfluxDB”,“description”:"Outputs

metrics to InfluxDB"}

``

As you can see the extension is properly loaded and the check runs:

``

{“timestamp”:“2014-10-06T13:57:57.940260+0000”,“level”:“info”,“message”:"publishing

check

request",“payload”:{“name”:“load_metrics”,“issued”:1412603877,“command”:"/etc/sensu/plugins/system/load-metrics.rb"},"subs

cribers":[“all”]}

``

But the data never gets there, writting a puts event_data on the start

of the run method shows that run function its never called.

Any help appreciatted!

[1] https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb

Regards,

Alfredo Palhares


#3

Also, you should be using MultiJson.load() and dump() instead of JSON. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L71

···

On Tue, Oct 7, 2014 at 7:02 AM, Sean Porter portertech@gmail.com wrote:

Hi Alfredo,

I noticed that you call EventMachine run() in your extension, you cannot do this, as the event loop is already started and managed by Sensu itself. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L50

You also do not want to stop the event loop on error, just log the error event. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L59

As of Sensu 0.13, the extension API does not pass a block to stop(), so you cannot yield, and the method does not need to return anything. eg. https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb#L65

Sean.

On Mon, Oct 6, 2014 at 7:00 AM, Alfredo Palhares masterkorp@masterkorp.net wrote:

Hello,

I am having dificulties on running an extension[1]

The check:

``

{

“checks”: {

"load_metrics": {

  "command": "/etc/sensu/plugins/system/load-metrics.rb",

  "interval": 3,

  "type": "metric",

  "subscribers": ["all"],

  "handlers": ["metrics"]

}

}

}

``

The handler

``

{

“handlers”: {

"metrics": {

"type": "set",

"handlers": ["influxdb", "debug"]

}

}

}

``

The logs:

``

{“timestamp”:“2014-10-06T13:57:07.739508+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/influxdb.json"}

{“timestamp”:“2014-10-06T13:57:07.739931+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/influxdb.json",“changes”:{“database”:[null,“test”],“host”:[null,“192.168.33.1”],"pas

ssword":[null,“root”],“port”:[null,8087],“user”:[null,“root”]}}

{“timestamp”:“2014-10-06T13:57:07.740419+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/checks.json"}

{“timestamp”:“2014-10-06T13:57:07.740887+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/checks.json",“changes”:{“checks”:{“load_metrics”:[null,{“command”:"/etc/sensu/plugin

s/system/load-metrics.rb",“interval”:3,“type”:“metric”,“subscribers”:[“all”],“handlers”:[“metrics”]}]}}}

{“timestamp”:“2014-10-06T13:57:07.741406+0000”,“level”:“warn”,“message”:"loading

config file",“file”:"/etc/sensu/conf.d/handlers.json"}

{“timestamp”:“2014-10-06T13:57:07.741478+0000”,“level”:“warn”,“message”:"config

file applied

changes",“file”:"/etc/sensu/conf.d/handlers.json",“changes”:{“handlers”:{“metrics”:[null,{“type”:“set”,“handlers”:["deb

ug",“influxdb”]}]}}}

{“timestamp”:“2014-10-06T13:57:07.825698+0000”,“level”:“warn”,“message”:"loading

extension files from directory",“directory”:"/etc/sensu/extensions"}

{“timestamp”:“2014-10-06T13:57:07.826519+0000”,“level”:“warn”,“message”:"loading

extension file",“file”:"/etc/sensu/extensions/influxdb.rb"}

{“timestamp”:“2014-10-06T13:57:07.826949+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“json”,“description”:"returns JSON

formatted event data"}

{“timestamp”:“2014-10-06T13:57:07.827368+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“ruby_hash”,“description”:"returns

ruby hash event data"}

{“timestamp”:“2014-10-06T13:57:07.827662+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“mutator”,“name”:“only_check_output”,“description”:"returns

check output"}

{“timestamp”:“2014-10-06T13:57:07.827927+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“handler”,“name”:“debug”,“description”:"returns raw

event data"}

{“timestamp”:“2014-10-06T13:57:07.828377+0000”,“level”:“warn”,“message”:"loaded

extension",“type”:“handler”,“name”:“InfluxDB”,“description”:"Outputs

metrics to InfluxDB"}

``

As you can see the extension is properly loaded and the check runs:

``

{“timestamp”:“2014-10-06T13:57:57.940260+0000”,“level”:“info”,“message”:"publishing

check

request",“payload”:{“name”:“load_metrics”,“issued”:1412603877,“command”:"/etc/sensu/plugins/system/load-metrics.rb"},"subs

cribers":[“all”]}

``

But the data never gets there, writting a puts event_data on the start

of the run method shows that run function its never called.

Any help appreciatted!

[1] https://github.com/seegno/sensu-influxdb-extension/blob/master/influxdb.rb

Regards,

Alfredo Palhares