Class: LogStash::Inputs::Syslog
- Defined in:
- lib/logstash/inputs/syslog.rb
Overview
Read syslog messages as events over the network.
This input is a good choice if you already use syslog today. It is also a good choice if you want to receive logs from appliances and network devices where you cannot run your own log collector.
Of course, ‘syslog’ is a very muddy term. This input only supports RFC3164 syslog with some small modifications. The date format is allowed to be RFC3164 style or ISO8601. Otherwise the rest of the RFC3164 must be obeyed. If you do not use RFC3164, do not use this input.
Note: this input will start listeners on both TCP and UDP
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
-
#initialize(params) ⇒ Syslog
constructor
A new instance of Syslog.
- #register ⇒ Object
- #run(output_queue) ⇒ Object
- #syslog_relay(event) ⇒ Object
- #teardown ⇒ Object
Methods inherited from Base
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s
Constructor Details
#initialize(params) ⇒ Syslog
Returns a new instance of Syslog.
48 49 50 51 52 |
# File 'lib/logstash/inputs/syslog.rb', line 48 def initialize(params) super @shutdown_requested = false BasicSocket.do_not_reverse_lookup = true end |
Instance Method Details
#register ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/logstash/inputs/syslog.rb', line 55 def register @grok_filter = LogStash::Filters::Grok.new( "overwrite" => "message", "match" => { "message" => "<%{POSINT:priority}>%{SYSLOGLINE}" }, ) @date_filter = LogStash::Filters::Date.new( "match" => [ "timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601"] ) @grok_filter.register @date_filter.register @tcp_clients = ThreadSafe::Array.new end |
#run(output_queue) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/logstash/inputs/syslog.rb', line 72 def run(output_queue) # udp server udp_thr = Thread.new do begin udp_listener(output_queue) rescue => e break if @shutdown_requested @logger.warn("syslog udp listener died", :address => "#{@host}:#{@port}", :exception => e, :backtrace => e.backtrace) sleep(5) retry end # begin end # Thread.new # tcp server tcp_thr = Thread.new do begin tcp_listener(output_queue) rescue => e break if @shutdown_requested @logger.warn("syslog tcp listener died", :address => "#{@host}:#{@port}", :exception => e, :backtrace => e.backtrace) sleep(5) retry end # begin end # Thread.new # If we exit and we're the only input, the agent will think no inputs # are running and initiate a shutdown. udp_thr.join tcp_thr.join end |
#syslog_relay(event) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/logstash/inputs/syslog.rb', line 197 def syslog_relay(event) @grok_filter.filter(event) if event["tags"].nil? || !event["tags"].include?("_grokparsefailure") # Per RFC3164, priority = (facility * 8) + severity # = (facility << 3) & (severity) priority = event["priority"].first.to_i rescue 13 severity = priority & 7 # 7 is 111 (3 bits) facility = priority >> 3 event["priority"] = priority event["severity"] = severity event["facility"] = facility event["timestamp"] = event["timestamp8601"] if event.include?("timestamp8601") @date_filter.filter(event) else @logger.info? && @logger.info("NOT SYSLOG", :message => event["message"]) # RFC3164 says unknown messages get pri=13 priority = 13 event["priority"] = 13 event["severity"] = 5 # 13 & 7 == 5 event["facility"] = 1 # 13 >> 3 == 1 end # Apply severity and facility metadata if # use_labels => true if @use_labels facility_number = event["facility"] severity_number = event["severity"] if @facility_labels[facility_number] event["facility_label"] = @facility_labels[facility_number] end if @severity_labels[severity_number] event["severity_label"] = @severity_labels[severity_number] end end end |
#teardown ⇒ Object
165 166 167 168 169 170 |
# File 'lib/logstash/inputs/syslog.rb', line 165 def teardown @shutdown_requested = true close_udp close_tcp finished end |