logstash-output-riemann 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2ea250e17584a63e3fe0913f3163184563f70dc
4
- data.tar.gz: f7f14e55e1945b721075272918a53107755d4c94
3
+ metadata.gz: 9a6691d3d4600fd420f3d6f9559a24d8ff71a429
4
+ data.tar.gz: 7124df74d4c3889c25c0689a8a4700f5141c6b0a
5
5
  SHA512:
6
- metadata.gz: 239a290f27a0191afdf2628e4a57107d316c2d0070e1cc88c3e8fbacbb13c477da253f45f30a945a40157dafcf1ae0b4473802ebbf4bd3316ad9173d12c31f06
7
- data.tar.gz: 90bf0f4d401c035e2f617903eb8137c87168124f61be5f03a8f68a6f5904e1cacb5407c0c15f47a86d56e4b909b20b9d0e0a309f97f5fad84ea4c928d11f8136
6
+ metadata.gz: e1b77bed0fa58c719c8a85f34f6e402eea96abfc96255096a00136aa72e550bad90d5420cffcc3a9ef53338ba2e5a44ca25fc4cdb73ff7653691c6029c7aba3c
7
+ data.tar.gz: b5f42724566690d3a1edcdafab9163c513b23b635a31c9e44ce8c88b5434fc118394d417b498eb361d6c015525ee23094254eeb061eb400c56d7b294028c5088
File without changes
@@ -11,6 +11,7 @@ Contributors:
11
11
  * Marc Fournier (mfournier)
12
12
  * Pier-Hugues Pellerin (ph)
13
13
  * Richard Pijnenburg (electrical)
14
+ * Jacob Hitze (jhitze)
14
15
 
15
16
  Note: If you've sent us patches, bug reports, or otherwise contributed to
16
17
  Logstash, and you aren't on the list above and want to be, please let us know
@@ -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
@@ -13,7 +13,7 @@ Logstash provides infrastructure to automatically generate documentation for thi
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
 
@@ -107,23 +107,30 @@ class LogStash::Outputs::Riemann < LogStash::Outputs::Base
107
107
 
108
108
  public
109
109
  def map_fields(parent, fields)
110
- fields.each {|key, val|
111
- if !key.start_with?("@")
112
- field = parent.nil? ? key : parent + '.' + key
113
- contents = val
114
- if contents.is_a?(Hash)
115
- map_fields(field, contents)
116
- else
117
- @my_event[field.to_sym] = contents
118
- end
110
+ this_level = Hash.new
111
+ fields.each do |key, contents|
112
+ next if key.start_with?("@")
113
+ field = parent.nil? ? key : "#{parent}.#{key}"
114
+ if contents.is_a?(Hash)
115
+ this_level.merge! map_fields(field, contents)
116
+ else
117
+ this_level[field.to_sym] = contents
119
118
  end
120
- }
119
+ end
120
+ return this_level
121
121
  end
122
122
 
123
123
  public
124
124
  def receive(event)
125
125
  return unless output?(event)
126
126
 
127
+ r_event = build_riemann_formatted_event(event)
128
+
129
+ @logger.debug("Riemann event: ", :riemann_event => r_event)
130
+ send_to_riemann(r_event)
131
+ end # def receive
132
+
133
+ def build_riemann_formatted_event(event)
127
134
  # Let's build us an event, shall we?
128
135
  r_event = Hash.new
129
136
  r_event[:host] = event.sprintf(@sender)
@@ -140,18 +147,21 @@ class LogStash::Outputs::Riemann < LogStash::Outputs::Base
140
147
  end
141
148
  end
142
149
  if @map_fields == true
143
- @my_event = Hash.new
144
- map_fields(nil, event)
145
- r_event.merge!(@my_event) {|key, val1, val2| val1}
150
+ r_event.merge! map_fields(nil, event.to_hash)
146
151
  end
147
152
  r_event[:tags] = event["tags"] if event["tags"].is_a?(Array)
148
- @logger.debug("Riemann event: ", :riemann_event => r_event)
153
+
154
+ return r_event
155
+ end
156
+
157
+ def send_to_riemann(riemann_formatted_event)
149
158
  begin
150
159
  proto_client = @client.instance_variable_get("@#{@protocol}")
151
160
  @logger.debug("Riemann client proto: #{proto_client.to_s}")
152
- proto_client << r_event
161
+ proto_client << riemann_formatted_event
153
162
  rescue Exception => e
154
163
  @logger.debug("Unhandled exception", :error => e)
155
164
  end
156
- end # def receive
165
+ end # def send_to_riemann
166
+
157
167
  end # class LogStash::Outputs::Riemann
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-riemann'
4
- s.version = '0.1.4'
4
+ s.version = '0.2.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Riemann is a network event stream processing system."
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"
@@ -25,5 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'riemann-client', ['0.2.1']
26
26
 
27
27
  s.add_development_dependency 'logstash-devutils'
28
+ s.add_development_dependency "logstash-codec-plain"
28
29
  end
29
30
 
