logstash-input-gelf 2.0.2 → 2.0.3

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: c300317ea03aabab7bd1c7f99882e91a0b6c245a
4
- data.tar.gz: b4c6ceb2eec3fe01f5e13a38067a384db0b5acc7
3
+ metadata.gz: 943a77f8602e7e8cfa73b87113150d15fdb5ba7b
4
+ data.tar.gz: 1698c9d2177fa3b5f1fdd2df9c2a06e0ca871633
5
5
  SHA512:
6
- metadata.gz: 7580a06ea44838c481241d069ce18d8e2e0a75b0b6dd592720adf069b3e5b0f4f75986ea3c5c02e6928c847b105526f526f6162756c50688ee1b7e7a0fd699e5
7
- data.tar.gz: ec105386f002250bf4cbd58ef8d9addb3b923fc51d89c9df1d1a4468bd90ce71648829b39d5dcf9a8f4104758b6d3ebb2f2837646d3f01541e7ff3f664c5e5fd
6
+ metadata.gz: ec422f290472e01dd2a5e2d1482f00d82d0d51d000686d6b1fb5d5ed44e47f3927484b1687e2477c6625eaffc00aecad5559da433eeb5fc0a36b8baa53e30a74
7
+ data.tar.gz: d36417132925a905b0b91012a92c65428a2d3443bb1252300982361585d9d35f73883b2939bfc3fc67a177b542faa3c27e347117e4d36c29c6ca5f0fa8b8fb2e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ ## 2.0.3
2
+ - Fix Timestamp coercion to preserve upto microsecond precision, https://github.com/logstash-plugins/logstash-input-gelf/pull/35
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%20Inputs/job/logstash-plugin-input-gelf-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Inputs/job/logstash-plugin-input-gelf-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.
@@ -11,7 +11,15 @@ require "socket"
11
11
  # making it a good choice if you already use Graylog2 today.
12
12
  #
13
13
  # The main use case for this input is to leverage existing GELF
14
- # logging libraries such as the GELF log4j appender.
14
+ # logging libraries such as the GELF log4j appender. A library used
15
+ # by this plugin has a bug which prevents it parsing uncompressed data.
16
+ # If you use the log4j appender you need to configure it like this to force
17
+ # gzip even for small messages:
18
+ #
19
+ # <Socket name="logstash" protocol="udp" host="logstash.example.com" port="5001">
20
+ # <GelfLayout compressionType="GZIP" compressionThreshold="1" />
21
+ # </Socket>
22
+ #
15
23
  #
16
24
  class LogStash::Inputs::Gelf < LogStash::Inputs::Base
17
25
  config_name "gelf"
@@ -44,6 +52,8 @@ class LogStash::Inputs::Gelf < LogStash::Inputs::Base
44
52
  config :strip_leading_underscore, :validate => :boolean, :default => true
45
53
 
46
54
  RECONNECT_BACKOFF_SLEEP = 5
55
+ TIMESTAMP_GELF_FIELD = "timestamp".freeze
56
+ SOURCE_HOST_FIELD = "source_host".freeze
47
57
 
48
58
  public
49
59
  def initialize(params)
@@ -96,13 +106,7 @@ class LogStash::Inputs::Gelf < LogStash::Inputs::Base
96
106
  # Gelfd parser outputs null if it received and cached a non-final chunk
97
107
  next if data.nil?
98
108
 
99
- event = LogStash::Event.new(LogStash::Json.load(data))
100
-
101
- event["source_host"] = client[3]
102
- if event["timestamp"].is_a?(Numeric)
103
- event.timestamp = LogStash::Timestamp.at(event["timestamp"])
104
- event.remove("timestamp")
105
- end
109
+ event = self.class.new_event(data, client[3])
106
110
 
107
111
  remap_gelf(event) if @remap
108
112
  strip_leading_underscore(event) if @strip_leading_underscore
@@ -112,15 +116,41 @@ class LogStash::Inputs::Gelf < LogStash::Inputs::Base
112
116
  end
113
117
  end # def udp_listener
114
118
 
