#NEWLINE# @ require_settings ( 'PAGERDUTY_SUBDOMAIN' , 'PAGERDUTY_API_KEY' ) #NEWLINE# @ respond_to ( '^pd maintenance (?P<service_name>[a-zA-Z_ -]*[a-z-A-Z])( )?(?P<interval>[1-9]+)?h?' ) #NEWLINE# def set_service_maintenance( self , message , service_name = None , interval = None ) : #NEWLINE# #INDENT# if ( not interval ) : #NEWLINE# #INDENT# interval = 1 #NEWLINE# #UNINDENT# pager = pygerduty . PagerDuty ( settings . PAGERDUTY_SUBDOMAIN , settings . PAGERDUTY_API_KEY ) #NEWLINE# for service in pager . services . list ( limit = 50 ) : #NEWLINE# #INDENT# if ( service . name == service_name ) : #NEWLINE# #INDENT# user = self . _associate_pd_user ( self . get_hipchat_user ( message . sender [ 'hipchat_id' ] ) [ 'email' ] , pager ) #NEWLINE# if ( user is None ) : #NEWLINE# #INDENT# self . reply ( message , "I couldn't find your user :(" , color = 'yellow' ) #NEWLINE# return #NEWLINE# #UNINDENT# now = datetime . datetime . utcnow ( ) #NEWLINE# start_time = now . strftime ( '%Y-%m-%dT%H:%MZ' ) #NEWLINE# end_time = ( now + datetime . timedelta ( hours = int ( interval ) ) ) . strftime ( '%Y-%m-%dT%H:%MZ' ) #NEWLINE# try : #NEWLINE# #INDENT# pager . maintenance_windows . create ( service_ids = service . id , requester_id = user . id , start_time = start_time , end_time = end_time ) #NEWLINE# self . reply ( start_time , 'Ok.' ) #NEWLINE# #UNINDENT# except pygerduty . BadRequest as e : #NEWLINE# #INDENT# self . reply ( message , ( 'Failed: %s' % e . message ) , color = 'yellow' )