@@ -1 +1,114 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/plugin"
3
+ require "logstash/json"
4
+
5
+ describe "outputs/riemann" do
6
+
7
+ context "registration" do
8
+
9
+ it "should register" do
10
+ output = LogStash::Plugin.lookup("output", "riemann").new
11
+ expect {output.register}.not_to raise_error
12
+ end
13
+
14
+ context "protocol" do
15
+ it "should fail if not set to [tcp] or [udp]" do
16
+ expect {
17
+ output = LogStash::Plugin.lookup("output", "riemann").new("protocol" => "fake")
18
+ output.register
19
+ }.to raise_error
20
+ end
21
+
22
+ it "should not error out if set to [tcp]" do
23
+ expect {
24
+ output = LogStash::Plugin.lookup("output", "riemann").new("protocol" => "tcp")
25
+ output.register
26
+ }.not_to raise_error
27
+ end
28
+
29
+ it "should not error out if set to [udp]" do
30
+ expect {
31
+ output = LogStash::Plugin.lookup("output", "riemann").new("protocol" => "udp")
32
+ output.register
33
+ }.not_to raise_error
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ context "receive" do
40
+
41
+ output = LogStash::Plugin.lookup("output", "riemann").new
42
+ data = {"message"=>"hello", "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
43
+ event = LogStash::Event.new data
44
+
45
+ it "should accept the event" do
46
+
47
+ expect{
48
+ output.receive event
49
+ }.not_to raise_error
50
+ end
51
+
52
+ end
53
+
54
+ context "map_fields" do
55
+
56
+ context "with basic data" do
57
+
58
+ it "will return keys that do not start with @ sign." do
59
+ data = {"message"=>"hello", "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
60
+ expected_data = {:message=>"hello", :host=>"vagrant-ubuntu-trusty-64"}
61
+ output = LogStash::Plugin.lookup("output", "riemann").new
62
+ expect(output.map_fields(nil, data)).to eq expected_data
63
+ end
64
+
65
+ it "will return a hash of nested values" do
66
+ data = {"message"=>"hello", "node_info" => {"name" => "node1", "status" => "up"}, "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
67
+ expected_data = {:message =>"hello", :host =>"vagrant-ubuntu-trusty-64", :"node_info.name" => "node1", :"node_info.status" => "up"}
68
+ output = LogStash::Plugin.lookup("output", "riemann").new
69
+ expect(output.map_fields(nil, data)).to eq expected_data
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ context "build_riemann_formatted_event" do
76
+
77
+ context "with map_fields" do
78
+
79
+ it "will return symboled hash with at least :host, :time, and :description" do
80
+ data = {"message"=>"hello", "node_info" => {"name" => "node1", "status" => "up"}, "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
81
+ expected_data = {:time=>1433374494, :message =>"hello", :description =>"hello", :host =>"vagrant-ubuntu-trusty-64", :"node_info.name" => "node1", :"node_info.status" => "up"}
82
+ event = LogStash::Event.new data
83
+ output = LogStash::Plugin.lookup("output", "riemann").new("map_fields" => "true")
84
+ expect(output.build_riemann_formatted_event(event)).to eq expected_data
85
+ end
86
+
87
+ end
88
+
89
+ context "without map_fields" do
90
+
91
+ it "will return symboled hash with at least :host, :time, and :description" do
92
+ data = {"message"=>"hello", "node_info" => {"name" => "node1", "status" => "up"}, "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
93
+ expected_data = {:time=>1433374494, :description =>"hello", :host =>"vagrant-ubuntu-trusty-64"}
94
+ event = LogStash::Event.new data
95
+ output = LogStash::Plugin.lookup("output", "riemann").new
96
+ expect(output.build_riemann_formatted_event(event)).to eq expected_data
97
+ end
98
+
99
+ end
100
+
101
+ context "with tags" do
102
+
103
+ it "will return a symboled tags with multiple tags" do
104
+ data = {"tags"=> ["good_enough", "smart_enough", "doggone_it", "people_like_me"], "message"=>"hello", "node_info" => {"name" => "node1", "status" => "up"}, "@version"=>"1", "@timestamp"=>"2015-06-03T23:34:54.076Z", "host"=>"vagrant-ubuntu-trusty-64"}
105
+ expected_data = {:tags => ["good_enough", "smart_enough", "doggone_it", "people_like_me"], :time=>1433374494, :description =>"hello", :host =>"vagrant-ubuntu-trusty-64"}
106
+ event = LogStash::Event.new data
107
+ output = LogStash::Plugin.lookup("output", "riemann").new
108
+ expect(output.build_riemann_formatted_event(event)).to eq expected_data
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+ end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-riemann
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-08-04 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: 2.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,34 +28,50 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
+ name: riemann-client
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.1
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '='
37
43
  - !ruby/object:Gem::Version
38
44
  version: 0.2.1
39
- name: riemann-client
40
45
  prerelease: false
41
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
42
49
  version_requirements: !ruby/object:Gem::Requirement
43
50
  requirements:
44
- - - '='
51
+ - - '>='
45
52
  - !ruby/object:Gem::Version
46
- version: 0.2.1
47
- - !ruby/object:Gem::Dependency
53
+ version: '0'
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  requirements:
50
56
  - - '>='
51
57
  - !ruby/object:Gem::Version
52
58
  version: '0'
53
- name: logstash-devutils
54
59
  prerelease: false
55
60
  type: :development
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-codec-plain
56
63
  version_requirements: !ruby/object:Gem::Requirement
57
64
  requirements:
58
65
  - - '>='
59
66
  - !ruby/object:Gem::Version
60
67
  version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
61
75
  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
62
76
  email: info@elastic.co
63
77
  executables: []
@@ -65,9 +79,11 @@ extensions: []
65
79
  extra_rdoc_files: []
66
80
  files:
67
81
  - .gitignore
82
+ - CHANGELOG.md
68
83
  - CONTRIBUTORS
69
84
  - Gemfile
70
85
  - LICENSE
86
+ - NOTICE.TXT
71
87
  - README.md
72
88
  - Rakefile
73
89
  - lib/logstash/outputs/riemann.rb