Class: Haproxy2Rpm::SyslogHandler

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/haproxy2rpm/syslog.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SyslogHandler

Returns a new instance of SyslogHandler.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/haproxy2rpm/syslog.rb', line 7

def initialize(*args)
  # The syslog parsing stuff here taken from the 'logporter' gem.
  pri = "(?:<(?<pri>[0-9]{1,3})>)?"
  month = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
  day = "(?: [1-9]|[12][0-9]|3[01])"
  hour = "(?:[01][0-9]|2[0-4])"
  minute = "(?:[0-5][0-9])"
  second = "(?:[0-5][0-9])"
  time = [hour, minute, second].join(":")
  timestamp = "(?<timestamp>#{month} #{day} #{time})"
  hostname = "(?<hostname>[A-Za-z0-9_.:\-]+)"
  header = timestamp + " " + hostname
  tag = '(?<tag>[a-zA-Z_\-\/\.0-9\[\]]+)'
  message = "(?<message>[ -~]+)"  # ascii 32 to 126
  re = "^#{pri}#{header} #{tag}:\s*#{message}"

  if RUBY_VERSION =~ /^1\.8/
    # Ruby 1.8 doesn't support named captures
    # replace (?<foo> with (
    re = re.gsub(/\(\?<[^>]+>/, "(")
  end

  @syslog3164_re = Regexp.new(re)
end

Instance Method Details

#parse_data(data) ⇒ Object



41
42
43
# File 'lib/haproxy2rpm/syslog.rb', line 41

def parse_data(data)
  @syslog3164_re.match(data)
end

#receive_data(data) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/haproxy2rpm/syslog.rb', line 32

def receive_data(data)
  match = parse_data(data)
  message = match ? match[5] : ""
  Haproxy2Rpm.logger.debug "RECEIVED (syslog): #{data}"
  Haproxy2Rpm.logger.debug "PARSED DATA (syslog): #{match.inspect}"
  Haproxy2Rpm.logger.debug "PARSED PAYLOAD (syslog): #{message}"
  Haproxy2Rpm.rpm.process_and_send(message)
end