Created
April 13, 2017 11:37
-
-
Save pmiles/ab503ba8f638219b0097ff27a1d21101 to your computer and use it in GitHub Desktop.
sensu slack multichannel handler config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Quick howto on setting up Slack Multichannel handler (handler-slack-multichannel.rb) | |
See https://github.com/sensu-plugins/sensu-plugins-slack | |
These instructions are proven to work on Ubuntu | |
## Installation | |
### Manual way | |
I found it easiest to install using gem, but you may want to directly check out this repo. | |
Since I am using embedded ruby with Sensu I used the following commands : | |
/opt/sensu/embedded/bin/gem install --http-proxy http://proxy:3128 erubis | |
/opt/sensu/embedded/bin/gem install --http-proxy http://proxy:3128 sensu-plugins-slack | |
Note - remove the http-proxy options if you do not use a proxy server | |
Next copy and paste the following json into /etc/sensu/conf.d/handlers/slack.json | |
``` | |
{ | |
"handlers": { | |
"slack": { | |
"command": "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack-multichannel.rb", | |
"type": "pipe", | |
"severities": [ | |
"ok", | |
"warning", | |
"critical", | |
"unknown" | |
] | |
} | |
}, | |
"slack": { | |
"channels": { | |
"default": [ | |
], | |
"compulsory": [ | |
] | |
}, | |
"webhook_url": "https://hooks.slack.com/services/HIDDEN/SECRET", | |
"proxy_addr": "proxy", | |
"proxy_port": "3128", | |
"bot_name": "SensuBot", | |
"icon_url": "http://sensuapp.org/img/sensu_logo_large-c92d73db.png", | |
"icon_emoji": ":snowman:" | |
} | |
} | |
``` | |
Note - remove the proxy_addr and proxy_port lines if you do not have a proxy server in your infrastructure. | |
### Using Puppet | |
``` | |
package { 'erubis': | |
ensure => 'installed', | |
provider => 'sensu_gem', | |
install_options => [{'--http-proxy' => 'http://proxy:3128'}], | |
} | |
package { 'sensu-plugins-slack': | |
ensure => 'installed', | |
provider => 'sensu_gem', | |
install_options => [{'--http-proxy' => 'http://proxy:3128'}], | |
} | |
# NOTE - you need the sensu puppet module before using the handler code below | |
sensu::handler { 'slack': | |
type => 'pipe', | |
command => '/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack-multichannel.rb', | |
config => { | |
'channels' => { 'default' => [], 'compulsory' => [] }, | |
'proxy_addr' => 'proxy', | |
'proxy_port' => '3128', | |
'webhook_url' => 'https://hooks.slack.com/services/HIDDEN/SECRET', | |
'bot_name' => 'SensuBot', | |
'icon_url' => 'http://sensuapp.org/img/sensu_logo_large-c92d73db.png', | |
'icon_emoji' => ':snowman:' | |
} | |
} | |
``` | |
Note - remove the install_options lines, the proxy_addr and proxy_port if you do not have a proxy server in your infrastructure. | |
## Testing | |
You will need to restart sensu-server before attempting to test. | |
Create the file /tmp/eventdata.json | |
``` | |
{ | |
"id": "ef6b87d2-1f89-439f-8bea-33881436ab90", | |
"action": "create", | |
"timestamp": 1460172826, | |
"occurrences": 1, | |
"refresh": 60, | |
"check": { | |
"slack": {"channels":["#devops_team"]}, | |
"type": "standard", | |
"total_state_change": 11, | |
"history": ["0", "0", "1", "1", "2", "2"], | |
"status": 2, | |
"output": "Just a test", | |
"executed": 1460172826, | |
"issued": 1460172826, | |
"name": "test_check", | |
"thresholds": { | |
"critical": 180, | |
"warning": 120 | |
} | |
}, | |
"client": { | |
"timestamp": 1460172596, | |
"version": "0.29.0", | |
"socket": { | |
"port": 3030, | |
"bind": "127.0.0.1" | |
}, | |
"subscriptions": [ | |
"production" | |
], | |
"environment": "development", | |
"address": "127.0.0.1", | |
"name": "intdasa1" | |
} | |
} | |
``` | |
Then run | |
``` | |
cat /tmp/eventdata.json | /opt/sensu/embedded/bin/ruby /opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-slack-1.0.0/bin/handler-slack-multichannel.rb``` | |
With a bit of luck, you should get a message arrive in the slack channel called #devops_team | |
Note, you will need to have setup the Slack API access and put this URL into the handler json before testing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment