Repository navigation
Expand file tree
/
Copy pathwebhook.py
More file actions
47 lines (40 loc) · 1.51 KB
/
Copy pathwebhook.py
File metadata and controls
47 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask, request
import json
import requests
import os
app = Flask(__name__)
if 'SF_TOKEN' in os.environ:
print os.environ['SF_TOKEN']
else:
print 'SF_TOKEN env variable not found'
sys.exit(0)
@app.route('/hook', methods=['POST'])
def login():
headers = {'X-SF-TOKEN' : os.environ['SF_TOKEN'],'Content-Type' : 'application/json'}
data = json.loads(request.data)
if 'event' in data:
if "start" not in data['event']:
send_event = {}
send_event['category']='USER_DEFINED'
send_event['eventType']='code_build_'+data['event']
custom_data={'buildName':data['buildName'],'buildUrl':data['buildUrl']}
send_event['properties']=custom_data
send_event = [send_event]
print json.dumps(send_event,indent=2)
r = requests.post('https://ingest.signalfx.com/v2/event',headers=headers,data=json.dumps(send_event))
return(r.text)
elif 'pusher' in data:
send_event = {}
send_event['category']='USER_DEFINED'
send_event['eventType']='code_push'
custom_data={'Pusher':data['pusher']['email']}
send_event['properties']=custom_data
send_event = [send_event]
print json.dumps(send_event,indent=2)
r = requests.post('https://ingest.signalfx.com/v2/event',headers=headers,data=json.dumps(send_event))
return(r.text)
else:
print data
return "OK"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5050)