send Graphite output to Slack

Just a quick recipe to send rendered graphs from Graphite to Slack, using your crontab(5) and Incoming Webhooks:

0  5  *  *  * /path/to/script.sh >/dev/null

This will send a message to your webhook’s default channel every day at 5am, and Slack show you a preview of the graph in the channel. For completeness’ sake (!) here’s the contents of `/path/to/script.sh`:

#!/bin/sh
METRIC="stats.gauges.somemetric"
OPTS="from=-2hours&until=now&width=400&height=250"
BASE="https://graph.host.com/render"
GRAPH="${BASE}?${OPTS}&target=${METRIC}&title=${METRIC}"
PAYLOAD="payload={\"text\": \"<$GRAPH|daily metric graph>\"}"
curl -s --dump-header - -X POST --data-urlencode "$PAYLOAD" \
 'https://my.slack.com/services/hooks/incoming-webhook?token=XXXXXXXXXXXXX'

UPDATE: the initial version had a bug with single quotes which ought to have been double quotes. Thanks to GregTheRules for catching that.

Advertisements

2 thoughts on “send Graphite output to Slack

  1. Hi !

    Your script is a nice idea !

    I found an issue with your shell script : $DATA is not evaluated in the $PAYLOAD because of the double quotes. Escaping them with a backquote do the trick.

    Here is my version :

    PAYLOAD=”payload={\”text\”: \”\”}”

    Cheers,
    G.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s