You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.8 KiB
Python
64 lines
2.8 KiB
Python
|
|
from flask import Flask, request
|
|
import os
|
|
import incident
|
|
|
|
app = Flask( __name__ )
|
|
app.config.from_envvar( 'FIH_SETTINGS' )
|
|
|
|
app.mm = incident.Mattermost( url = app.config[ 'MATTERMOST_URL' ],
|
|
port = app.config[ 'MATTERMOST_PORT' ],
|
|
login_id = app.config[ 'MATTERMOST_USER_EMAIL' ],
|
|
password = app.config[ 'MATTERMOST_USER_PASSWORD' ],
|
|
).mm
|
|
|
|
@app.route( '/mattermost/incident', methods = [ 'POST' ] )
|
|
def mattermost_incident():
|
|
# channel_name: testing
|
|
# command: /incident
|
|
# channel_id: o3ob1utim3nummoswjyt4174mo
|
|
# user_name: marek
|
|
# test_domain: faelix
|
|
# text: test
|
|
# team_id: 3woo8mbjrbb1in53xwdzi4ynqh
|
|
# user_id: ko3uxmend7ne8ger4uw9mxkt1o
|
|
# token: XXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
|
|
if request.form[ 'token' ] in app.config[ 'MATTERMOST_COMMAND_TOKENS' ]:
|
|
incident_number = incident.generate_incident_number()
|
|
fi_number = "FI#" + incident_number
|
|
channel_name = "incident" + incident_number
|
|
purpose = request.form[ 'text' ]
|
|
|
|
channel = app.mm.channels.create_channel( options = { "team_id": request.form[ 'team_id' ],
|
|
"name": channel_name,
|
|
"display_name": fi_number,
|
|
"purpose": "Internal discussion about incident " + fi_number,
|
|
"header": purpose,
|
|
"type": "O",
|
|
} )
|
|
|
|
# add user to the channel we just created
|
|
app.mm.client.make_request( 'post', '/channels/' + channel[ 'id' ] + '/members', options = { 'user_id': request.form[ 'user_id' ],
|
|
} )
|
|
app.mm.posts.create_post( options = { 'channel_id': channel[ 'id' ],
|
|
'message': "Incident Channel for %s created by @%s" % ( fi_number, request.form[ 'user_name' ] ),
|
|
} )
|
|
|
|
app.mm.posts.create_post( options = { 'channel_id': request.form[ 'channel_id' ],
|
|
'message': 'Starting incident %s with discussion in channel ~%s' % ( fi_number, channel_name, ),
|
|
} )
|
|
|
|
return ""
|
|
else:
|
|
return "Invalid command token."
|
|
|
|
@app.route( '/mattermost/fih', methods = [ 'POST' ] )
|
|
def mattermost_fig():
|
|
print( repr( request.form ) )
|
|
return "Whaaat?"
|
|
|
|
@app.route( '/' )
|
|
def hello_world():
|
|
return 'Hello, World!'
|