Skip to content

Commit

Permalink
return an error message with helpful debug when config !correct?
Browse files Browse the repository at this point in the history
added sample event and config

Signed-off-by: Ben Abrams <[email protected]>
  • Loading branch information
majormoses committed Feb 1, 2018
1 parent eb47d60 commit b66271d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [Unreleased]

### Changed
- `handler-slack.rb`: emit an `unknown` with helpful debug messages when passing in bad config (@majormoses)

### Added
- added sample event payload and config (@majormoses)

## [3.0.0] - 2018-01-11
### Breaking Changes
- bumped `sensu-plugin` dependency to 2.x which removes in handler filtering for `occurrences`. If you want to keep using the same filtering features you must specify it and ensure that you have applied the filter by setting `"filters": ["occurrences"]`. For more information see [here](https://blog.sensuapp.org/deprecating-event-filtering-in-sensu-plugin-b60c7c500be3) (@majormoses)
Expand Down
9 changes: 9 additions & 0 deletions bin/handler-slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def incident_key

def get_setting(name)
settings[config[:json_config]][name]
rescue TypeError, NoMethodError => e
puts "settings: #{settings}"
puts "slack key: #{config[:json_config]}. This should not be a file name/path."
puts <<-EOS
key name: #{name}. This is the key in config that broke.
Check the slack key to make sure it's parent key exists"
EOS
puts "error: #{e.message}"
exit 3 # unknown
end

def handle
Expand Down
10 changes: 10 additions & 0 deletions sample/handler_slack_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"slack": {
"webhook_url": "https://hooks.slack.com/services/XXX/XXX/XXX",
"dashboard": "https://my-super-awesome-dashbord.domain.tld",
"channel": "#bots",
"bot_name": "sensubot",
"icon_url": "https://raw.githubusercontent.com/sensu/sensu-logo/master/sensu1_flat%20white%20bg_png.png",
"icon_emoji": ":snowman:"
}
}
34 changes: 34 additions & 0 deletions sample/handler_slack_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "ef6b87d2-1f89-439f-8bea-33881436ab90",
"action": "create",
"timestamp": 1460172826,
"occurrences": 2,
"check": {
"type": "standard",
"total_state_change": 11,
"history": ["0", "0", "1", "1", "2", "2"],
"status": 2,
"output": "No keepalive sent from client for 230 seconds (>=180)",
"executed": 1460172826,
"issued": 1460172826,
"name": "keepalive",
"thresholds": {
"critical": 180,
"warning": 120
}
},
"client": {
"timestamp": 1460172596,
"version": "0.27.0",
"socket": {
"port": 3030,
"bind": "127.0.0.1"
},
"subscriptions": [
"base"
],
"environment": "development",
"address": "127.0.0.1",
"name": "slackbot"
}
}

0 comments on commit b66271d

Please sign in to comment.