lib/syslogstash/syslog_reader.rb in syslogstash-0.1.3 vs lib/syslogstash/syslog_reader.rb in syslogstash-0.1.4

- old
+ new

@@ -17,12 +17,13 @@ debug { "#run called" } begin socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0) socket.bind(Socket.pack_sockaddr_un(@file)) - rescue Errno::EEXIST - File.unlink(@file) + rescue Errno::EEXIST, Errno::EADDRINUSE + log { "socket file #{@file} already exists; deleting" + File.unlink(@file) rescue nil retry rescue SystemCallError $stderr.puts "Error while trying to bind to #{@file}" raise end @@ -34,10 +35,11 @@ debug { "Message received: #{msg.inspect}" } process_message msg.first.chomp end ensure socket.close + log { "removing socket file #{@file}" File.unlink(@file) rescue nil end end end @@ -72,11 +74,11 @@ syslog_timestamp: timestamp, severity: severity, facility: facility, hostname: hostname, program: program, - pid: pid, + pid: pid.nil? ? nil : pid.to_i, message: message, ).to_json @logstash.send_entry(log_entry) else @@ -87,15 +89,13 @@ def log_entry(h) {}.tap do |e| e['@version'] = '1' e['@timestamp'] = Time.now.utc.strftime("%FT%T.%LZ") - h['facility_name'] = FACILITIES[h[:facility]] - h['severity_name'] = SEVERITIES[h[:severity]] + h[:facility_name] = FACILITIES[h[:facility]] + h[:severity_name] = SEVERITIES[h[:severity]] e.merge!(h.delete_if { |k,v| v.nil? }) - - e[:pid] = e[:pid].to_i if e.has_key?(:pid) e.merge!(@tags) if @tags.is_a? Hash debug { "Log entry is: #{e.inspect}" } end