logstash-input-gelfx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6948305aa36cdbbc985d055d43b190ab73420c4
4
+ data.tar.gz: 9e69725af6292ef8239d866cf100ae4be550006d
5
+ SHA512:
6
+ metadata.gz: 18ac409ad7295e05ff78e8c9b0060293e10ef080681283aad4395f04ae50b0bc43b51b1c4a72bf4252238b189de9303a3d6eea6e9cf3d0cea25a4d0d4a1ce3ba
7
+ data.tar.gz: 938a4d884c46e1813b7a7c88167238fb91d09bba7ec218266b7b07f00d808a5a0fa483ee99338a9bb80ace6f5ecb3eed9c63213962d24f7a6bf01ecbf6766545
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## 3.0.2
2
+ - Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
3
+
4
+ ## 3.0.1
5
+ - Republish all the gems under jruby.
6
+ ## 3.0.0
7
+ - Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141
8
+ ## 2.0.8
9
+ - Make the `Event.from_json` return a single element instead of an array and make this plugin works under 5.0
10
+ ## 2.0.7
11
+ - Fix failing test caused by reverting Java Event back to Ruby Event
12
+ ## 2.0.6
13
+ - Fix plugin crash when Logstash::Json fails to parse a message, https://github.com/logstash-plugins/logstash-input-gelf/pull/27
14
+ ## 2.0.5
15
+ - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
16
+ ## 2.0.4
17
+ - New dependency requirements for logstash-core for the 5.0 release
18
+ ## 2.0.3
19
+ - Fix Timestamp coercion to preserve upto microsecond precision, https://github.com/logstash-plugins/logstash-input-gelf/pull/35
20
+ ## 2.0.0
21
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
22
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
23
+ - Dependency on logstash-core update to 2.0
data/CONTRIBUTORS ADDED
@@ -0,0 +1,23 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Bernd Ahlers (bernd)
6
+ * Chris McCoy (lofidellity)
7
+ * Colin Surprenant (colinsurprenant)
8
+ * JeremyEinfeld
9
+ * John E. Vincent (lusis)
10
+ * Jordan Sissel (jordansissel)
11
+ * Kurt Hurtado (kurtado)
12
+ * Nick Ethier (nickethier)
13
+ * Pete Fritchman (fetep)
14
+ * Pier-Hugues Pellerin (ph)
15
+ * Richard Pijnenburg (electrical)
16
+ * Suyog Rao (suyograo)
17
+ * joe miller (joemiller)
18
+ * Guy Boertje (guyboertje)
19
+
20
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
21
+ Logstash, and you aren't on the list above and want to be, please let us know
22
+ and we'll make sure you're here. Contributions from folks like you are what make
23
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logstash-mass_effect.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -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 ADDED
@@ -0,0 +1,103 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
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
+
7
+ ## Modification by Leffen
8
+ I am using the gelf plugin as a forwarder to rabbitmq and a "possible" way to enhance the data.
9
+ So I have removed all intrinsic changes to the messages so they go unmodified from source to destination.
10
+ Only adding source_host as a field. Also only support logstash 2.3 and above. Espesiaclly bothersome with official version
11
+ is the meddeling with the timestamp.
12
+
13
+
14
+ ## Documentation
15
+
16
+ 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/).
17
+
18
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
19
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
20
+
21
+ ## Need Help?
22
+
23
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
24
+
25
+ ## Developing
26
+
27
+ ### 1. Plugin Developement and Testing
28
+
29
+ #### Code
30
+ - To get started, you'll need JRuby with the Bundler gem installed.
31
+
32
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
33
+
34
+ - Install dependencies
35
+ ```sh
36
+ bundle install
37
+ ```
38
+
39
+ #### Test
40
+
41
+ - Update your dependencies
42
+
43
+ ```sh
44
+ bundle install
45
+ ```
46
+
47
+ - Run tests
48
+
49
+ ```sh
50
+ bundle exec rspec
51
+ ```
52
+
53
+ ### 2. Running your unpublished Plugin in Logstash
54
+
55
+ #### 2.1 Run in a local Logstash clone
56
+
57
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
58
+ ```ruby
59
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
60
+ ```
61
+ - Install plugin
62
+ ```sh
63
+ # Logstash 2.3 and higher
64
+ bin/logstash-plugin install --no-verify
65
+
66
+ # Prior to Logstash 2.3
67
+ bin/plugin install --no-verify
68
+
69
+ ```
70
+ - Run Logstash with your plugin
71
+ ```sh
72
+ bin/logstash -e 'filter {awesome {}}'
73
+ ```
74
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
75
+
76
+ #### 2.2 Run in an installed Logstash
77
+
78
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
79
+
80
+ - Build your plugin gem
81
+ ```sh
82
+ gem build logstash-filter-awesome.gemspec
83
+ ```
84
+ - Install the plugin from the Logstash home
85
+ ```sh
86
+ # Logstash 2.3 and higher
87
+ bin/logstash-plugin install --no-verify
88
+
89
+ # Prior to Logstash 2.3
90
+ bin/plugin install --no-verify
91
+
92
+ ```
93
+ - Start Logstash and proceed to test the plugin
94
+
95
+ ## Contributing
96
+
97
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
98
+
99
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
100
+
101
+ It is more important to the community that you are able to contribute.
102
+
103
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "logstash/json"
5
+ require "logstash/timestamp"
6
+ require "stud/interval"
7
+ require "date"
8
+ require "socket"
9
+
10
+ # This input will read GELF messages as events over the network,
11
+ # making it a good choice if you already use Graylog2 today.
12
+ #
13
+ #
14
+ class LogStash::Inputs::Gelf < LogStash::Inputs::Base
15
+ config_name "gelfx"
16
+
17
+ default :codec, "plain"
18
+
19
+ # The IP address or hostname to listen on.
20
+ config :host, :validate => :string, :default => "0.0.0.0"
21
+
22
+ # The port to listen on. Remember that ports less than 1024 (privileged
23
+ # ports) may require root to use.
24
+ config :port, :validate => :number, :default => 9397
25
+
26
+
27
+ RECONNECT_BACKOFF_SLEEP = 5
28
+ TIMESTAMP_GELF_FIELD = "timestamp".freeze
29
+ SOURCE_HOST_FIELD = "source_host".freeze
30
+ MESSAGE_FIELD = "message"
31
+ TAGS_FIELD = "tags"
32
+ PARSE_FAILURE_TAG = "_jsonparsefailure"
33
+ PARSE_FAILURE_LOG_MESSAGE = "JSON parse failure. Falling back to plain-text"
34
+
35
+ public
36
+ def initialize(params)
37
+ super
38
+ BasicSocket.do_not_reverse_lookup = true
39
+ end # def initialize
40
+
41
+ public
42
+ def register
43
+ require 'gelfd'
44
+ end # def register
45
+
46
+ public
47
+ def run(output_queue)
48
+ begin
49
+ # udp server
50
+ udp_listener(output_queue)
51
+ rescue => e
52
+ unless stop?
53
+ @logger.warn("gelf listener died", :exception => e, :backtrace => e.backtrace)
54
+ Stud.stoppable_sleep(RECONNECT_BACKOFF_SLEEP) { stop? }
55
+ retry unless stop?
56
+ end
57
+ end # begin
58
+ end # def run
59
+
60
+ public
61
+ def stop
62
+ @udp.close
63
+ rescue IOError # the plugin is currently shutting down, so its safe to ignore theses errors
64
+ end
65
+
66
+ private
67
+ def udp_listener(output_queue)
68
+ @logger.info("Starting gelf listener", :address => "#{@host}:#{@port}")
69
+
70
+ @udp = UDPSocket.new(Socket::AF_INET)
71
+ @udp.bind(@host, @port)
72
+
73
+ while !stop?
74
+ line, client = @udp.recvfrom(8192)
75
+
76
+ begin
77
+ data = Gelfd::Parser.parse(line)
78
+ rescue => ex
79
+ @logger.warn("Gelfd failed to parse a message skipping", :exception => ex, :backtrace => ex.backtrace)
80
+ next
81
+ end
82
+
83
+ # Gelfd parser outputs null if it received and cached a non-final chunk
84
+ next if data.nil?
85
+
86
+ event = self.class.new_event(data, client[3])
87
+ next if event.nil?
88
+
89
+ output_queue << event
90
+ end
91
+ end # def udp_listener
92
+
93
+ def self.new_event(json_gelf, host)
94
+ event = parse(json_gelf)
95
+ return if event.nil?
96
+
97
+ event.set(SOURCE_HOST_FIELD, host)
98
+
99
+ event
100
+ end
101
+
102
+
103
+ # from_json_parse uses the Event#from_json method to deserialize and directly produce events
104
+ def self.from_json_parse(json)
105
+ # from_json will always return an array of item.
106
+ # in the context of gelf, the payload should be an array of 1
107
+ LogStash::Event.from_json(json).first
108
+ rescue LogStash::Json::ParserError => e
109
+ logger.error(PARSE_FAILURE_LOG_MESSAGE, :error => e, :data => json)
110
+ LogStash::Event.new(MESSAGE_FIELD => json, TAGS_FIELD => [PARSE_FAILURE_TAG, '_fromjsonparser'])
111
+ end # def self.from_json_parse
112
+ end # class LogStash::Inputs::Gelf
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-input-gelfx'
4
+ s.version = '1.0.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "This input will read GELF messages as events over the network, making it a good choice if you already use Graylog2 today."
7
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
8
+ s.authors = ["Elastic"]
9
+ s.email = 'info@elastic.co'
10
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
+
25
+ s.add_runtime_dependency "gelfd", ["0.2.0"] #(Apache 2.0 license)
26
+ s.add_runtime_dependency 'logstash-codec-plain'
27
+ s.add_runtime_dependency "stud", "~> 0.0.22"
28
+
29
+ s.add_development_dependency 'logstash-devutils'
30
+ s.add_development_dependency "gelf", ["1.3.2"] #(MIT license)
31
+ s.add_development_dependency "flores"
32
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/gelf"
4
+ require_relative "../support/helpers"
5
+ require "gelf"
6
+ require "flores/random"
7
+
8
+ describe LogStash::Inputs::Gelf do
9
+ context "when interrupting the plugin" do
10
+ let(:port) { Flores::Random.integer(1024..65535) }
11
+ let(:host) { "127.0.0.1" }
12
+ let(:chunksize) { 1420 }
13
+ let(:producer) { InfiniteGelfProducer.new(host, port, chunksize) }
14
+ let(:config) { {"host" => host, "port" => port} }
15
+
16
+ before { producer.run }
17
+ after { producer.stop }
18
+
19
+
20
+ it_behaves_like "an interruptible input plugin"
21
+ end
22
+
23
+ it "reads chunked gelf messages " do
24
+ port = 12209
25
+ host = "127.0.0.1"
26
+ chunksize = 1420
27
+ gelfclient = GELF::Notifier.new(host, port, chunksize)
28
+
29
+ conf = <<-CONFIG
30
+ input {
31
+ gelfx {
32
+ port => "#{port}"
33
+ host => "#{host}"
34
+ }
35
+ }
36
+ CONFIG
37
+
38
+ large_random = 2000.times.map { 32 + rand(126 - 32) }.join("")
39
+
40
+ messages = [
41
+ "hello",
42
+ "world",
43
+ large_random,
44
+ "we survived gelf!"
45
+ ]
46
+
47
+ events = input(conf) do |pipeline, queue|
48
+ # send a first message until plugin is up and receives it
49
+ while queue.size <= 0
50
+ gelfclient.notify!("short_message" => "prime")
51
+ sleep(0.1)
52
+ end
53
+ gelfclient.notify!("short_message" => "start")
54
+
55
+ e = queue.pop
56
+ while (e.get("message") != "start")
57
+ e = queue.pop
58
+ end
59
+
60
+ messages.each do |m|
61
+ gelfclient.notify!("short_message" => m)
62
+ end
63
+
64
+ messages.map { queue.pop }
65
+ end
66
+
67
+ events.each_with_index do |e, i|
68
+ insist { e.get("message") } == messages[i]
69
+ insist { e.get("host") } == Socket.gethostname
70
+ end
71
+ end
72
+
73
+
74
+ context "when an invalid JSON is fed to the listener" do
75
+ subject { LogStash::Inputs::Gelf.new_event(message, "host") }
76
+ let(:message) { "Invalid JSON message" }
77
+
78
+ context "default :from_json parser output" do
79
+ it { should be_a(LogStash::Event) }
80
+
81
+ it "falls back to plain-text" do
82
+ expect(subject.get("message")).to eq(message)
83
+ end
84
+
85
+ it "tags message with _jsonparsefailure" do
86
+ expect(subject.get("tags")).to include("_jsonparsefailure")
87
+ end
88
+
89
+ it "tags message with _fromjsonparser" do
90
+ expect(subject.get("tags")).to include("_fromjsonparser")
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ class InfiniteGelfProducer
3
+ def initialize(host, port, chunksize)
4
+ @client = GELF::Notifier.new(host, port, chunksize)
5
+ end
6
+
7
+ def run
8
+ @producer = Thread.new do
9
+ while true
10
+ @client.notify!("short_message" => "hello world")
11
+ end
12
+ end
13
+ end
14
+
15
+ def stop
16
+ @producer.kill
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-gelfx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '='
37
+ - !ruby/object:Gem::Version
38
+ version: 0.2.0
39
+ name: gelfd
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.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: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 0.0.22
67
+ name: stud
68
+ prerelease: false
69
+ type: :runtime
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.22
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ name: logstash-devutils
82
+ prerelease: false
83
+ type: :development
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '='
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.2
95
+ name: gelf
96
+ prerelease: false
97
+ type: :development
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.2
103
+ - !ruby/object:Gem::Dependency
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ name: flores
110
+ prerelease: false
111
+ type: :development
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
118
+ email: info@elastic.co
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - CHANGELOG.md
124
+ - CONTRIBUTORS
125
+ - Gemfile
126
+ - LICENSE
127
+ - NOTICE.TXT
128
+ - README.md
129
+ - lib/logstash/inputs/gelf.rb
130
+ - logstash-input-gelfx.gemspec
131
+ - spec/inputs/gelf_spec.rb
132
+ - spec/support/helpers.rb
133
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
134
+ licenses:
135
+ - Apache License (2.0)
136
+ metadata:
137
+ logstash_plugin: 'true'
138
+ logstash_group: input
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.4.8
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: This input will read GELF messages as events over the network, making it a good choice if you already use Graylog2 today.
159
+ test_files:
160
+ - spec/inputs/gelf_spec.rb
161
+ - spec/support/helpers.rb