Skip to content

Instantly share code, notes, and snippets.

@mateobur
Created December 12, 2017 15:58
Show Gist options
  • Save mateobur/8915ed2b4494f25d32f990e492a03214 to your computer and use it in GitHub Desktop.
Save mateobur/8915ed2b4494f25d32f990e492a03214 to your computer and use it in GitHub Desktop.
Prometheus alerts to Sysdig Monitor integration webhook
from flask import Flask, request
from sdcclient import SdcClient
import json, os
app = Flask(__name__)
sdclient = SdcClient(os.environ['SYSDIG_API_KEY'])
@app.route('/', methods=['POST'])
def handle_alert():
data = json.loads(request.data)
alertname = data['groupLabels']['alertname']
description = data['commonAnnotations']['description']
severity = int(data['commonAnnotations']['severity'])
scope = ''
for key in data['commonAnnotations']:
if key == "description" or key == "severity":
continue
newname = key.replace('_', '.')
scope += newname + ' = "' + data['commonAnnotations'][key] + '" and '
tags = data['commonLabels']
response = sdclient.post_event(alertname, description, severity,
scope[:-4], tags)
if not response[0]:
print "Error: " + response[1]
return "OK"
if __name__ == '__main__':
app.run(app.run(host='0.0.0.0', port=10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment