Class: LogStash::Inputs::Syslog
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Syslog
show all
- Defined in:
- lib/logstash/inputs/syslog.rb
Defined Under Namespace
Classes: TCPInput, UDPInput
Instance Attribute Summary
Attributes inherited from Base
#logger
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #tag
Instance Method Details
#receive(host, port, message) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/logstash/inputs/syslog.rb', line 31
def receive(host, port, message)
url = @url.clone
url.host = host
url.port = port
event = LogStash::Event.new({
"@message" => message,
"@type" => @type,
"@tags" => @tags.clone,
})
syslog_relay(event, url)
@logger.debug(["Got event", event.class, event.to_hash])
@callback.call(event)
end
|
#register ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/logstash/inputs/syslog.rb', line 10
def register
if !@url.host or !@url.port
@logger.fatal("No host or port given in #{self.class}: #{@url}")
raise "configuration error"
end
@logger.info("Starting tcp listener for #{@url}")
EventMachine::start_server(@url.host, @url.port, TCPInput, self, @logger)
@logger.info("Starting udp listener for #{@url}")
EventMachine::open_datagram_socket(@url.host, @url.port, UDPInput, self,
@logger)
@@syslog_re ||= \
/(?:<([0-9]{1,3})>)?([A-z]{3} ?[0-9]{1,2} [0-9]{2}:[0-9]{2}:[0-9]{2}) (?:(\S+[^:]) )?(.*)/
end
|
#syslog_relay(event, url) ⇒ Object
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
|
# File 'lib/logstash/inputs/syslog.rb', line 54
def syslog_relay(event, url)
match = @@syslog_re.match(event.message)
if match
priority = match[1].to_i
severity = priority & 7 facility = priority >> 3
event.fields["priority"] = priority
event.fields["severity"] = severity
event.fields["facility"] = facility
event.timestamp = LogStash::Time.to_iso8601(
DateTime.strptime(match[2], "%b %d %H:%M:%S"))
url.host = match[3]
url.port = nil
event.source = url
event.message = match[4]
else
@logger.info(["NOT SYSLOG", event.message])
url.host = Socket.gethostname if url.host == "127.0.0.1"
priority = 13
severity = priority & 7 facility = priority >> 3
event.fields["priority"] = 13
event.fields["severity"] = 5 event.fields["facility"] = 1
event.source = url
end
end
|