def test_log_client_online(): current_time = pendulum.now() pendulum.set_test_now(current_time) clients = list(parse_logs(testlog_path))[0].clients old_onlinetime = int(clients['1'].onlinetime.total_seconds()) pendulum.set_test_now(current_time.add(seconds=2)) # add 2s to .now() clients = list(parse_logs(testlog_path))[0].clients assert int(clients['1'].onlinetime.total_seconds()) == old_onlinetime + 2
def main(configuration): if configuration.getboolean('General', 'debug'): logger.setLevel(logging.DEBUG) idmap = configuration.get('General', 'idmap') if idmap: idmap = abspath(idmap) if not exists(idmap): logger.fatal('identmap not found (%s)', idmap) # read id_map identmap = json.load(open(idmap)) else: identmap = None log = configuration.get('General', 'log') if not log: raise InvalidConfiguration('log or output missing') servers = parse_logs( log, ident_map=identmap, online_dc=configuration.getboolean('General', 'onlinedc') ) render_servers( sorted(servers, key=lambda s: s.sid), output=abspath(configuration.get('General', 'output')), template=configuration.get('General', 'template'), datetime_fmt=configuration.get('General', 'datetimeformat'), onlinetime_threshold=int(configuration.get( 'General', 'onlinetimethreshold')) )
def test_ident_map_wrong_identifier(): clients = list( parse_logs('tsstats/tests/res/test.log.identmap_wrong_identifier', ident_map={ '2': '1', '3': '1' }))[0].clients client = clients.get('1') # assert client exists assert client # assert correct identifier assert client.identifier == '1'
def main(configuration): start_time = time() # setup logging if configuration.getboolean('General', 'debug'): logger.setLevel(logging.DEBUG) if configuration.getboolean('General', 'debugstdout'): stream_handler.setLevel(logging.DEBUG) else: logger.addHandler(file_handler) # attach handlers logger.addHandler(stream_handler) idmap = configuration.get('General', 'idmap') if idmap: idmap = abspath(idmap) if not exists(idmap): logger.fatal('identmap not found (%s)', idmap) # read id_map identmap = json.load(open(idmap)) else: identmap = None if isinstance(identmap, list): identmap = transform_pretty_identmap(identmap) log = configuration.get('General', 'log') if not log: raise InvalidConfiguration('log or output missing') if isdir(log): log = pathjoin(log, '*.log') servers = parse_logs(log, ident_map=identmap, online_dc=configuration.getboolean( 'General', 'onlinedc')) render_servers(sorted(servers, key=lambda s: s.sid), output=abspath(configuration.get('General', 'output')), template=configuration.get('General', 'template'), datetime_fmt=configuration.get('General', 'datetimeformat'), onlinetime_threshold=int( configuration.get('General', 'onlinetimethreshold')), lastseen_relative=configuration.getboolean( 'General', 'lastseenrelative')) logger.info('Finished after %s seconds', time() - start_time)
def test_parse_utf8(output): servers = parse_logs(testlog_path + '.utf8') render_servers(servers, output)
def test_parse_groups(): server = list(parse_logs('tsstats/tests/res/test.log.groups')) assert len(server) == 0
def clients(): return list(parse_logs(testlog_path, online_dc=False))[0].clients