Module: SentryFS

Defined in:
lib/sentry_fs.rb

Defined Under Namespace

Classes: Event

Constant Summary collapse

EXPRESSIONS =
{
  global: /\A\S+ \S+ \[(?<level>WARNING|ALERT|CRIT|ERR)\] (?<line>\S+) (?<message>.*)\z/,
  session: /\A(?<uuid>\S+) \S+ \S+ \[(?<level>WARNING|ALERT|CRIT|ERR)\] (?<line>\S+) (?<message>.*)\z/,
  odbc: /\A(?<message>.*CODE.*ERROR.*)\z/
}

Class Method Summary collapse

Class Method Details

.capture(event) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/sentry_fs.rb', line 55

def self.capture(event)
  Raven.capture_message(event.message, {
    level: event.level,
    extra: {
      uuid: event.uuid,
      full_message: event.full_message
    }.merge(event.extra)
  })
end

.parse(log_line) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sentry_fs.rb', line 26

def self.parse(log_line)
  log_line.chomp!
  EXPRESSIONS.each {|name, regexp|
    match = log_line.match(regexp)
    if match
      uuid = match.names.include?("uuid") ? match[:uuid] : nil
      line = match.names.include?("line") ? match[:line] : nil
      level = match.names.include?("level") ? match[:level].downcase : "err"
      begin
        json = JSON.parse(match[:message])
        message = json["message"]
        extra = json["extra"]
      rescue JSON::ParserError
        message = [line, match[:message]].compact.join(" ")
        extra = {}
      end
      event = Event.new(
        uuid: uuid,
        message: message,
        full_message: log_line,
        extra: extra,
        level: level
      )
      return event
    end
  }
  nil
end