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.
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
|
|
import os
|
|
import datetime
|
|
import random
|
|
import mattermostdriver
|
|
|
|
random.seed( os.urandom( 8 ) )
|
|
|
|
def generate_incident_number():
|
|
return "FI" + datetime.datetime.now().strftime( "%Y%m%d" ) + ( "%4d" % int( random.random() * 10000 ) )
|
|
|
|
class Mattermost( object ):
|
|
def __init__( self, team_id, *args, **kwargs ):
|
|
self.team_id = team_id
|
|
self.mm = mattermostdriver.Driver( kwargs )
|
|
self.mm.login()
|
|
|
|
def create_channel( self, name, purpose = None ):
|
|
r = self.mm.channels.create_channel( options = { "team_id": self.team_id,
|
|
"name": name,
|
|
"purpose": "Incident " + name + ( purpose and " " + purpose or "" ),
|
|
"header": "",
|
|
"type": "P",
|
|
} )
|
|
print( repr( r ) )
|
|
|
|
|
|
def notify( self, notify_channel_id, incident_number, incident_channel_name ):
|
|
self.mm.posts.create_post( options = { 'channel_id': notify_channel_id,
|
|
'message': 'Starting incident %s with discussion in channel -%s' % ( incident_number, incident_channel_name, ),
|
|
} )
|