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_debug(output): logger.setLevel(logging.DEBUG) render_servers(servers, output_path) logger.setLevel(logging.INFO) soup = BeautifulSoup(open(output_path), "html.parser") # check debug-label presence assert soup.find_all(style="color: red; padding-right: 10px;") for client_item in soup.find("ul", id="1.onlinetime").find_all("li"): nick = client_item.find("span").text # check for right identifier nick, encl_identifier = nick.split() identifier = encl_identifier.replace("(", "").replace(")", "") assert clients[identifier].nick == nick
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 soup(output): render_servers(servers, output_path) return BeautifulSoup(open(output_path), "html.parser")
def test_parse_utf8(output): servers = parse_logs(testlog_path + '.utf8') render_servers(servers, output)