now also updating the front page

master
Marek Isalski 7 years ago
parent 4fac492255
commit a1eb4645c4

@ -4,27 +4,18 @@ import os
import glob import glob
import re import re
class Event( object ): class Index( object ):
def __init__( self, path, glob ): def __init__( self, path ):
self.path = path self.path = path
self.glob = glob
self.fields = {} self.fields = {}
self.doc = "" self.doc = ""
def path_short( self ): def path_short( self ):
# XXX needs tidy # XXX needs tidy
return "content/event/" + os.path.basename( self.path ) return "content/pages/index.md"
def open( self ): def open( self ):
if os.path.exists( self.path ):
self.read()
return False
for path in glob.glob( self.glob ):
if os.path.exists( path ):
self.path = path
self.read() self.read()
return False
return True
def write( self ): def write( self ):
outdata = ( '''\ outdata = ( '''\
@ -45,6 +36,54 @@ class Event( object ):
self.fields = yaml.load( yamldata ) self.fields = yaml.load( yamldata )
self.doc = docdata.strip() self.doc = docdata.strip()
def _toggle( self, fieldname ):
if self.fields.get( fieldname ):
del self.fields[ fieldname ]
else:
self.fields[ fieldname ] = True
return " ".join( [ x for x in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ] if self.fields.get( x ) ] )
def toggle_incident( self ):
return self._toggle( 'incident' )
def toggle_degraded( self ):
return self._toggle( 'degraded' )
def toggle_maintenance( self ):
return self._toggle( 'maintenance' )
def toggle_notice( self ):
return self._toggle( 'notice' )
def toggle_ok( self ):
return self._toggle( 'ok' )
def set_flags( self, flags ):
for fieldname in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ]:
self.fields[ fieldname ] = fieldname in flags
class Event( Index ):
def __init__( self, path, glob ):
super().__init__( path )
self.glob = glob
def path_short( self ):
# XXX needs tidy
return "content/event/" + os.path.basename( self.path )
def open( self ):
if os.path.exists( self.path ):
self.read()
return False
for path in glob.glob( self.glob ):
if os.path.exists( path ):
self.path = path
self.read()
return False
return True
def set_title( self, title ): def set_title( self, title ):
self.fields[ '$title@' ] = title self.fields[ '$title@' ] = title
@ -86,25 +125,3 @@ class Event( object ):
if not self.fields.get( 'timeline' ): if not self.fields.get( 'timeline' ):
self.fields[ 'timeline' ] = [] self.fields[ 'timeline' ] = []
self.fields[ 'timeline' ].append( { 'time': time, 'line': line } ) self.fields[ 'timeline' ].append( { 'time': time, 'line': line } )
def _toggle( self, fieldname ):
if self.fields.get( fieldname ):
del self.fields[ fieldname ]
else:
self.fields[ fieldname ] = True
return " ".join( [ x for x in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ] if self.fields.get( x ) ] )
def toggle_incident( self ):
return self._toggle( 'incident' )
def toggle_degraded( self ):
return self._toggle( 'degraded' )
def toggle_maintenance( self ):
return self._toggle( 'maintenance' )
def toggle_notice( self ):
return self._toggle( 'notice' )
def toggle_ok( self ):
return self._toggle( 'ok' )

@ -56,6 +56,7 @@ def channel_name_to_raw_incident_number( channel_name ):
def mattermost_incident_command( command, args, channel_id, raw_incident_number, user_name ): def mattermost_incident_command( command, args, channel_id, raw_incident_number, user_name ):
channel = app.mm.channels.get_channel( channel_id ) channel = app.mm.channels.get_channel( channel_id )
slug = slugify.slugify( channel[ 'purpose' ] ) slug = slugify.slugify( channel[ 'purpose' ] )
index = event.Index( path = app.config[ "STATUS_EVENT_INDEX" ] )
ev = event.Event( path = app.config[ "STATUS_EVENT_SCHEME" ] % { "incident_number": raw_incident_number, ev = event.Event( path = app.config[ "STATUS_EVENT_SCHEME" ] % { "incident_number": raw_incident_number,
"slug": slug, "slug": slug,
}, },
@ -154,7 +155,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
} ) } )
elif command == "START": elif command == "START":
new = ev.open() ev.open()
started = ev.set_started( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) ) started = ev.set_started( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write() ev.write()
@ -162,7 +163,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event start date set by %s to: `%s`" % ( user_name, started ), 'message': "Event start date set by %s to: `%s`" % ( user_name, started ),
} ) } )
elif command == "ETR": elif command == "ETR":
new = ev.open() ev.open()
expected = ev.set_expected( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) ) expected = ev.set_expected( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write() ev.write()
@ -170,7 +171,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event estimated time of resolution set by %s to: `%s`" % ( user_name, expected ), 'message': "Event estimated time of resolution set by %s to: `%s`" % ( user_name, expected ),
} ) } )
elif command == "FINISHED": elif command == "FINISHED":
new = ev.open() ev.open()
finished = ev.set_finished( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) ) finished = ev.set_finished( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write() ev.write()
@ -178,7 +179,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event finished time set by %s to: `%s`" % ( user_name, finished ), 'message': "Event finished time set by %s to: `%s`" % ( user_name, finished ),
} ) } )
elif command == "RESOLVED": elif command == "RESOLVED":
new = ev.open() ev.open()
resolved = ev.set_resolved( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) ) resolved = ev.set_resolved( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write() ev.write()
@ -189,7 +190,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
if not args: if not args:
return "You need to specify some text to add to the timeline..." return "You need to specify some text to add to the timeline..."
new = ev.open() ev.open()
ev.add_timeline( time = datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ), line = args ) ev.add_timeline( time = datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ), line = args )
ev.write() ev.write()
@ -198,41 +199,56 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
} ) } )
elif command == "INCIDENT": elif command == "INCIDENT":
new = ev.open() ev.open()
flags = ev.toggle_incident() flags = ev.toggle_incident()
ev.write() ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id, app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ), 'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} ) } )
elif command == "DEGRADED": elif command == "DEGRADED":
new = ev.open() ev.open()
flags = ev.toggle_degraded() flags = ev.toggle_degraded()
ev.write() ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id, app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ), 'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} ) } )
elif command == "MAINTENANCE": elif command == "MAINTENANCE":
new = ev.open() ev.open()
flags = ev.toggle_maintenance() flags = ev.toggle_maintenance()
ev.write() ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id, app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ), 'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} ) } )
elif command == "NOTICE": elif command == "NOTICE":
new = ev.open() ev.open()
flags = ev.toggle_notice() flags = ev.toggle_notice()
ev.write() ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id, app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ), 'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} ) } )
elif command == "OK": elif command == "OK":
new = ev.open() ev.open()
flags = ev.toggle_ok() flags = ev.toggle_ok()
ev.write() ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id, app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ), 'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),

Loading…
Cancel
Save