<s> from copy import deepcopy as clone_object <EOL> from fluent . sender import FluentSender <EOL> from math import isnan , isinf <EOL> from laikaboss . si_module import SI_MODULE <EOL> from laikaboss . util import get_option , log_module_error <EOL> from uuid import UUID <EOL> class ScanObjectStub : <EOL> def __init__ ( self , ) : <EOL> self . parent = '<STR_LIT>' <EOL> self . uuid = '<STR_LIT>' <EOL> class ResultStub : <EOL> def __init__ ( self , ) : <EOL> self . files = { } <EOL> class LOG_FLUENT ( SI_MODULE ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ) : <EOL> '''<STR_LIT>''' <EOL> self . module_name = "<STR_LIT>" <EOL> self . _senders = { } <EOL> def _run ( self , scanObject , result , depth , args ) : <EOL> """<STR_LIT>""" <EOL> tag = get_option ( args , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> host = get_option ( args , "<STR_LIT:host>" , "<STR_LIT>" , "<STR_LIT:localhost>" ) <EOL> port = int ( get_option ( args , "<STR_LIT:port>" , "<STR_LIT>" , <NUM_LIT> ) ) <EOL> bufmax = int ( get_option ( args , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ) <EOL> timeout = float ( get_option ( args , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ) <EOL> label = get_option ( args , "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> sender = self . _get_sender ( tag , host , port , bufmax , timeout ) <EOL> log_record = self . _parse_log_record ( result ) <EOL> sender . emit ( label , log_record ) <EOL> if sender . pendings : <EOL> log_module_error ( self . module_name , scanObject , result , <EOL> '<STR_LIT>' ) <EOL> return [ ] <EOL> def _close ( self , ) : <EOL> '''<STR_LIT>''' <EOL> for sender in self . _senders . itervalues ( ) : <EOL> if sender . pendings : <EOL> sender . emit ( '<STR_LIT>' , <EOL> { '<STR_LIT:message>' : <EOL> '<STR_LIT>' } ) <EOL> if sender . pendings : <EOL> log_module_error ( self . module_name , ScanObjectStub ( ) , ResultStub ( ) , <EOL> '<STR_LIT>' ) <EOL> def _get_sender ( self , tag , host , port , bufmax , timeout ) : <EOL> '''<STR_LIT>''' <EOL> sender = None <EOL> key = "<STR_LIT>" % ( tag , host , port , bufmax , timeout ) <EOL> if key in self . _senders : <EOL> sender = self . _senders [ key ] <EOL> else : <EOL> sender = FluentSender ( tag , host , port , bufmax , timeout ) <EOL> self . _senders [ key ] = sender <EOL> return sender <EOL> def _parse_log_record ( self , result ) : <EOL> '''<STR_LIT>''' <EOL> buffer_results = [ ] <EOL> for scan_object in result . files . itervalues ( ) : <EOL> buffer_result = clone_object ( scan_object . __dict__ ) <EOL> if "<STR_LIT>" in buffer_result : <EOL> del buffer_result [ "<STR_LIT>" ] <EOL> buffer_results . append ( buffer_result ) <EOL> log_record = { <EOL> '<STR_LIT:source>' : result . source , <EOL> '<STR_LIT>' : self . _log_record_strainer ( buffer_results ) <EOL> } <EOL> return log_record <EOL> def _log_record_strainer ( self , thing ) : <EOL> '''<STR_LIT>''' <EOL> thing_type = type ( thing ) <EOL> if thing_type in [ list , set , frozenset ] : <EOL> new_thing = [ ] <EOL> for element in thing : <EOL> new_thing . append ( self . _log_record_strainer ( element ) ) <EOL> return new_thing <EOL> elif thing_type is dict : <EOL> new_thing = { } <EOL> for key , value in thing . iteritems ( ) : <EOL> new_key = self . _log_record_strainer ( key ) <EOL> new_value = self . _log_record_strainer ( value ) <EOL> new_thing [ new_key ] = new_value <EOL> return new_thing <EOL> elif thing_type is UUID : <EOL> return str ( thing ) <EOL> elif thing_type is float : <EOL> if isnan ( thing ) : <EOL> return '<STR_LIT>' <EOL> elif isinf ( thing ) : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return thing <EOL> else : <EOL> return thing </s>
