forked from jeff0928/SlashSNOW
/
slashsnow.py
109 lines (92 loc) · 3.36 KB
/
slashsnow.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from flask import Flask, request
from create_incident import create_incident
import get_user_id
import os
import yaml
app = Flask(__name__)
@app.route('/ticket', methods=['POST'])
def rackerex_ticket():
conf_file = os.path.expanduser('~/snowconfig.yaml')
with open(conf_file,'r') as ymlfile:
cfg = yaml.load(ymlfile)
auth_token = str(cfg['rackerex']['auth'])
token = request.form['token']
if auth_token not in token:
abort(403)
slack_user = request.form['user_id']
task_for = get_user_id.get_snow_uid(get_user_id.get_user_id(slack_user))
short_desc = request.form['text']
queue = 'Racker Experience'
try:
incident = create_incident(task_for, short_desc, queue)
except IOError as err:
incident = create_incident(task_for, short_desc, queue)
return incident
@app.route('/asops', methods=['POST'])
def asops_ticket():
conf_file = os.path.expanduser('~/snowconfig.yaml')
with open(conf_file,'r') as ymlfile:
cfg = yaml.load(ymlfile)
auth_token = str(cfg['asops']['auth'])
token = request.form['token']
if auth_token not in token:
abort(403)
slack_user = request.form['user_id']
task_for = get_user_id.get_snow_uid(get_user_id.get_user_id(slack_user))
short_desc = request.form['text']
queue = 'ASOPS'
try:
incident = create_incident(task_for, short_desc, queue)
except IOError as err:
incident = create_incident(task_for, short_desc, queue)
return incident
@app.route('/servicedesk', methods=['POST'])
def sdesk_ticket():
conf_file = os.path.expanduser('~/snowconfig.yaml')
with open(conf_file,'r') as ymlfile:
cfg = yaml.load(ymlfile)
auth_token = str(cfg['sdesk']['auth'])
token = request.form['token']
if auth_token not in token:
abort(403)
slack_user = request.form['user_id']
task_for = get_user_id.get_snow_uid(get_user_id.get_user_id(slack_user))
short_desc = request.form['text']
queue = 'Service Desk'
try:
incident = create_incident(task_for, short_desc, queue)
except IOError as err:
incident = create_incident(task_for, short_desc, queue)
return incident
@app.route('/servicedeskopenfor', methods=['POST'])
def sdesk_ticket_openfor():
conf_file = os.path.expanduser('~/snowconfig.yaml')
with open(conf_file,'r') as ymlfile:
cfg = yaml.load(ymlfile)
auth_token = str(cfg['sdesk']['auth_openfor'])
token = request.form['token']
if auth_token not in token:
abort(403)
slack_user = request.form['user_id']
task_for = request.form['text'].split(' ', 1)[0]
short_desc = request.form['text'].split(' ', 1)[1]
queue = 'Service Desk'
try:
incident = create_incident(task_for, short_desc, queue)
except IOError as err:
incident = create_incident(task_for, short_desc, queue)
return incident
@app.route('/test', methods=['GET', 'POST'])
def test():
conf_file = os.path.expanduser('~/snowconfig.yaml')
with open(conf_file,'r') as ymlfile:
cfg = yaml.load(ymlfile)
auth_token = str(cfg['test']['auth'])
token = request.form['token']
if auth_token not in token:
abort(403)
user_info = request.form
return repr(user_info)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)