From b66271d008d9d86f7475931141def45e91e5c4be Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Mon, 27 Nov 2017 19:24:59 -0800 Subject: [PATCH] return an error message with helpful debug when config !correct? added sample event and config Signed-off-by: Ben Abrams --- CHANGELOG.md | 6 ++++++ bin/handler-slack.rb | 9 +++++++++ sample/handler_slack_config.json | 10 ++++++++++ sample/handler_slack_event.json | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 sample/handler_slack_config.json create mode 100644 sample/handler_slack_event.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc445a..f7a649c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/bin/handler-slack.rb b/bin/handler-slack.rb index 1a832c4..45d9d41 100755 --- a/bin/handler-slack.rb +++ b/bin/handler-slack.rb @@ -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 diff --git a/sample/handler_slack_config.json b/sample/handler_slack_config.json new file mode 100644 index 0000000..09ac4b0 --- /dev/null +++ b/sample/handler_slack_config.json @@ -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:" + } +} diff --git a/sample/handler_slack_event.json b/sample/handler_slack_event.json new file mode 100644 index 0000000..91cf5e1 --- /dev/null +++ b/sample/handler_slack_event.json @@ -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" + } + }