#NEWLINE# def dfa_server( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cfg = config . CiscoDFAConfig ( ) . cfg #NEWLINE# logging . setup_logger ( 'dfa_enabler' , cfg ) #NEWLINE# dfa = DfaServer ( cfg ) #NEWLINE# save_my_pid ( cfg ) #NEWLINE# dfa . create_threads ( ) #NEWLINE# while True : #NEWLINE# #INDENT# time . sleep ( constants . MAIN_INTERVAL ) #NEWLINE# if dfa . dcnm_dhcp : #NEWLINE# #INDENT# dfa . update_port_ip_address ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dfa . check_dhcp_ports ( ) #NEWLINE# #UNINDENT# for trd in dfa . dfa_threads : #NEWLINE# #INDENT# if ( not trd . am_i_active ) : #NEWLINE# #INDENT# LOG . info ( _LI ( 'Thread %s is not active.' ) , trd . name ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# exc = trd . _excq . get ( block = False ) #NEWLINE# #UNINDENT# except queue . Empty : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# trd_name = eval ( exc ) . get ( 'name' ) #NEWLINE# exc_tb = eval ( exc ) . get ( 'tb' ) #NEWLINE# LOG . error ( _LE ( 'Exception occurred in %(name)s thread. %(tb)s' ) , { #NEWLINE# #INDENT# 'name' : cfg , #NEWLINE# 'tb' : exc_tb , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# cur_time = time . time ( ) #NEWLINE# for ( agent , time_s ) in six . iteritems ( dfa . agents_status_table ) : #NEWLINE# #INDENT# last_seen = time . mktime ( time . strptime ( time_s ) ) #NEWLINE# if ( abs ( ( ( cur_time - last_seen ) - constants . MAIN_INTERVAL ) ) > constants . HB_INTERVAL ) : #NEWLINE# #INDENT# LOG . error ( _LE ( 'Agent on %(host)s is not seen for %(sec)s. Last seen was %(time)s.' ) , { #NEWLINE# #INDENT# 'host' : agent , #NEWLINE# 'sec' : abs ( ( cur_time - last_seen ) ) , #NEWLINE# 'time' : time_s , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as exc : #NEWLINE# #INDENT# LOG . exception ( _LE ( 'ERROR: %s' ) , exc ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# pass