#NEWLINE# def process_notice( notice , log ) : #NEWLINE# #INDENT# ( zsig , body ) = parse_zephyr_body ( is_personal . message ) #NEWLINE# is_personal = False #NEWLINE# is_huddle = False #NEWLINE# if ( notice . opcode == 'PING' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# zephyr_class = notice . cls . lower ( ) #NEWLINE# if ( zephyr_class == options . nagios_class ) : #NEWLINE# #INDENT# with open ( options . nagios_path , 'w' ) as f : #NEWLINE# #INDENT# f . write ( '0\n' ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# if ( notice . recipient != '' ) : #NEWLINE# #INDENT# is_personal = True #NEWLINE# #UNINDENT# if ( is_personal and ( not options . forward_personals ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( ( zephyr_class not in current_zephyr_subs ) and ( not is_personal ) ) : #NEWLINE# #INDENT# logger . debug ( ( 'Skipping ... %s/%s/%s' % ( zephyr_class , notice . instance , is_personal ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( notice . format . startswith ( 'Zephyr error: See' ) or notice . format . endswith ( '@(@color(blue))' ) ) : #NEWLINE# #INDENT# logger . debug ( 'Skipping message we got from Zulip!' ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( ( zephyr_class == 'mail' ) and ( notice . instance . lower ( ) == 'inbox' ) and is_personal and ( not options . forward_mail_zephyrs ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if is_personal : #NEWLINE# #INDENT# if body . startswith ( 'CC:' ) : #NEWLINE# #INDENT# is_huddle = True #NEWLINE# huddle_recipients = [ to_zulip_username ( x . strip ( ) ) for x in body . split ( '\n' ) [ 0 ] [ 4 : ] . split ( ) ] #NEWLINE# if ( notice . sender not in huddle_recipients ) : #NEWLINE# #INDENT# huddle_recipients . append ( to_zulip_username ( notice . sender ) ) #NEWLINE# #UNINDENT# body = body . split ( '\n' , 1 ) [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# if ( options . forward_class_messages and ( notice . opcode . lower ( ) == 'crypt' ) ) : #NEWLINE# #INDENT# body = decrypt_zephyr ( zephyr_class , notice . instance . lower ( ) , body ) #NEWLINE# #UNINDENT# zeph = { #NEWLINE# #INDENT# 'time' : str ( notice . time ) , #NEWLINE# 'sender' : notice . sender , #NEWLINE# 'zsig' : zsig , #NEWLINE# 'content' : body , #NEWLINE# #UNINDENT# } #NEWLINE# if is_huddle : #NEWLINE# #INDENT# zeph [ 'type' ] = 'private' #NEWLINE# zeph [ 'recipient' ] = huddle_recipients #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if is_personal : #NEWLINE# #INDENT# zeph [ 'type' ] = 'private' #NEWLINE# zeph [ 'recipient' ] = to_zulip_username ( notice . recipient ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# zeph [ 'type' ] = 'stream' #NEWLINE# zeph [ 'stream' ] = zephyr_class #NEWLINE# if ( notice . instance . strip ( ) != '' ) : #NEWLINE# #INDENT# zeph [ 'subject' ] = notice . instance #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# zeph [ 'subject' ] = ( '(instance "%s")' % ( notice . instance , ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if is_personal : #NEWLINE# #INDENT# if ( ( notice . cls . lower ( ) != 'message' ) and ( notice . instance . lower != 'personal' ) ) : #NEWLINE# #INDENT# heading = ( '[-c %s -i %s]\n' % ( notice . cls , notice . instance ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( notice . cls . lower ( ) != 'message' ) : #NEWLINE# #INDENT# heading = ( '[-c %s]\n' % ( notice . cls , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( notice . instance . lower ( ) != 'personal' ) : #NEWLINE# #INDENT# heading = ( '[-i %s]\n' % ( notice . instance , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# heading = '' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# zeph [ 'content' ] = ( heading + zeph [ 'content' ] ) #NEWLINE# #UNINDENT# zeph = decode_unicode_byte_strings ( zeph ) #NEWLINE# logger . info ( ( 'Received a message on %s/%s from %s...' % ( zephyr_class , notice . instance , notice . sender ) ) ) #NEWLINE# if ( log is not None ) : #NEWLINE# #INDENT# log . write ( ( simplejson . dumps ( zeph ) + '\n' ) ) #NEWLINE# log . flush ( ) #NEWLINE# #UNINDENT# if ( os . fork ( ) == 0 ) : #NEWLINE# #INDENT# global CURRENT_STATE #NEWLINE# CURRENT_STATE = States . ChildSending #NEWLINE# try : #NEWLINE# #INDENT# res = send_zulip ( zeph ) #NEWLINE# if ( res . get ( 'result' ) != 'success' ) : #NEWLINE# #INDENT# logger . error ( ( 'Error relaying zephyr:\n%s\n%s' % ( zeph , res ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( 'Error relaying zephyr:' ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# os . _exit ( 0 )