119
+ # generate a new LogStash::Event from json input and assign host to source_host event field.
120
+ # @param json_gelf [String] GELF json data
121
+ # @param host [String] source host of GELF data
122
+ # @return [LogStash::Event] new event with parsed json gelf, assigned source host and coerced timestamp
123
+ def self.new_event(json_gelf, host)
124
+ event = LogStash::Event.new(LogStash::Json.load(json_gelf))
125
+
126
+ event[SOURCE_HOST_FIELD] = host
127
+
128
+ if (gelf_timestamp = event[TIMESTAMP_GELF_FIELD]).is_a?(Numeric)
129
+ event.timestamp = self.coerce_timestamp(gelf_timestamp)
130
+ event.remove(TIMESTAMP_GELF_FIELD)
131
+ end
132
+
133
+ event
134
+ end
135
+
136
+ # transform a given timestamp value into a proper LogStash::Timestamp, preserving microsecond precision
137
+ # and work around a JRuby issue with Time.at loosing fractional part with BigDecimal.
138
+ # @param timestamp [Numeric] a Numeric (integer, float or bigdecimal) timestampo representation
139
+ # @return [LogStash::Timestamp] the proper LogStash::Timestamp representation
140
+ def self.coerce_timestamp(timestamp)
141
+ # bug in JRuby prevents correcly parsing a BigDecimal fractional part, see https://github.com/elastic/logstash/issues/4565
142
+ timestamp.is_a?(BigDecimal) ? LogStash::Timestamp.at(timestamp.to_i, timestamp.frac * 1000000) : LogStash::Timestamp.at(timestamp)
143
+ end
144
+
115
145
  private
116
146
  def remap_gelf(event)
117
- if event["full_message"]
147
+ if event["full_message"] && !event["full_message"].empty?
118
148
  event["message"] = event["full_message"].dup
119
149
  event.remove("full_message")
120
150
  if event["short_message"] == event["message"]
121
151
  event.remove("short_message")
122
152
  end
123
- elsif event["short_message"]
153
+ elsif event["short_message"] && !event["short_message"].empty?
124
154
  event["message"] = event["short_message"].dup
125
155
  event.remove("short_message")
126
156
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-gelf'
4
- s.version = '2.0.2'
4
+ s.version = '2.0.3'
5
5
  s.licenses = ['Apache License (2.0)']
6
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
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"
@@ -66,6 +66,84 @@ describe LogStash::Inputs::Gelf do
66
66
 
67
67
  events.each_with_index do |e, i|
68
68
  insist { e["message"] } == messages[i]
69
+ insist { e["host"] } == Socket.gethostname
70
+ end
71
+ end
72
+
73
+ context "timestamp coercion" do
74
+ # these test private methods, this is advisable for now until we roll out this coercion in the Timestamp class
75
+ # and remove this
76
+
77
+ context "integer numeric values" do
78
+ it "should coerce" do
79
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800).to_iso8601).to eq("2000-01-01T05:00:00.000Z")
80
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800).usec).to eq(0)
81
+ end
82
+ end
83
+
84
+ context "float numeric values" do
85
+ # using explicit and certainly useless to_f here just to leave no doubt about the numeric type involved
86
+
87
+ it "should coerce and preserve millisec precision in iso8601" do
88
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.1.to_f).to_iso8601).to eq("2000-01-01T05:00:00.100Z")
89
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.12.to_f).to_iso8601).to eq("2000-01-01T05:00:00.120Z")
90
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.123.to_f).to_iso8601).to eq("2000-01-01T05:00:00.123Z")
91
+ end
92
+
93
+ it "should coerce and preserve usec precision" do
94
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.1.to_f).usec).to eq(100000)
95
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.12.to_f).usec).to eq(120000)
96
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.123.to_f).usec).to eq(123000)
97
+
98
+ # since Java Timestamp in 2.3+ relies on JodaTime which supports only millisec precision
99
+ # the usec method will only be precise up to millisec.
100
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.1234.to_f).usec).to be_within(1000).of(123400)
101
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.12345.to_f).usec).to be_within(1000).of(123450)
102
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(946702800.123456.to_f).usec).to be_within(1000).of(123456)
103
+ end
104
+ end
105
+
106
+ context "BigDecimal numeric values" do
107
+ it "should coerce and preserve millisec precision in iso8601" do
108
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.1")).to_iso8601).to eq("2000-01-01T05:00:00.100Z")
109
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.12")).to_iso8601).to eq("2000-01-01T05:00:00.120Z")
110
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.123")).to_iso8601).to eq("2000-01-01T05:00:00.123Z")
111
+ end
112
+
113
+ it "should coerce and preserve usec precision" do
114
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.1")).usec).to eq(100000)
115
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.12")).usec).to eq(120000)
116
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.123")).usec).to eq(123000)
117
+
118
+ # since Java Timestamp in 2.3+ relies on JodaTime which supports only millisec precision
119
+ # the usec method will only be precise up to millisec.
120
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.1234")).usec).to be_within(1000).of(123400)
121
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.12345")).usec).to be_within(1000).of(123450)
122
+ expect(LogStash::Inputs::Gelf.coerce_timestamp(BigDecimal.new("946702800.123456")).usec).to be_within(1000).of(123456)
123
+ end
124
+ end
125
+ end
126
+
127
+ context "json timestamp coercion" do
128
+ # these test private methods, this is advisable for now until we roll out this coercion in the Timestamp class
129
+ # and remove this
130
+
131
+ it "should coerce integer numeric json timestamp input" do
132
+ event = LogStash::Inputs::Gelf.new_event("{\"timestamp\":946702800}", "dummy")
133
+ expect(event.timestamp.to_iso8601).to eq("2000-01-01T05:00:00.000Z")
134
+ end
135
+
136
+ it "should coerce float numeric value and preserve milliseconds precision in iso8601" do
137
+ event = LogStash::Inputs::Gelf.new_event("{\"timestamp\":946702800.123}", "dummy")
138
+ expect(event.timestamp.to_iso8601).to eq("2000-01-01T05:00:00.123Z")
139
+ end
140
+
141
+ it "should coerce float numeric value and preserve usec precision" do
142
+ # since Java Timestamp in 2.3+ relies on JodaTime which supports only millisec precision
143
+ # the usec method will only be precise up to millisec.
144
+
145
+ event = LogStash::Inputs::Gelf.new_event("{\"timestamp\":946702800.123456}", "dummy")
146
+ expect(event.timestamp.usec).to be_within(1000).of(123456)
69
147
  end
