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.

41 lines
1.4 KiB
Python

from flask import Flask, request
import os
import incident
app = Flask( __name__ )
app.config.from_envvar( 'FIH_SETTINGS' )
mm = incident.Mattermost( app.config[ 'MATTERMOST_TEAM_ID' ],
url = app.config[ 'MATTERMOST_URL' ],
port = app.config[ 'MATTERMOST_PORT' ],
login_id = app.config[ 'MATTERMOST_USER_EMAIL' ],
password = app.config[ 'MATTERMOST_USER_PASSWORD' ],
)
@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' ]:
fi_number = incident.generate_incident_number()
channel_name = fi_number.lower()
mm.create_channel( channel_name, request.form[ 'text' ] )
mm.notify( request.form[ 'channel_id' ], fi_number, channel_name )
return "" # "Starting incident %s in channel #%s." % ( fi_number, channel_name )
else:
return "Invalid command token."
@app.route( '/' )
def hello_world():
return 'Hello, World!'