#!/usr/bin/env python3 # vim: wrapmargin=0 textwidth=0 smarttab expandtab tabstop=2 shiftwidth=2 """Produce a report on the provided EDDN Gateway log file's ERRORs.""" import argparse import fileinput import re import semantic_version def parse_cl_args() -> str: """ Check command-line arguments for input file name. :returns: str - input file name """ parser = argparse.ArgumentParser( prog='eddn-report-log-errors', description='Process an EDDN Gateway log file and report on any ERROR lines found' ) parser.add_argument( 'inputfile', metavar='', help='Name of an EDDN Gateway log file' ) args = parser.parse_args() return args.inputfile def process_file(input_file: str) -> None: print(f'Input file: {input_file}') _RE_ERROR = re.compile( r'^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[\.,][0-9]{3} - ERROR - Gateway:[0-9]+:' r' (?P.+)' r' \((?P[0-9]+),' r' "(?P[^"]*)",' r' "(?P[^"]*)",' r' "(?P[^"]*)",' r' "(?P[^"]*)",' r' "(?P[^"]*)"\)' r' from (?P.+)$' ) # TODO: Make this handle gzipped files with fileinput.FileInput(files=(input_file), mode='r') as input: line = input.readline() while line: line = line.strip() matches = _RE_ERROR.search(line) if matches: # print(matches.group('err_msg')) # print(matches.group('request_size')) # print(matches.group('uploader_id')) # print(matches.group('software_name')) # print(matches.group('software_version')) # print(matches.group('schema_ref')) # print(matches.group('journal_event')) # print(matches.group('sender_ip')) # print('') try: software_version = semantic_version.Version.coerce(matches.group('software_version')) except ValueError as e: print(f"Error parsing sofwareVersion for:\n{matches.group('software_version')}\n{line}\n") next ################################################################### # Issues we know about and HAVE already alerted their # developers to. ################################################################### if matches.group('software_name') == 'EDDiscovery': # https://github.com/EDDiscovery/EDDiscovery/releases/latest if software_version >= semantic_version.Version.coerce('16.0.5.0'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/outfitting/2': err_msg = matches.group('err_msg') if ( err_msg.startswith('Failed Validation "[]') != -1 ): # pass else: print(line) else: print(line) elif matches.group('software_name') == 'EDDLite': # https://github.com/EDDiscovery/EDDLite/releases/latest if software_version >= semantic_version.Version.coerce('2.5.0'): print(line) elif matches.group('software_name') == 'EDDI': # https://github.com/EDCD/EDDI/releases/latest if software_version >= semantic_version.Version.coerce('4.0.2'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/fsssignaldiscovered/1': if matches.group('err_msg').startswith( 'Failed Validation "[ pass elif matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/navroute/1': if matches.group('err_msg').startswith( 'Failed Validation "[ pass else: print(line) elif matches.group('software_name').startswith('E:D Market Connector'): # https://github.com/EDCD/EDMarketConnector/releases/latest if software_version >= semantic_version.Version.coerce('5.7.0'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/journal/1': if matches.group('err_msg').startswith( 'Failed Validation "[ pass elif matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/fsssignaldiscovered/1': if matches.group('err_msg') == 'Failed Validation "[]"': # pass elif matches.group('err_msg') == 'Failed Validation "[]"': # pass else: print(line) else: print(line) elif matches.group('software_name') == 'Elite G19s Companion App': # if software_version >= semantic_version.Version.coerce('3.7.7888.21039'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/commodity/3': if matches.group('err_msg') == 'Failed Validation "[]"': # Reported via Frontier forums: pass else: print(line) else: print(line) elif matches.group('software_name') == 'EDSM': # It's in-browser, no public source/releases if software_version >= semantic_version.Version.coerce('1.0.3'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/journal/1': if matches.group('journal_event') == 'Scan': # if matches.group('err_msg').startswith( 'Failed Validation "[]"' ): pass elif ( matches.group('err_msg').startswith('Failed Validation "[]"') ): # pass else: print(matches.group('err_msg')) print(line) else: print(line) else: print(line) elif matches.group('software_name') == 'EDSM - Console': # It's in-browser, no public source/releases if software_version >= semantic_version.Version.coerce('1.0.2'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/journal/1': if matches.group('journal_event') == 'Scan': # if not matches.group('err_msg').startswith( 'Failed Validation "[= semantic_version.Version.coerce('1.2.3'): if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/journal/1': if matches.group('journal_event') == 'Docked': # if matches.group('err_msg').startswith( 'Failed Validation "[ if matches.group('err_msg').startswith( 'Failed Validation "[]"' ): pass else: print(line) else: print(line) elif matches.group('software_name') == 'EliteLogAgent': # if software_version >= semantic_version.Version.coerce('2.0.0.660'): print(line) # # elif matches.group('software_name') == 'Moonlight': if matches.group('software_version') == '1.3.4': if matches.group('schema_ref') == 'https://eddn.edcd.io/schemas/journal/1': if matches.group('journal_event') == 'Scan': # Ref: if not matches.group('err_msg').startswith( 'Failed Validation "[ # elif matches.group('software_name') in ('EVA [iPhone]', 'EVA [iPad]', 'EVA [Android]'): pass ################################################################### # Issues we know about, but haven't yet alerted developers to ################################################################### ################################################################### else: print(line) line = input.readline() if __name__ == "__main__": input_file = parse_cl_args() process_file(input_file)