Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
Never
def filter_log_data(input_file):
    print(f"Filtering data in {input_file}")
    # Define the list of important words
    important_words = ['unauthorized', 'error', 'kernel error', 'OS error', 'rejected', 'warning', "error", "fail", "exception", "critical",
            "security", "authentication", "intrusion", "attack", "status", "performance", "uptime", "load", "config", "setting", "permission", "firewall",
            "debug", "trace", "stack"]
    
    # Define the output filename
    output_file = f"{input_file.replace('.txt', '-filtered.txt')}"

    # Open the input and output files
    with open(input_file, 'r') as input_file, open(output_file, 'w') as output_file:
        # Loop through each line in the input file
        for line in input_file:
            # Check if any of the important words appear in the line
            if any(word in line.lower() for word in important_words):
                # If yes, write the line to the output file
                output_file.write(line)
    # Return the output filename
    #return output_file