StackStorm-Exchange / stackstorm-sensu

st2 content pack containing sensu integrations
https://exchange.stackstorm.org/
Apache License 2.0
5 stars 6 forks source link

Stackstorm is not triggering the action with Sensu event handler #13

Closed arnabnandy1706 closed 5 years ago

arnabnandy1706 commented 5 years ago

I have created a rule like below, but the rule is not getting triggered when an event is getting triggered in Sensu.

Please Help !

---
name: http-proc-check
description: Rule to check HTTP process in the Sensu clients
pack: sensu
trigger:
   type: sensu.event_handler
criteria:
   trigger.check.name:
      pattern: "proc-http"
     type: "equals"
    trigger.check.output:
     pattern: "CheckProcess CRITICAL*"
      type: "matchregex"
 action:
    ref: "core.local"
    parameters:
     cmd: "echo \"{{trigger}}\" >> /tmp/sensu-sample.out"
  enabled: true

Below is the handler_st2.json in Sensu Server.

{
  "handlers": {
    "st2": {
      "type": "pipe",
      "command": "/opt/sensu/embedded/bin/st2_handler.rb"
    }
  }
}

Thanks, Arnab

LindsayHill commented 5 years ago

Have you gone through all the configuration steps at https://github.com/StackStorm-Exchange/stackstorm-sensu#configure-sensu-to-send-events-to-stackstorm?

Make sure that your handler is properly configured (including credentials), and that Sensu is running that handler when events of interest are triggered.

arnabnandy1706 commented 5 years ago

Hello @LindsayHill ,

I have configured as per the document. Below are the Handler files:

[root@sensu-host conf.d]# cat st2_handler.json
{
    "st2_handler": {
    "st2_username": "st2admin"
    "st2_password": "*********"
    "st2_api_key": "",
    "st2_api_base_url": "https://stackstorm-host/api/",
    "st2_auth_base_url": "https://stackstorm-host/auth"
  }
}
[root@sensu-host conf.d]# cat handler_st2.json
{
  "handlers": {
    "st2": {
      "type": "pipe",
      "command": "/opt/sensu/embedded/bin/st2_handler.rb"
    }
  }
}

When I am testing getting below the error:

[root@sensu-host conf.d]# echo '{"client": {"name": 1}, "check":{"name": 2}, "id": "12345"}' | /opt/sensu/embedded/bin/st2_handler.rb --unauthed

Traceback (most recent call last):
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-stackstorm-0.1.1/lib/sensu-plugins-stackstorm/../../bin/st2_handler.py", line 433, in <module>
    main(payload=payload, verbose=args.verbose, unauthed=args.unauthed, ssl_verify=args.ssl_verify)
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-stackstorm-0.1.1/lib/sensu-plugins-stackstorm/../../bin/st2_handler.py", line 417, in main
    _set_config_opts(unauthed=unauthed, verbose=verbose, ssl_verify=ssl_verify)
  File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-stackstorm-0.1.1/lib/sensu-plugins-stackstorm/../../bin/st2_handler.py", line 391, in _set_config_opts
    SENSU_HOST = Config['api'].get('host', 'localhost')
**AttributeError: 'NoneType' object has no attribute 'get**

Please help !

Thanks Arnab

LindsayHill commented 5 years ago

Looks like your Sensu system doesn't have an API configuration scope defined. Should be something like /etc/sensu/conf.d/api.json

{
  "api": {
    "bind": "0.0.0.0",
    "port": 4567,
    "host": "localhost"
  }
}

See https://docs.sensu.io/sensu-core/1.6/api/configuration/

arnabnandy1706 commented 5 years ago

Thanks @LindsayHill ,

It's working fine now.