Class: Fluent::Plugin::LogcheckFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::LogcheckFilter
- Extended by:
- T::Sig
- Defined in:
- lib/fluent/plugin/filter_logcheck.rb
Overview
Fluentd filter plugin that applies logcheck rules for log filtering
Instance Method Summary collapse
-
#configure(conf)
Configure the plugin with the provided configuration.
-
#filter(_tag, _time, record) ⇒ Hash{String => T.untyped}?
Filter a log record using logcheck rules.
- #initialize constructor
-
#shutdown
Shutdown the plugin and log final statistics.
-
#start
Start the plugin and initialize statistics.
Constructor Details
#initialize
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fluent/plugin/filter_logcheck.rb', line 51 def initialize super @rule_sets = T.let({}, T::Hash[String, T.untyped]) @rule_engine = T.let(nil, T.untyped) @filter_decision = T.let(nil, T.untyped) @match_accessor = T.let(nil, T.untyped) @statistics = T.let({ processed: 0, ignored: 0, alerted: 0, passed: 0, errors: 0, start_time: nil }, T::Hash[Symbol, T.untyped]) @last_stats_log = T.let(nil, T.nilable(Time)) # Declare configuration variables @match_field = T.let('', String) @default_action = T.let(:keep, Symbol) @mark_matches = T.let(false, T::Boolean) @mark_field_prefix = T.let('', String) @cache_size = T.let(0, Integer) @recursive_scan = T.let(true, T::Boolean) @ignore_parse_errors = T.let(true, T::Boolean) @log_rule_errors = T.let(true, T::Boolean) @max_rules_per_file = T.let(0, Integer) @debug_mode = T.let(false, T::Boolean) @log_statistics = T.let(false, T::Boolean) @statistics_interval = T.let(0, Integer) @rules_file = T.let(nil, T.nilable(String)) @rules_dir = T.let(nil, T.nilable(String)) @rule_configs = T.let([], T::Array[T.untyped]) @rule_priority = T.let([], T::Array[Symbol]) end |
Instance Method Details
#configure(conf)
This method returns an undefined value.
Configure the plugin with the provided configuration
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fluent/plugin/filter_logcheck.rb', line 89 def configure(conf) super # Validate configuration validate_configuration # Create record accessor for match field @match_accessor = record_accessor_create(@match_field) # Initialize components (will be implemented later) initialize_components end |
#filter(_tag, _time, record) ⇒ Hash{String => T.untyped}?
Filter a log record using logcheck rules
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/fluent/plugin/filter_logcheck.rb', line 133 def filter(_tag, _time, record) @statistics[:processed] += 1 # Extract text to match text = extract_match_text(record) if text.nil? || text.empty? log.debug "No text found in field '#{@match_field}', passing record" if @debug_mode @statistics[:passed] += 1 log_periodic_statistics return record end log.debug "Processing message: #{text[0..100]}#{'...' if text.length > 100}" if @debug_mode # Make filtering decision decision = make_filter_decision(text) log.debug "Filter decision: #{decision.decision} (#{decision.description})" if @debug_mode # Apply decision result = apply_decision(record, decision) # Update statistics case decision.decision when Logcheck::FilterDecision::IGNORE @statistics[:ignored] += 1 when Logcheck::FilterDecision::ALERT @statistics[:alerted] += 1 when Logcheck::FilterDecision::PASS @statistics[:passed] += 1 end log_periodic_statistics result rescue StandardError => e @statistics[:errors] += 1 log.error "Error processing record: #{e.}" log.error_backtrace e.backtrace if @debug_mode log_periodic_statistics record # Return original record on error end |
#shutdown
This method returns an undefined value.
Shutdown the plugin and log final statistics
121 122 123 124 125 |
# File 'lib/fluent/plugin/filter_logcheck.rb', line 121 def shutdown super log_final_statistics log.info 'Logcheck filter stopped' end |
#start
This method returns an undefined value.
Start the plugin and initialize statistics
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fluent/plugin/filter_logcheck.rb', line 104 def start super @statistics[:start_time] = Time.now @last_stats_log = Time.now log.info "Logcheck filter started with #{total_rules} rules" log.info "Configuration: match_field=#{@match_field}, default_action=#{@default_action}, mark_matches=#{@mark_matches}" log.info "Debug mode: #{@debug_mode ? 'enabled' : 'disabled'}" log.info "Statistics logging: #{@log_statistics ? "enabled (interval: #{@statistics_interval}s)" : 'disabled'}" return unless @debug_mode log_rule_summary end |