Class: Fluent::Plugin::Logcheck::Rule
- Inherits:
-
Object
- Object
- Fluent::Plugin::Logcheck::Rule
- Extended by:
- T::Sig
- Defined in:
- lib/fluent/plugin/logcheck/rule.rb
Overview
Represents a single logcheck rule with pattern matching capability
Instance Attribute Summary collapse
- #line_number ⇒ Integer readonly
- #raw_pattern ⇒ String readonly
- #source_file ⇒ String readonly
- #type ⇒ Symbol readonly
Instance Method Summary collapse
-
#initialize(raw_pattern, type, source_file, line_number)
constructor
Initialize a new rule.
-
#match?(text) ⇒ Boolean
Test if rule matches given text.
-
#metadata ⇒ Hash{Symbol => T.untyped}
Get rule metadata.
-
#pattern ⇒ Regexp
Get compiled regex pattern (lazy compilation).
Constructor Details
#initialize(raw_pattern, type, source_file, line_number)
Initialize a new rule
47 48 49 50 51 52 53 54 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 47 def initialize(raw_pattern, type, source_file, line_number) @raw_pattern = raw_pattern @type = type @source_file = source_file @line_number = line_number @compiled_pattern = T.let(nil, T.nilable(Regexp)) @pattern = T.let(nil, T.nilable(Regexp)) end |
Instance Attribute Details
#line_number ⇒ Integer (readonly)
39 40 41 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 39 def line_number @line_number end |
#raw_pattern ⇒ String (readonly)
30 31 32 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 30 def raw_pattern @raw_pattern end |
#source_file ⇒ String (readonly)
36 37 38 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 36 def source_file @source_file end |
#type ⇒ Symbol (readonly)
33 34 35 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 33 def type @type end |
Instance Method Details
#match?(text) ⇒ Boolean
Test if rule matches given text
60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 60 def match?(text) return false if text.nil? pattern.match?(text.to_s) rescue StandardError => e raise PatternCompileError, "Failed to match pattern '#{@raw_pattern}': #{e.}" end |
#metadata ⇒ Hash{Symbol => T.untyped}
Get rule metadata
78 79 80 81 82 83 84 85 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 78 def { type: @type, source_file: @source_file, line_number: @line_number, pattern: @raw_pattern } end |
#pattern ⇒ Regexp
Get compiled regex pattern (lazy compilation)
71 72 73 |
# File 'lib/fluent/plugin/logcheck/rule.rb', line 71 def pattern @pattern ||= compile_pattern end |