Skip to content

Instantly share code, notes, and snippets.

@jhaubrich
Last active December 15, 2015 18:39
Show Gist options
  • Save jhaubrich/5305944 to your computer and use it in GitHub Desktop.
Save jhaubrich/5305944 to your computer and use it in GitHub Desktop.
Help me make this beautiful.
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