Skip to content

Instantly share code, notes, and snippets.

@jaimegago
Last active June 25, 2016 00:31
Show Gist options
  • Save jaimegago/6a814eeaec9c1620a817d6ac4bd7375b to your computer and use it in GitHub Desktop.
Save jaimegago/6a814eeaec9c1620a817d6ac4bd7375b to your computer and use it in GitHub Desktop.
slack graphite integration in flask (/graphite command)
from flask import Flask
from flask import request
from flask import Response
import json
import urlparse
app = Flask(__name__)
@app.route('/graphite', methods=['GET', 'POST'])
def graphite_png():
args = request.form['text'].split()
time = args[0]
graph_query = args[1]
params='/render?target=%s&format=png&from=%s' % (graph_query, time)
url = urlparse.urljoin('http://graphite_url',params)
message_text= "Graphite target: ```%s```\nFrom: ```%s```\nSlack command: ```/graphite %s %s```" % (graph_query, time, time, graph_query)
attachment = { "response_type": "in_channel", "text": message_text, "attachments": [ {"title": "", "image_url": url} ] }
return_json = json.dumps(attachment)
return Response(return_json, mimetype='application/json')
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment