Class: LanGrove::Protocol::Syslog

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/protocol/syslog.rb

Instance Method Summary collapse

Instance Method Details

#decode(message) ⇒ Object



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

def decode( message )
  
  #
  # eg:
  # 
  # <NN>Apr  4 11:00:06 host.domain.com puppet[29206]: Event message
  #

  pass     = message.split('>')[1].split()
  time     = Time.at( DateTime.parse( pass[0..2].join(' ') ).strftime( "%s" ).to_i )
  hostname = pass[3]
  message  = pass[4..-1].join(' ').split(': ',2)

  hostname.gsub!( /vlan[\d]*\./, '')
  
  @decoded = {
    :timestamp => time,         # DateTime object
    :hostname  => hostname,     # without prepended vlanN
    :tag       => message[0],   # includes[PID]
    :event     => message[1]    # everything after the colon after the tag
  }
  
  return @decoded
  
end