Yelp / sensu_handlers

Custom Sensu Handlers to support a multi-tenant environment, allowing checks themselves to emit the type of handler behavior they need in the event json
Apache License 2.0
75 stars 31 forks source link

Add component support for individual teams (like tags) #133

Closed jvperrin closed 5 years ago

jvperrin commented 5 years ago

This adds component support so that components can be set per-team in sensu_handlers::teams. This is useful since the jira project is generally set per-team and components are required per-project, so being able to set components (like tags) per-team is useful.

I also changed the code for picking components to be a bit different and more similar to the way labels/tags are currently constructed:

[
  *@event['check']['component'],
  *team_data('component'),
].uniq.reject(&:nil?)

Nicely enough, this handles nil, various values, and arrays as values without problems:

irb(main):001:0> [*nil]
=> []
irb(main):002:0> [*5]
=> [5]
irb(main):003:0> [*[1, nil, 3]]
=> [1, nil, 3]
irb(main):004:0> [*5, *nil, *[1, 2, 'test']].uniq.reject(&:nil?)
=> [5, 1, 2, "test"]

I tested this by editing /etc/sensu/conf.d/handlers/jira.json on an admin server in dev and adding a default component to a team for testing and then using a technique like in #129 to make test tickets (but without a component explicitly set).