Class: Fluent::TextParser::WebsphereSysout

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb

Constant Summary collapse

REGEXP_PMRM0003I =
'^.*type=(?<type>.+)\s+detail=(?<detail>.+)\s+elapsed=(?<elapsed>\S+)$'
FORMAT_MAX_NUM =
20

Instance Method Summary collapse

Constructor Details

#initializeWebsphereSysout

Returns a new instance of WebsphereSysout.



19
20
21
22
23
# File 'lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb', line 19

def initialize
  super
  @mutex = Mutex.new
  @regexp_pmrm0003i = Regexp.new(REGEXP_PMRM0003I)
end

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb', line 25

def configure(conf)
  super

  conf["format1"] ||= @format1

  $log.info "format1:  -> "+@format1

  formats = parse_formats(conf).compact.map { |f| f[1..-2] }.join
  $log.info "formats:  -> "+formats
  begin
    @regex = Regexp.new(formats, Regexp::MULTILINE)
    if @regex.named_captures.empty?
      raise "No named captures"
    end
    @parser = RegexpParser.new(@regex, conf)
  rescue => e
    raise ConfigError, "Invalid regexp '#{formats}': #{e}"
  end

  if @format_firstline
    check_format_regexp(@format_firstline, 'format_firstline')
    @firstline_regex = Regexp.new(@format_firstline[1..-2])
  end
end

#firstline?(text) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb', line 160

def firstline?(text)
  @firstline_regex.match(text)
end

#has_firstline?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb', line 156

def has_firstline?
  !!@format_firstline
end

#parse(text, &block) ⇒ Object



50
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fluentd/plugin/parser_multiline_websphere_iib_stdout.rb', line 50

def parse(text, &block)
  m = @regex.match(text)

  unless m
    if block_given?
      yield nil, nil
      return
    else
      return nil, nil
    end
  end

  record = {}
  record["tipolog"] = @tipolog
  record["integration_node"] = @integration_node
  record["integration_server"] = @integration_server
  record["producto"] = @producto
  record["ambiente"] = @ambiente
  record["eventype"] = "INFO"
  record["severity"] = "LOW"
  record["severity_level"] = 5
  record["hostname"] = Socket.gethostname 

  m.names.each { |name|
      if value = m[name]
        case name
        when "timestamp"
          #Se calcula timestmap adicionando timezone
          timestamp = @mutex.synchronize { DateTime.strptime(value,@time_format).strftime(@output_time_format) }
          time = @mutex.synchronize { DateTime.strptime(value,@time_format).to_time.to_i }
          #$log.info "timestamp: #{value+@timezone_offset}"
          record[name] = timestamp 
        when "eventype"
           record[name] = value
           case record[name]
           when "I"
              record["eventype"] = "INFO"
              record["severity"] = "LOW"
              record["severity_level"] = 5
           when "D"
              record["eventype"] = "DETAIL"
              record["severity"] = "LOW"
              record["severity_level"] = 6
           when "E"
              record["eventype"] = "ERROR"
              record["severity"] ="HIGH"
              record["severity_level"] = 5
           when "W"
              record["eventype"] = "WARNING"
              record["severity"] = "MEDIUM"
              record["severity_level"] = 5
           when "F"
              record["eventype"] = "FATAL"
              record["severity"] = "HIGH"
              record["severity_level"] = 4
           when "C"
              record["eventype"] = "CONFIGURATION"
              record["severity"] = "MEDIUM"
              record["severity_level"] = 5
           when "O"
              record["eventype"] = "SYSTEM_OUTPUT"
              record["severity"] = "LOW"
              record["severity_level"] = 5
           when "R"
              record["eventype"] = "SYSTEM_ERROR"
              record["severity"] = "LOW"
              record["severity_level"] = 5
           when "Z"
              record["eventype"] = "NOT_RECOGNIZED"
              record["severity"] = "LOW"
              record["severity_level"] = 5
           end

        when "message"
           case record["msgid"]
           when "PMRM0003I:"
              msg = value
              #Se extrae datos de request metrics
              if requestMetrics = @regexp_pmrm0003i.match(msg)
                 record["type"] = requestMetrics["type"]
                 record["detail"] = requestMetrics["detail"]
                 record["elapsed"] = requestMetrics["elapsed"]
                 record["tipolog"] = 'requestmetrics.'+record["tipolog"]
                 record["mesage"].delete
              end
           else
             record[name] = value
           end
        else
          record[name] = value
        end
      end
    }

  if @estimate_current_event
    time ||= Engine.now
  end

  if block_given?
    yield time, record
  else
    return time, record
  end

end