Profile photo

from miller import blake

Hello, I'm a systems administrator, I get paid to be a software developer, I like Python, I'm a fan of good design, and I don't think things always have to be so stupid.
You can follow me @bltmiller, subscribe via RSS, and email me.

Send Kapacitor Alerts to Slack Through a Proxy

Kapacitor does not have the ability to work behind an HTTP(S) proxy, and while that is indeed in the works, you might need something working today.

The normal Kapacitor config for Slack integration looks something like:

[slack]
  enabled = true
  # you're going to update the url in a moment
  url = "https://hooks.slack.com/services/Y0UR/70K3N/H3R3"
  channel = "#alerts"
  global = true
  state-changes-only = true

We’re going to make one change, but first you’ll need to setup a relay to Slack. Go install that with:

pip install relay2slack

The webhook relay is a simple app that starts a Flask server and listens locally for requests to forward onto Slack. This solution will work as long as we’re running relay2slack on the same server as Kapacitor. To daemonize the relay, follow the documentation in the project’s repository.

Now that you have your Slack webhook relay running, you can now update Kapacitor to point to it:

[slack]
  enabled = true
  # url now points to relay2slack running locally
  url = "http://localhost:5000/relay"
  channel = "#alerts"
  global = true
  state-changes-only = true

Voila! Kapacitor can successfully send its requests to the relay on your localhost, and the relay forwards the JSON payload to your Slack webhook address using your proxy. This is not limited to just Kapacitor: the same strategy can be applied to any application that cannot be configured to use system proxy settings.


comments powered by Disqus

Copyright © 2016, Blake Miller. All rights reserved. | Sitemap · RSS