70
148
  end
71
149
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-gelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
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: 2016-03-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,90 +28,92 @@ 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: gelfd
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.0
34
40
  requirement: !ruby/object:Gem::Requirement
35
41
  requirements:
36
42
  - - '='
37
43
  - !ruby/object:Gem::Version
38
44
  version: 0.2.0
39
- name: gelfd
40
45
  prerelease: false
41
46
  type: :runtime
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
- version: 0.2.0
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-codec-plain
54
59
  prerelease: false
55
60
  type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: stud
56
63
  version_requirements: !ruby/object:Gem::Requirement
57
64
  requirements:
58
- - - '>='
65
+ - - ~>
59
66
  - !ruby/object:Gem::Version
60
- version: '0'
61
- - !ruby/object:Gem::Dependency
67
+ version: 0.0.22
62
68
  requirement: !ruby/object:Gem::Requirement
63
69
  requirements:
64
70
  - - ~>
65
71
  - !ruby/object:Gem::Version
66
72
  version: 0.0.22
67
- name: stud
68
73
  prerelease: false
69
74
  type: :runtime
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-devutils
70
77
  version_requirements: !ruby/object:Gem::Requirement
71
78
  requirements:
72
- - - ~>
79
+ - - '>='
73
80
  - !ruby/object:Gem::Version
74
- version: 0.0.22
75
- - !ruby/object:Gem::Dependency
81
+ version: '0'
76
82
  requirement: !ruby/object:Gem::Requirement
77
83
  requirements:
78
84
  - - '>='
79
85
  - !ruby/object:Gem::Version
80
86
  version: '0'
81
- name: logstash-devutils
82
87
  prerelease: false
83
88
  type: :development
89
+ - !ruby/object:Gem::Dependency
90
+ name: gelf
84
91
  version_requirements: !ruby/object:Gem::Requirement
85
92
  requirements:
86
- - - '>='
93
+ - - '='
87
94
  - !ruby/object:Gem::Version
88
- version: '0'
89
- - !ruby/object:Gem::Dependency
95
+ version: 1.3.2
90
96
  requirement: !ruby/object:Gem::Requirement
91
97
  requirements:
92
98
  - - '='
93
99
  - !ruby/object:Gem::Version
94
100
  version: 1.3.2
95
- name: gelf
96
101
  prerelease: false
97
102
  type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ name: flores
98
105
  version_requirements: !ruby/object:Gem::Requirement
99
106
  requirements:
100
- - - '='
107
+ - - '>='
101
108
  - !ruby/object:Gem::Version
102
- version: 1.3.2
103
- - !ruby/object:Gem::Dependency
109
+ version: '0'
104
110
  requirement: !ruby/object:Gem::Requirement
105
111
  requirements:
106
112
  - - '>='
107
113
  - !ruby/object:Gem::Version
108
114
  version: '0'
109
- name: flores
110
115
  prerelease: false
111
116
  type: :development
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - '>='
115
- - !ruby/object:Gem::Version
116
- version: '0'
117
117
  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
118
118
  email: info@elastic.co
119
119
  executables: []