<commit_before># encoding: UTF-8
require 'json'

class Fluent::ModsecurityFilter < Fluent::Filter
    Fluent::Plugin.register_filter('modsecurity', self)
    def configure(conf)
        super
    end
    def filter(tag, time, record)
        print record['message']
        message = record['message']
        list = message.split(" ")
        file = File.read(list[5])
        data_hash = JSON.parse(file)
        data_hash
    end
end<commit_msg>lookup all record and find detail log path<commit_after># encoding: UTF-8
require 'json'

class Fluent::ModsecurityFilter < Fluent::Filter
    Fluent::Plugin.register_filter('modsecurity', self)

    desc "Path prefix of the detail log"
    config_param :path_prefix, :string, default: "/var/log"

    def configure(conf)
        super
        @path_prefix = conf['path_prefix']
    end

    def filter(tag, time, record)
        log_path = ""
        record.each{ |key, value|
            token = value.split(" ")
            token.each { |v|
                if v.start_with?(@path_prefix)
                    log_path = v
                    break
                end
            }
        }
        file = File.read(log_path)
        data_hash = JSON.parse(file)
        record['detail'] = data_hash
        record
    end
end
{'fraction_non_alphanumeric': 0.105716523101018, 'fraction_numerical': 0.0023492560689115116, 'mean_word_length': 2.0795180722891566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '917803', 'n_tokens_mistral': 376, 'n_tokens_neox': 366, 'n_words': 92}