Class: Fluent::Plugin::Logcheck::Rule

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(raw_pattern, type, source_file, line_number)

Initialize a new rule

Parameters:

  • raw_pattern (String)

    Original regex pattern string

  • type (Symbol)

    Rule type (:ignore, :cracking, :violations)

  • source_file (String)

    Path to source file

  • line_number (Integer)

    Line number in source file



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_numberInteger (readonly)

Returns:

  • (Integer)


39
40
41
# File 'lib/fluent/plugin/logcheck/rule.rb', line 39

def line_number
  @line_number
end

#raw_patternString (readonly)

Returns:

  • (String)


30
31
32
# File 'lib/fluent/plugin/logcheck/rule.rb', line 30

def raw_pattern
  @raw_pattern
end

#source_fileString (readonly)

Returns:

  • (String)


36
37
38
# File 'lib/fluent/plugin/logcheck/rule.rb', line 36

def source_file
  @source_file
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


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

Parameters:

  • text (T.untyped)

    Text to match against

Returns:

  • (Boolean)

    True if pattern matches



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.message}"
end

#metadataHash{Symbol => T.untyped}

Get rule metadata

Returns:

  • (Hash{Symbol => T.untyped})

    Rule metadata including type, source file, line number, and pattern



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

#patternRegexp

Get compiled regex pattern (lazy compilation)

Returns:

  • (Regexp)

    Compiled regex pattern



71
72
73
# File 'lib/fluent/plugin/logcheck/rule.rb', line 71

def pattern
  @pattern ||= compile_pattern
end