logstash-output-syslog 0.1.4 → 0.2.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: d333d7299ba493752bafbe7436d06bc9ef9271fa
4
- data.tar.gz: 70c4927dbab0e42ec21a41ed4e2c9831373e0a17
3
+ metadata.gz: adf244fc4a07c51b9b7f855fd561c04904f07776
4
+ data.tar.gz: 02c9b31239c8090938d623b19a091d0a67d7e446
5
5
  SHA512:
6
- metadata.gz: 779056b2cf2b7d8f440c049c56c96a12f4d1da647c6f332d974938bc8e2476bbd71a46c5751f2d6f6176538b5e3da666d806fc102cc125f7260622688982e707
7
- data.tar.gz: 2202189c3f11f2d55594ef6bedbf1d883822db51a4c5a75c00a94f2112e15b8eb819fb1a97ff792dfdb253b5cf1243234a73408ec843d011f5eae51f274dce59
6
+ metadata.gz: 642bae90d7875e24535ec18c8162883f86b78a0eb6feed53124e20e182c3dd3dcf2b55cb0a327c5dfeb97dde765a2e996ad39044ed60d825b50f8866031ac9ec
7
+ data.tar.gz: cdf6c9fdc485edde59acfc49c21eacd8b5a3a85fc20b50ca9ffc14186ad87526e36e787e4967ebfdc6e8fe792f94af3b46addbe17b9b0bf9d4ec2653ad9ec95d
File without changes
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  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.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
16
- Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
17
 
18
18
  ## Developing
19
19
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -7,7 +7,13 @@ require "date"
7
7
  # Send events to a syslog server.
8
8
  #
9
9
  # You can send messages compliant with RFC3164 or RFC5424
10
- # UDP or TCP syslog transport is supported
10
+ # using either UDP or TCP as the transport protocol.
11
+ #
12
+ # By default the contents of the `message` field will be shipped as
13
+ # the free-form message text part of the emitted syslog message. If
14
+ # your messages don't have a `message` field or if you for some other
15
+ # reason want to change the emitted message, modify the `message`
16
+ # configuration option.
11
17
  class LogStash::Outputs::Syslog < LogStash::Outputs::Base
12
18
  config_name "syslog"
13
19
 
@@ -51,10 +57,13 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
51
57
 
52
58
  # syslog server address to connect to
53
59
  config :host, :validate => :string, :required => true
54
-
60
+
55
61
  # syslog server port to connect to
56
62
  config :port, :validate => :number, :required => true
57
63
 
64
+ # when connection fails, retry interval in sec.
65
+ config :reconnect_interval, :validate => :number, :default => 1
66
+
58
67
  # syslog server protocol. you can choose between udp and tcp
59
68
  config :protocol, :validate => ["tcp", "udp"], :default => "udp"
60
69
 
@@ -75,40 +84,27 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
75
84
 
76
85
  # process id for syslog message
77
86
  config :procid, :validate => :string, :default => "-"
78
-
87
+
88
+ # message text to log
89
+ config :message, :validate => :string, :default => "%{message}"
90
+
79
91
  # message id for syslog message
80
92
  config :msgid, :validate => :string, :default => "-"
81
93
 
82
94
  # syslog message format: you can choose between rfc3164 or rfc5424
83
95
  config :rfc, :validate => ["rfc3164", "rfc5424"], :default => "rfc3164"
84
96
 
85
-
86
- public
87
97
  def register
88
- @client_socket = nil
89
- end
90
-
91
- private
92
- def udp?
93
- @protocol == "udp"
94
- end
98
+ @client_socket = nil
95
99
 
96
- private
97
- def rfc3164?
98
- @rfc == "rfc3164"
99
- end
100
+ facility_code = FACILITY_LABELS.index(@facility)
101
+ severity_code = SEVERITY_LABELS.index(@severity)
102
+ @priority = (facility_code * 8) + severity_code
100
103
 
