Class: Bosh::Agent::SyslogMonitor::Server

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EM::Protocols::LineText2
Defined in:
lib/bosh_agent/syslog_monitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(nats, agent_id) ⇒ Server

Returns a new instance of Server.



17
18
19
20
# File 'lib/bosh_agent/syslog_monitor.rb', line 17

def initialize(nats, agent_id)
  @nats = nats
  @agent_id = agent_id
end

Instance Method Details

#receive_line(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bosh_agent/syslog_monitor.rb', line 22

def receive_line(data)
  parsed = SyslogProtocol.parse(data)

  if parsed.content.end_with?('disconnected by user')
    title = 'SSH Logout'
  elsif parsed.content.include?('Accepted publickey for')
    title = 'SSH Login'
  else
    return
  end

  json = Yajl::Encoder.encode(
    {
      'id' => UUIDTools::UUID.random_create,
      'severity' => SEVERITY,
      'title' => title,
      'summary' => parsed.content,
      'created_at' => Time.now.to_i
    }
  )
  @nats.publish("hm.agent.alert.#{@agent_id}", json)
end