예제 #1
0
def check_newdate_file():
    today = get_today()
    # check if new date comes for each log file
    for parse_log in parse_log_list:
        (file_path, log_date, log_type, inode,
         offset) = parse_log.get_file_record()
        if compare_date(today, log_date):
            old_date_str = get_date_str_ex(log_date)
            new_date_str = get_date_str_ex(today)
            new_file_path = file_path.replace(old_date_str, new_date_str)
            if is_file(new_file_path):
                # last time check the old log file then update mysql
                logger.info("last time to check the old file %s" % file_path)
                ret = parse_log.check()
                # update parse_log
                parse_log.set_file_record(new_file_path, today, 0, 0)
                # delete old xml node in xml file
                record_xml.delete_log_record(file_path)
예제 #2
0
def update_logs(date):
    global record_xml
    record_xml = RecordXML(setting.LOG_RECORD_FILE)
    date_str = get_date_str_ex(date)
    for (log_type, log_config) in setting.RULE_MAP.items():
        log_file = log_config["path"]
        log_file = log_file.replace('$DATE', date_str)
        (log_inode, log_off) = record_xml.get_log_record(log_file)
        logger.info("log file %s, log_inode %d", log_file, log_inode)
        tmp_parser_list = []
        for rule in log_config['rules']:
            event_id = rule['rule_id']
            if event_id in parser_list:
                tmp_parser_list.append(parser_list.get(event_id))
        new_parse_log = ParseLog(log_type, tmp_parser_list)
        new_parse_log.set_file_record(log_file, date, log_inode, log_off)
        print '%s %s %s-%s-%s' % (log_file, log_type, date.year, date.month, date.day)
        parse_log_list.append(new_parse_log)