101
- private
102
- def connect
103
- if udp?
104
- @client_socket = UDPSocket.new
105
- @client_socket.connect(@host, @port)
106
- else
107
- @client_socket = TCPSocket.new(@host, @port)
108
- end
104
+ # use instance variable to avoid string comparison for each event
105
+ @is_rfc3164 = (@rfc == "rfc3164")
109
106
  end
110
107
 
111
- public
112
108
  def receive(event)
113
109
  return unless output?(event)
114
110
 
@@ -116,30 +112,42 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
116
112
  procid = event.sprintf(@procid)
117
113
  sourcehost = event.sprintf(@sourcehost)
118
114
 
119
- facility_code = FACILITY_LABELS.index(@facility)
120
-
121
- severity_code = SEVERITY_LABELS.index(@severity)
122
-
123
- priority = (facility_code * 8) + severity_code
124
-
125
- if rfc3164?
115
+ if @is_rfc3164
126
116
  timestamp = event.sprintf("%{+MMM dd HH:mm:ss}")
127
- syslog_msg = "<"+priority.to_s()+">"+timestamp+" "+sourcehost+" "+appname+"["+procid+"]: "+event["message"]
117
+ syslog_msg = "<#{@priority.to_s}>#{timestamp} #{sourcehost} #{appname}[#{procid}]: #{event.sprintf(@message)}"
128
118
  else
129
119
  msgid = event.sprintf(@msgid)
130
- timestamp = event.sprintf("%{+YYYY-MM-dd'T'HH:mm:ss.SSSZ}")
131
- syslog_msg = "<"+priority.to_s()+">1 "+timestamp+" "+sourcehost+" "+appname+" "+procid+" "+msgid+" - "+event["message"]
120
+ timestamp = event.sprintf("%{+YYYY-MM-dd'T'HH:mm:ss.SSSZZ}")
121
+ syslog_msg = "<#{@priority.to_s}>1 #{timestamp} #{sourcehost} #{appname} #{procid} #{msgid} - #{event.sprintf(@message)}"
132
122
  end
133
123
 
134
124
  begin
135
- connect unless @client_socket
125
+ @client_socket ||= connect
136
126
  @client_socket.write(syslog_msg + "\n")
137
127
  rescue => e
138
- @logger.warn(@protocol+" output exception", :host => @host, :port => @port,
139
- :exception => e, :backtrace => e.backtrace)
128
+ @logger.warn("syslog " + @protocol + " output exception: closing, reconnecting and resending event", :host => @host, :port => @port, :exception => e, :backtrace => e.backtrace, :event => event)
140
129
  @client_socket.close rescue nil
141
130
  @client_socket = nil
131
+
132
+ sleep(@reconnect_interval)
133
+ retry
142
134
  end
143
135
  end
144
- end
145
136
 
137
+ private
138
+
139
+ def udp?
140
+ @protocol == "udp"
141
+ end
142
+
143
+ def connect
144
+ socket = nil
145
+ if udp?
146
+ socket = UDPSocket.new
147
+ socket.connect(@host, @port)
148
+ else
149
+ socket = TCPSocket.new(@host, @port)
150
+ end
151
+ socket
152
+ end
153
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-syslog'
4
- s.version = '0.1.4'
4
+ s.version = '0.2.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", '>= 1.4.0', '< 2.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-syslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.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-04-20 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
14
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-codec-plain
54
+ prerelease: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
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: []
@@ -51,9 +65,11 @@ extensions: []
51
65
  extra_rdoc_files: []
52
66
  files:
53
67
  - .gitignore
68
+ - CHANGELOG.md
54
69
  - CONTRIBUTORS
55
70
  - Gemfile
56
71
  - LICENSE
72
+ - NOTICE.TXT
57
73
  - README.md
58
74
  - Rakefile
59
75
  - lib/logstash/outputs/syslog.rb
@@ -81,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
97
  version: '0'
82
98
  requirements: []
83
99
  rubyforge_project:
84
- rubygems_version: 2.1.9
100
+ rubygems_version: 2.4.8
85
101
  signing_key:
86
102
  specification_version: 4
87
103
  summary: Send events to a syslog server.