Last active
December 15, 2015 18:39
-
-
Save jhaubrich/5305944 to your computer and use it in GitHub Desktop.
Help me make this beautiful.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def objectify(frame): | |
""" yeilds one parsed object defined by the parsers in | |
the waas library. | |
""" | |
log_source = frame['log_type'] | |
parsers = {'SP': sp_log.parse, | |
'CP': cp_log.parse, | |
'WAAS': waas_log.parse} | |
try: | |
parsed = parsers[ log_source] | |
except: | |
yield {'channel': 'error.bad_frame', | |
'msg': {'line': frame['lines'], 'site': frame['site_name']}} | |
for line in frame['lines']: | |
for channel, msg in parsed(line): | |
if channel: | |
msg.update({'site': frame['site_name']}) | |
yield {'channel': log_source + '.' + channel, 'msg': msg} | |
else: # channel was None | |
yield {'channel': log_source + '.' + 'UNPARSED', | |
'msg': {'line': line, 'site': frame['site_name']}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment