logstash-output-syslog 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38b00918482b4c1e4fb3ba8e0cf8e6de277f18dc
4
- data.tar.gz: 09006c2489b94dbee2efec1185bfeceb967b56d8
3
+ metadata.gz: fed3005266aeadaa979f5943e57231766a852a1c
4
+ data.tar.gz: e9b7625982c94a62f18e80d7819fb23681ed65a8
5
5
  SHA512:
6
- metadata.gz: 07d83b6c7309ac0cb56c8e6fba651f890752fd1365e0372309e435d058cc951eb4702fe17b3c5d4ece5a17edc7a3cfd74c300fe17ecd27041293cfa5fb18e1d5
7
- data.tar.gz: 7326764644336b210094fec45728c45d6cd6ddda36b5c5e9b3e327300849ef7c7030acf8f0ae271eb53067c406ca35f523b8e7fc4515cf6b6949739fc142c4b1
6
+ metadata.gz: 876f0086824fb91936086645f1290f2864b450c301a9f5201512f8f3d75ed01d162cfe9ec203669a3578132b57a31b94729c18a33132d74f64ff624da8904880
7
+ data.tar.gz: cf49d0c4b980c542333d4691d3fb57d0f531439a8649cffb661b917795388a33bf42dbabfa7b6435c73626bb7eb3b82ee1223f347a517434d16654bfb8d2fdef
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ ## 2.1.0
2
+ - reconnect on exception. added basic specs
3
+
1
4
  ## 2.0.0
2
- - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
5
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
6
  instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
7
  - Dependency on logstash-core update to 2.0
5
8
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Logstash Plugin
2
2
 
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-syslog-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-syslog-unit/)
5
+
3
6
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
7
 
5
8
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
@@ -57,10 +57,13 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
57
57
 
58
58
  # syslog server address to connect to
59
59
  config :host, :validate => :string, :required => true
60
-
60
+
61
61
  # syslog server port to connect to
62
62
  config :port, :validate => :number, :required => true
63
63
 
64
+ # when connection fails, retry interval in sec.
65
+ config :reconnect_interval, :validate => :number, :default => 1
66
+
64
67
  # syslog server protocol. you can choose between udp and tcp
65
68
  config :protocol, :validate => ["tcp", "udp"], :default => "udp"
66
69
 
@@ -84,71 +87,65 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
84
87
 
85
88
  # message text to log
86
89
  config :message, :validate => :string, :default => "%{message}"
87
-
90
+
88
91
  # message id for syslog message
89
92
  config :msgid, :validate => :string, :default => "-"
90
93
 
91
94
  # syslog message format: you can choose between rfc3164 or rfc5424
92
95
  config :rfc, :validate => ["rfc3164", "rfc5424"], :default => "rfc3164"
93
96
 
94
-
95
- public
96
97
  def register
97
- @client_socket = nil
98
- end
99
-
100
- private
101
- def udp?
102
- @protocol == "udp"
103
- end
98
+ @client_socket = nil
104
99
 
105
- private
106
- def rfc3164?
107
- @rfc == "rfc3164"
108
- end
100
+ facility_code = FACILITY_LABELS.index(@facility)
101
+ severity_code = SEVERITY_LABELS.index(@severity)
102
+ @priority = (facility_code * 8) + severity_code
109
103
 
110
- private
111
- def connect
112
- if udp?
113
- @client_socket = UDPSocket.new
114
- @client_socket.connect(@host, @port)
115
- else
116
- @client_socket = TCPSocket.new(@host, @port)
117
- end
104
+ # use instance variable to avoid string comparison for each event
105
+ @is_rfc3164 = (@rfc == "rfc3164")
118
106
  end
119
107
 
120
- public
121
108
  def receive(event)
122
-
123
-
124
109
  appname = event.sprintf(@appname)
125
110
  procid = event.sprintf(@procid)
126
111
  sourcehost = event.sprintf(@sourcehost)
127
112
 
128
- facility_code = FACILITY_LABELS.index(@facility)
129
-
130
- severity_code = SEVERITY_LABELS.index(@severity)
131
-
132
- priority = (facility_code * 8) + severity_code
133
-
134
- if rfc3164?
113
+ if @is_rfc3164
135
114
  timestamp = event.sprintf("%{+MMM dd HH:mm:ss}")
136
- syslog_msg = "<"+priority.to_s()+">"+timestamp+" "+sourcehost+" "+appname+"["+procid+"]: "+event.sprintf(@message)
115
+ syslog_msg = "<#{@priority.to_s}>#{timestamp} #{sourcehost} #{appname}[#{procid}]: #{event.sprintf(@message)}"
137
116
  else
138
117
  msgid = event.sprintf(@msgid)
139
118
  timestamp = event.sprintf("%{+YYYY-MM-dd'T'HH:mm:ss.SSSZZ}")
140
- syslog_msg = "<"+priority.to_s()+">1 "+timestamp+" "+sourcehost+" "+appname+" "+procid+" "+msgid+" - "+event.sprintf(@message)
119
+ syslog_msg = "<#{@priority.to_s}>1 #{timestamp} #{sourcehost} #{appname} #{procid} #{msgid} - #{event.sprintf(@message)}"
141
120
  end
142
121
 
143
122
  begin
144
- connect unless @client_socket
123
+ @client_socket ||= connect
145
124
  @client_socket.write(syslog_msg + "\n")
146
125
  rescue => e
147
- @logger.warn(@protocol+" output exception", :host => @host, :port => @port,
148
- :exception => e, :backtrace => e.backtrace)
126
+ @logger.warn("syslog " + @protocol + " output exception: closing, reconnecting and resending event", :host => @host, :port => @port, :exception => e, :backtrace => e.backtrace, :event => event)
149
127
  @client_socket.close rescue nil
150
128
  @client_socket = nil
129
+
130
+ sleep(@reconnect_interval)
131
+ retry
151
132
  end
152
133
  end
153
- end
154
134
 
135
+ private
136
+
137
+ def udp?
138
+ @protocol == "udp"
139
+ end
140
+
141
+ def connect
142
+ socket = nil
143
+ if udp?
144
+ socket = UDPSocket.new
145
+ socket.connect(@host, @port)
146
+ else
147
+ socket = TCPSocket.new(@host, @port)
148
+ end
149
+ socket
150
+ end
151
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-syslog'
4
- s.version = '2.0.2'
4
+ s.version = '2.1.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Send events to a syslog server."
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
24
24
 
25
25
  s.add_development_dependency 'logstash-devutils'
26
+ s.add_development_dependency 'logstash-codec-plain'
26
27
  end
27
28
 
@@ -1 +1,50 @@
1
+ # encoding: utf-8
2
+
1
3
  require "logstash/devutils/rspec/spec_helper"
4
+ require "logstash/outputs/syslog"
5
+
6
+ describe LogStash::Outputs::Syslog do
7
+
8
+ it "should register without errors" do
9
+ plugin = LogStash::Plugin.lookup("output", "syslog").new({"host" => "foo", "port" => "123", "facility" => "kernel", "severity" => "emergency"})
10
+ expect { plugin.register }.to_not raise_error
11
+ end
12
+
13
+ subject do
14
+ plugin = LogStash::Plugin.lookup("output", "syslog").new(options)
15
+ plugin.register
16
+ plugin
17
+ end
18
+
19
+ let(:socket) { double("fake socket") }
20
+ let(:event) { LogStash::Event.new({"message" => "bar", "host" => "baz"}) }
21
+
22
+ shared_examples "syslog output" do
23
+ it "should write expected format" do
24
+ expect(subject).to receive(:connect).and_return(socket)
25
+ expect(socket).to receive(:write).with(output)
26
+ subject.receive(event)
27
+ end
28
+ end
29
+
30
+ context "rfc 3164 and udp by default" do
31
+ let(:options) { {"host" => "foo", "port" => "123", "facility" => "kernel", "severity" => "emergency"} }
32
+ let(:output) { /^<0>.+baz LOGSTASH\[-\]: bar\n/m }
33
+
34
+ it_behaves_like "syslog output"
35
+ end
36
+
37
+ context "rfc 5424 and tcp" do
38
+ let(:options) { {"rfc" => "rfc5424", "protocol" => "tcp", "host" => "foo", "port" => "123", "facility" => "kernel", "severity" => "emergency"} }
39
+ let(:output) { /^<0>1 .+baz LOGSTASH - - - bar\n/m }
40
+
41
+ it_behaves_like "syslog output"
42
+ end
43
+
44
+ context "calculate priority" do
45
+ let(:options) { {"host" => "foo", "port" => "123", "facility" => "mail", "severity" => "critical"} }
46
+ let(:output) { /^<18>.+baz LOGSTASH\[-\]: bar\n/m }
47
+
48
+ it_behaves_like "syslog output"
49
+ end
50
+ end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-syslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
@@ -19,10 +20,7 @@ dependencies:
19
20
  - - <
20
21
  - !ruby/object:Gem::Version
21
22
  version: 3.0.0
22
- name: logstash-core
23
- prerelease: false
24
- type: :runtime
25
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: !ruby/object:Gem::Requirement
26
24
  requirements:
27
25
  - - '>='
28
26
  - !ruby/object:Gem::Version
@@ -30,35 +28,51 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 3.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '>='
37
43
  - !ruby/object:Gem::Version
38
44
  version: '0'
39
- name: logstash-devutils
40
45
  prerelease: false
41
46
  type: :development
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-codec-plain
42
49
  version_requirements: !ruby/object:Gem::Requirement
43
50
  requirements:
44
51
  - - '>='
45
52
  - !ruby/object:Gem::Version
46
53
  version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
47
61
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
48
62
  email: info@elastic.co
49
63
  executables: []
50
64
  extensions: []
51
65
  extra_rdoc_files: []
52
66
  files:
67
+ - lib/logstash/outputs/syslog.rb
68
+ - spec/outputs/syslog_spec.rb
69
+ - logstash-output-syslog.gemspec
53
70
  - CHANGELOG.md
71
+ - README.md
54
72
  - CONTRIBUTORS
55
73
  - Gemfile
56
74
  - LICENSE
57
75
  - NOTICE.TXT
58
- - README.md
59
- - lib/logstash/outputs/syslog.rb
60
- - logstash-output-syslog.gemspec
61
- - spec/outputs/syslog_spec.rb
62
76
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
63
77
  licenses:
64
78
  - Apache License (2.0)
@@ -81,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
95
  version: '0'
82
96
  requirements: []
83
97
  rubyforge_project:
84
- rubygems_version: 2.4.8
98
+ rubygems_version: 2.1.9
85
99
  signing_key:
86
100
  specification_version: 4
87
101
  summary: Send events to a syslog server.