gelf 3.0.0 → 3.1.0.pre.rc.1

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
- SHA1:
3
- metadata.gz: 7e1c02912c99651ae9b78b3d80a254b39e44b880
4
- data.tar.gz: 0723b767126b56dbe6d86bcb2ae77da7024eb128
2
+ SHA256:
3
+ metadata.gz: d41d82b5c88118f812edb4ed735cc846cc573a9ddd07ee30e21f618a8b8cff31
4
+ data.tar.gz: 9449c87daecd2aea39c212b5648633a5126575561bc913704356ba8fba149a3f
5
5
  SHA512:
6
- metadata.gz: fa809d0a268591b148822d58bf1f32d703b18ba8c1149e0c70d160cd30e49b834ddb2ef4d9bc206bd0650a6432e9021823d299bb760bfaa126dfd34d6960dc42
7
- data.tar.gz: 99f27da7b54e6a0e19713ae4c926a2005a7c94236c0b4d28a322cf78db81361e3cb4504a93c138cce9bcbc0025e71956adc86b3eb5b1e341f028c79f07703509
6
+ metadata.gz: 269377637ed1c58992e2e1b18215c89743fed95302b5aee90195b58dcf786a8baf5dffce07db95887d4de8f605ab79021fcbe7a72e5c1099da6c0a9c8c9eaa17
7
+ data.tar.gz: 6741adffa781adb9baa8a854389657ad3a55b1fcebf6a49490dcc718f666445156385710133cf6dc4104ece6d43645179dfb3cade28d20e78719181a34e138e5
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.1.0
5
5
  - 2.2.0
6
6
  - 2.3.0
7
+ - 2.4.0
7
8
  - jruby-19mode
8
9
  deploy:
9
10
  provider: rubygems
@@ -13,4 +14,4 @@ deploy:
13
14
  gemspec: gelf.gemspec
14
15
  on:
15
16
  tags: true
16
- repo: Graylog2/gelf-rb
17
+ repo: graylog-labs/gelf-rb
@@ -26,7 +26,8 @@ GEM
26
26
  rake
27
27
  rdoc
28
28
  semver
29
- json (1.8.3)
29
+ json (1.8.6)
30
+ json (1.8.6-java)
30
31
  jwt (1.5.4)
31
32
  metaclass (0.0.4)
32
33
  mini_portile2 (2.1.0)
@@ -38,6 +39,7 @@ GEM
38
39
  nokogiri (1.6.8)
39
40
  mini_portile2 (~> 2.1.0)
40
41
  pkg-config (~> 1.1.7)
42
+ nokogiri (1.6.8-java)
41
43
  oauth2 (1.2.0)
42
44
  faraday (>= 0.8, < 0.10)
43
45
  jwt (~> 1.0)
@@ -55,8 +57,10 @@ GEM
55
57
  test-unit (3.2.1)
56
58
  power_assert
57
59
  thread_safe (0.3.5)
60
+ thread_safe (0.3.5-java)
58
61
 
59
62
  PLATFORMS
63
+ java
60
64
  ruby
61
65
 
62
66
  DEPENDENCIES
@@ -67,4 +71,4 @@ DEPENDENCIES
67
71
  test-unit (~> 3.2.0)
68
72
 
69
73
  BUNDLED WITH
70
- 1.12.5
74
+ 1.14.6
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  ## GELF Ruby library
2
2
 
3
- This is the new GELF gem written by Alexey Palazhchenko. It is based on the old gem by Lennart Koopmann and allows you to send GELF messages to Graylog2 server instances. See [http://www.graylog2.org/about/gelf](http://www.graylog2.org/about/gelf) for more information about GELF and [http://rdoc.info/github/Graylog2/gelf-rb/master/frames](http://rdoc.info/github/Graylog2/gelf-rb/master/frames) for API documentation.
3
+ This is the new GELF gem written by Alexey Palazhchenko. It is based on the old gem by Lennart Koopmann and allows you to send GELF messages to Graylog or Logstash instances. See the [GELF specification](http://docs.graylog.org/en/stable/pages/gelf.html) for more information about GELF and [RDoc](http://rdoc.info/github/graylog-labs/gelf-rb/master/frames) for API documentation.
4
4
 
5
- Tested with Ruby 1.9, 2.0, 2.1, 2.2 and 2.3.
5
+ Tested with Ruby 1.9, 2.0, 2.1, 2.2, 2.3 and 2.4.
6
6
 
7
- ![](https://travis-ci.org/Graylog2/gelf-rb.png?branch=master) [![Code Climate](https://codeclimate.com/github/Graylog2/gelf-rb/badges/gpa.svg)](https://codeclimate.com/github/Graylog2/gelf-rb)
7
+ [![Build Status](https://travis-ci.org/graylog-labs/gelf-rb.svg?branch=master)](https://travis-ci.org/graylog-labs/gelf-rb)
8
+ [![Code Climate](https://codeclimate.com/github/graylog-labs/gelf-rb/badges/gpa.svg)](https://codeclimate.com/github/graylog-labs/gelf-rb)
8
9
 
9
10
  ## Usage
10
11
  ### Gelf::Notifier
11
12
 
12
- This allows you to sent arbitary messages via UDP to your Graylog2 server.
13
+ This allows you to sent arbitary messages via UDP to Graylog.
13
14
 
14
15
  n = GELF::Notifier.new("localhost", 12201)
15
16
 
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: gelf 3.0.0 ruby lib
5
+ # stub: gelf 3.1.0-rc.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "gelf"
9
- s.version = "3.0.0"
9
+ s.version = "3.1.0-rc.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  "test/test_ruby_sender.rb",
45
45
  "test/test_severity.rb"
46
46
  ]
47
- s.homepage = "http://github.com/Graylog2/gelf-rb"
47
+ s.homepage = "https://github.com/graylog-labs/gelf-rb"
48
48
  s.licenses = ["MIT"]
49
49
  s.rubygems_version = "2.5.1"
50
50
  s.summary = "Library to send GELF messages to Graylog logging server."
@@ -5,24 +5,20 @@ module GELF
5
5
  attr_accessor :formatter
6
6
 
7
7
  # Use it like Logger#add... or better not to use at all.
8
- def add(level, message = nil, progname = nil)
8
+ def add(level, message = nil, progname = nil, &block)
9
9
  progname ||= default_options['facility']
10
+ message ||= block.call unless block.nil?
10
11
 
11
12
  if message.nil?
12
- if block_given?
13
- message = yield
14
- else
15
- message = progname
16
- progname = default_options['facility']
17
- end
13
+ message = progname
14
+ progname = default_options['facility']
18
15
  end
19
16
 
20
17
  message_hash = { 'facility' => progname }
21
18
 
22
19
  if message.is_a?(Hash)
23
- # Stringify keys.
24
20
  message.each do |key, value|
25
- message_hash[key.to_s] = value
21
+ message_hash[key.to_s] = value.to_s
26
22
  end
27
23
  else
28
24
  message_hash['short_message'] = message.to_s
@@ -32,7 +28,9 @@ module GELF
32
28
  message_hash.merge!(self.class.extract_hash_from_exception(message))
33
29
  end
34
30
 
35
- notify_with_level(level, message_hash)
31
+ if message_hash.key?('short_message') && !message_hash['short_message'].empty?
32
+ notify_with_level(level, message_hash)
33
+ end
36
34
  end
37
35
 
38
36
  # Redefines methods in +Notifier+.
@@ -2,6 +2,12 @@ require 'gelf/transport/udp'
2
2
  require 'gelf/transport/tcp'
3
3
  require 'gelf/transport/tcp_tls'
4
4
 
5
+ # replace JSON and #to_json with Yajl if available
6
+ begin
7
+ require 'yajl/json_gem'
8
+ rescue LoadError
9
+ end
10
+
5
11
  module GELF
6
12
  # Graylog2 notifier.
7
13
  class Notifier
@@ -62,7 +68,7 @@ module GELF
62
68
  end
63
69
 
64
70
  def level=(new_level)
65
- @level = if new_level.is_a?(Fixnum)
71
+ @level = if new_level.is_a?(Integer)
66
72
  new_level
67
73
  else
68
74
  GELF.const_get(new_level.to_s.upcase)
@@ -152,14 +158,14 @@ module GELF
152
158
 
153
159
  def notify_with_level!(message_level, *args)
154
160
  return unless @enabled
155
- extract_hash(*args)
156
- @hash['level'] = message_level unless message_level.nil?
157
- if @hash['level'] >= level
161
+ hash = extract_hash(*args)
162
+ hash['level'] = message_level unless message_level.nil?
163
+ if hash['level'] >= level
158
164
  if default_options['protocol'] == GELF::Protocol::TCP
159
- validate_hash
160
- @sender.send(@hash.to_json + "\0")
165
+ validate_hash(hash)
166
+ @sender.send(hash.to_json + "\0")
161
167
  else
162
- @sender.send_datagrams(datagrams_from_hash)
168
+ @sender.send_datagrams(datagrams_from_hash(hash))
163
169
  end
164
170
  end
165
171
  end
@@ -175,12 +181,12 @@ module GELF
175
181
  { 'short_message' => object.to_s }
176
182
  end
177
183
 
178
- @hash = default_options.merge(self.class.stringify_keys(args.merge(primary_data)))
179
- convert_hoptoad_keys_to_graylog2
180
- set_file_and_line if @collect_file_and_line
181
- set_timestamp
182
- check_presence_of_mandatory_attributes
183
- @hash
184
+ hash = default_options.merge(self.class.stringify_keys(args.merge(primary_data)))
185
+ convert_hoptoad_keys_to_graylog2(hash)
186
+ set_file_and_line(hash) if @collect_file_and_line
187
+ set_timestamp(hash)
188
+ check_presence_of_mandatory_attributes(hash)
189
+ hash
184
190
  end
185
191
 
186
192
  def self.extract_hash_from_exception(exception)
@@ -192,10 +198,10 @@ module GELF
192
198
  end
193
199
 
194
200
  # Converts Hoptoad-specific keys in +@hash+ to Graylog2-specific.
195
- def convert_hoptoad_keys_to_graylog2
196
- if @hash['short_message'].to_s.empty?
197
- if @hash.has_key?('error_class') && @hash.has_key?('error_message')
198
- @hash['short_message'] = @hash.delete('error_class') + ': ' + @hash.delete('error_message')
201
+ def convert_hoptoad_keys_to_graylog2(hash)
202
+ if hash['short_message'].to_s.empty?
203
+ if hash.has_key?('error_class') && hash.has_key?('error_message')
204
+ hash['short_message'] = hash.delete('error_class') + ': ' + hash.delete('error_message')
199
205
  end
200
206
  end
201
207
  end
@@ -203,28 +209,28 @@ module GELF
203
209
  CALLER_REGEXP = /^(.*):(\d+).*/
204
210
  LIB_GELF_PATTERN = File.join('lib', 'gelf')
205
211
 
206
- def set_file_and_line
212
+ def set_file_and_line(hash)
207
213
  stack = caller
208
214
  frame = stack.find { |f| !f.include?(LIB_GELF_PATTERN) }
209
215
  match = CALLER_REGEXP.match(frame)
210
- @hash['file'] = match[1]
211
- @hash['line'] = match[2].to_i
216
+ hash['file'] = match[1]
217
+ hash['line'] = match[2].to_i
212
218
  end
213
219
 
214
- def set_timestamp
215
- @hash['timestamp'] = Time.now.utc.to_f if @hash['timestamp'].nil?
220
+ def set_timestamp(hash)
221
+ hash['timestamp'] = Time.now.utc.to_f if hash['timestamp'].nil?
216
222
  end
217
223
 
218
- def check_presence_of_mandatory_attributes
224
+ def check_presence_of_mandatory_attributes(hash)
219
225
  %w(version short_message host).each do |attribute|
220
- if @hash[attribute].to_s.empty?
226
+ if hash[attribute].to_s.empty?
221
227
  raise ArgumentError.new("#{attribute} is missing. Options version, short_message and host must be set.")
222
228
  end
223
229
  end
224
230
  end
225
231
 
226
- def datagrams_from_hash
227
- data = serialize_hash
232
+ def datagrams_from_hash(hash)
233
+ data = serialize_hash(hash)
228
234
  datagrams = []
229
235
 
230
236
  # Maximum total size is 8192 byte for UDP datagram. Split to chunks if bigger. (GELF v1.0 supports chunking)
@@ -246,25 +252,29 @@ module GELF
246
252
  datagrams
247
253
  end
248
254
 
249
- def validate_hash
250
- raise ArgumentError.new("Hash is empty.") if @hash.nil? || @hash.empty?
251
- @hash['level'] = @level_mapping[@hash['level']]
255
+ def validate_hash(hash)
256
+ raise ArgumentError.new("Hash is empty.") if hash.nil? || hash.empty?
257
+ hash['level'] = @level_mapping[hash['level']]
252
258
  end
253
259
 
254
- def serialize_hash
255
- validate_hash
260
+ def serialize_hash(hash)
261
+ validate_hash(hash)
256
262
 
257
- Zlib::Deflate.deflate(@hash.to_json).bytes
263
+ Zlib::Deflate.deflate(hash.to_json).bytes
258
264
  end
259
265
 
260
- def self.stringify_keys(hash)
261
- hash.keys.each do |key|
262
- value, key_s = hash.delete(key), key.to_s
263
- raise ArgumentError.new("Both #{key.inspect} and #{key_s} are present.") if hash.key?(key_s)
264
- value = stringify_keys(value) if value.is_a?(Hash)
265
- hash[key_s] = value
266
+ def self.stringify_keys(data)
267
+ return data unless data.is_a? Hash
268
+
269
+ data.each_with_object({}) do |(key, value), obj|
270
+ key_s = key.to_s
271
+
272
+ if (key != key_s) && data.key?(key_s)
273
+ raise ArgumentError, "Both #{key.inspect} and #{key_s} are present."
274
+ end
275
+
276
+ obj[key_s] = value
266
277
  end
267
- hash
268
278
  end
269
279
  end
270
280
  end
@@ -14,24 +14,37 @@ module GELF
14
14
  ERROR = 3
15
15
  FATAL = 4
16
16
  UNKNOWN = 5
17
+ # Additional native syslog severities. These will work in direct mapping mode
18
+ # only, for compatibility with syslog sources unrelated to Logger.
19
+ EMERGENCY = 10
20
+ ALERT = 11
21
+ CRITICAL = 12
22
+ WARNING = 14
23
+ NOTICE = 15
24
+ INFORMATIONAL = 16
17
25
  end
18
26
 
19
27
  include Levels
20
28
 
21
29
  # Maps Ruby Logger levels to syslog levels as SyslogLogger and syslogger gems. This one is default.
22
30
  LOGGER_MAPPING = {DEBUG => 7, # Debug
23
- INFO => 6, # Info
31
+ INFO => 6, # Informational
24
32
  WARN => 5, # Notice
25
33
  ERROR => 4, # Warning
26
34
  FATAL => 3, # Error
27
35
  UNKNOWN => 1} # Alert – shouldn't be used
28
36
 
29
- # Maps Ruby Logger levels to syslog levels as is.
30
- DIRECT_MAPPING = {DEBUG => 7, # Debug
31
- INFO => 6, # Info
32
- # skip 5 Notice
33
- WARN => 4, # Warning
34
- ERROR => 3, # Error
35
- FATAL => 2, # Critical
36
- UNKNOWN => 1} # Alert – shouldn't be used
37
+ # Maps Syslog or Ruby Logger levels directly to standard syslog numerical severities.
38
+ DIRECT_MAPPING = {DEBUG => 7, # Debug
39
+ INFORMATIONAL => 6, # Informational (syslog source)
40
+ INFO => 6, # Informational (Logger source)
41
+ NOTICE => 5, # Notice
42
+ WARNING => 4, # Warning (syslog source)
43
+ WARN => 4, # Warning (Logger source)
44
+ ERROR => 3, # Error
45
+ CRITICAL => 2, # Critical (syslog source)
46
+ FATAL => 2, # Critical (Logger source)
47
+ ALERT => 1, # Alert (syslog source)
48
+ UNKNOWN => 1, # Alert - shouldn't be used (Logger source)
49
+ EMERGENCY => 0} # Emergency (syslog source)
37
50
  end
@@ -53,11 +53,27 @@ module GELF
53
53
  end
54
54
 
55
55
  def write_socket(socket, message)
56
- socket.write(message) > 0
56
+ unsafe_write_socket(socket, message)
57
57
  rescue IOError, SystemCallError
58
58
  socket.close unless socket.closed?
59
59
  false
60
60
  end
61
+
62
+ def unsafe_write_socket(socket, message)
63
+ r,w = IO.select([socket], [socket])
64
+ # Read everything first
65
+ while r.any? do
66
+ # don't expect any reads, but a readable socket might
67
+ # mean the remote end closed, so read it and throw it away.
68
+ # we'll get an EOFError if it happens.
69
+ socket.sysread(16384)
70
+ r = IO.select([socket])
71
+ end
72
+
73
+ # Now send the payload
74
+ return false unless w.any?
75
+ return socket.syswrite(message) > 0
76
+ end
61
77
  end
62
78
  end
63
79
  end
@@ -6,12 +6,20 @@ module GELF
6
6
  class TCPTLS < TCP
7
7
  # Supported tls_options:
8
8
  # 'no_default_ca' [Boolean] prevents OpenSSL from using the systems CA store.
9
- # 'tls_version' [Symbol] any of :TLSv1, :TLSv1_1, :TLSv1_2 (default)
9
+ # 'version' [Symbol] any of :TLSv1, :TLSv1_1, :TLSv1_2 (default)
10
+ # 'ca' [String] the path to a custom CA store
10
11
  # 'cert' [String, IO] the client certificate file
11
12
  # 'key' [String, IO] the key for the client certificate
12
13
  # 'all_ciphers' [Boolean] allows any ciphers to be used, may be insecure
14
+ # 'rescue_ssl_errors' [Boolean] similar to rescue_network_errors in notifier.rb, allows SSL exceptions to be raised
15
+ # 'no_verify' [Boolean] disable peer verification
16
+
17
+ attr_accessor :rescue_ssl_errors
18
+
13
19
  def initialize(addresses, tls_options={})
14
20
  @tls_options = tls_options
21
+ @rescue_ssl_errors = @tls_options['rescue_ssl_errors']
22
+ @rescue_ssl_errors if @rescue_ssl_errors.nil?
15
23
  super(addresses)
16
24
  end
17
25
 
@@ -21,6 +29,7 @@ module GELF
21
29
  super(socket, message)
22
30
  rescue OpenSSL::SSL::SSLError
23
31
  socket.close unless socket.closed?
32
+ raise unless rescue_ssl_errors
24
33
  false
25
34
  end
26
35
 
@@ -29,6 +38,7 @@ module GELF
29
38
  start_tls(plain_socket)
30
39
  rescue OpenSSL::SSL::SSLError
31
40
  plain_socket.close unless plain_socket.closed?
41
+ raise unless rescue_ssl_errors
32
42
  nil
33
43
  end
34
44
 
@@ -74,16 +84,11 @@ module GELF
74
84
  end
75
85
  end
76
86
 
77
- # These are A-level ciphers as reported from Graylog 2.0.1
78
- # which were also available on Ruby using OpenSSL 1.0.2h
79
- # A lot of AES-128-CBC based ciphers were not available
80
- SECURE_CIPHERS = %w(
81
- AES128-GCM-SHA256
82
- ECDHE-RSA-AES128-GCM-SHA256
83
- DHE-RSA-AES128-GCM-SHA256
84
- ).freeze
87
+ # Ciphers have to come from the CipherString class, specifically the _TXT_ constants here - https://github.com/jruby/jruby-openssl/blob/master/src/main/java/org/jruby/ext/openssl/CipherStrings.java#L47-L178
85
88
  def restrict_ciphers(ctx)
86
- ctx.ciphers = SECURE_CIPHERS
89
+ # This CipherString is will allow a variety of 'currently' cryptographically secure ciphers,
90
+ # while also retaining a broad level of compatibility
91
+ ctx.ciphers = "TLSv1_2:TLSv1_1:TLSv1:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:!ADH:!IDEA:!3DES"
87
92
  end
88
93
 
89
94
  def verify_mode
@@ -103,8 +108,20 @@ module GELF
103
108
 
104
109
  def ssl_cert_store
105
110
  OpenSSL::X509::Store.new.tap do |store|
106
- # TODO: allow passing in expected server certificate and disabling system CAs
107
- store.set_default_paths
111
+ unless @tls_options['no_default_ca']
112
+ store.set_default_paths
113
+ end
114
+
115
+ if @tls_options.key?('ca')
116
+ ca = @tls_options['ca']
117
+ if File.directory?(ca)
118
+ store.add_path(@tls_options['ca'])
119
+ elsif File.file?(ca)
120
+ store.add_file(ca)
121
+ else
122
+ $stderr.puts "No directory or file: #{ca}"
123
+ end
124
+ end
108
125
  end
109
126
  end
110
127
  end
@@ -14,6 +14,16 @@ class TestLogger < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  context "#add" do
17
+ # logger.add(Logger::INFO, nil)
18
+ should 'implement add method with level, message and facility from defaults' do
19
+ @logger.expects(:notify_with_level!).with do |level, hash|
20
+ level == GELF::INFO &&
21
+ hash['short_message'] == 'gelf-rb' &&
22
+ hash['facility'] == 'gelf-rb'
23
+ end
24
+ @logger.add(GELF::INFO, nil)
25
+ end
26
+
17
27
  # logger.add(Logger::INFO, 'Message')
18
28
  should "implement add method with level and message from parameters, facility from defaults" do
19
29
  @logger.expects(:notify_with_level!).with do |level, hash|
@@ -119,9 +129,6 @@ class TestLogger < Test::Unit::TestCase
119
129
  @logger.add(GELF::INFO, nil, 'Facility') { RuntimeError.new('Boom!') }
120
130
  end
121
131
 
122
-
123
- #####################
124
-
125
132
  # logger.add(Logger::INFO, { :short_message => "Some message" })
126
133
  should "implement add method with level and message from hash, facility from defaults" do
127
134
  @logger.expects(:notify_with_level!).with do |level, hash|
@@ -155,6 +162,26 @@ class TestLogger < Test::Unit::TestCase
155
162
  end
156
163
  @logger.add(GELF::INFO, { :short_message => "Some message", :_foo => "bar", "_zomg" => "wat"}, "somefac")
157
164
  end
165
+
166
+ should 'implement add method with level and ignore zero-length message strings' do
167
+ @logger.expects(:notify_with_level!).never
168
+ @logger.add(GELF::INFO, '')
169
+ end
170
+
171
+ should 'implement add method with level and ignore hash without short_message key' do
172
+ @logger.expects(:notify_with_level!).never
173
+ @logger.add(GELF::INFO, { :message => 'Some message' })
174
+ end
175
+
176
+ should 'implement add method with level and ignore hash with zero-length short_message entry' do
177
+ @logger.expects(:notify_with_level!).never
178
+ @logger.add(GELF::INFO, { :short_message => '' })
179
+ end
180
+
181
+ should 'implement add method with level and ignore hash with nil short_message entry' do
182
+ @logger.expects(:notify_with_level!).never
183
+ @logger.add(GELF::INFO, { :short_message => nil })
184
+ end
158
185
  end
159
186
 
160
187
  GELF::Levels.constants.each do |const|
@@ -210,7 +237,6 @@ class TestLogger < Test::Unit::TestCase
210
237
  @logger.formatter
211
238
  end
212
239
 
213
-
214
240
  context "close" do
215
241
  should "close socket" do
216
242
  @sender.expects(:close).once
@@ -129,8 +129,8 @@ class TestNotifier < Test::Unit::TestCase
129
129
  context "serialize_hash" do
130
130
  setup do
131
131
  @notifier.level_mapping = :direct
132
- @notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value' })
133
- @data = @notifier.__send__(:serialize_hash)
132
+ hash = { 'level' => GELF::WARN, 'field' => 'value' }
133
+ @data = @notifier.__send__(:serialize_hash, hash)
134
134
  assert @data.respond_to?(:each) # Enumerable::Enumerator in 1.8, ::Enumerator in 1.9, so...
135
135
  @deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
136
136
  assert_instance_of Hash, @deserialized_hash
@@ -145,8 +145,8 @@ class TestNotifier < Test::Unit::TestCase
145
145
 
146
146
  context "datagrams_from_hash" do
147
147
  should "not split short data" do
148
- @notifier.instance_variable_set('@hash', { 'version' => '1.0', 'short_message' => 'message' })
149
- datagrams = @notifier.__send__(:datagrams_from_hash)
148
+ hash = { 'version' => '1.0', 'short_message' => 'message' }
149
+ datagrams = @notifier.__send__(:datagrams_from_hash, hash)
150
150
  assert_equal 1, datagrams.count
151
151
  assert_instance_of String, datagrams[0]
152
152
 
@@ -165,8 +165,7 @@ class TestNotifier < Test::Unit::TestCase
165
165
  srand(1) # for stable tests
166
166
  hash = { 'version' => '1.0', 'short_message' => 'message' }
167
167
  hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
168
- @notifier.instance_variable_set('@hash', hash)
169
- datagrams = @notifier.__send__(:datagrams_from_hash)
168
+ datagrams = @notifier.__send__(:datagrams_from_hash, hash)
170
169
  assert_equal 2, datagrams.count
171
170
  datagrams.each_index do |i|
172
171
  datagram = datagrams[i]
@@ -188,8 +187,7 @@ class TestNotifier < Test::Unit::TestCase
188
187
  srand(1) # for stable tests
189
188
  hash = { 'version' => '1.0', 'short_message' => 'message' }
190
189
  hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
191
- @notifier.instance_variable_set('@hash', hash)
192
- datagrams = @notifier.__send__(:datagrams_from_hash)
190
+ datagrams = @notifier.__send__(:datagrams_from_hash, hash)
193
191
  assert_equal 2, datagrams.count
194
192
  datagrams.each_index do |i|
195
193
  datagram = datagrams[i]
@@ -274,6 +272,16 @@ class TestNotifier < Test::Unit::TestCase
274
272
  @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
275
273
  end
276
274
 
275
+ should "not mutate arguments" do
276
+ data = { 'version' => '1.0', 'short_message' => 'message', foo: { bar: "BAZ" } }
277
+ original_hash = data.hash
278
+
279
+ @sender.expects(:send_datagrams)
280
+ @notifier.notify!(data)
281
+
282
+ assert_equal(data.hash, original_hash)
283
+ end
284
+
277
285
  GELF::Levels.constants.each do |const|
278
286
  should "call notify with level #{const} from method name" do
279
287
  @notifier.expects(:notify_with_level).with(GELF.const_get(const), { 'version' => '1.0', 'short_message' => 'message' })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Palazhchenko
@@ -130,7 +130,7 @@ files:
130
130
  - test/test_notifier.rb
131
131
  - test/test_ruby_sender.rb
132
132
  - test/test_severity.rb
133
- homepage: http://github.com/Graylog2/gelf-rb
133
+ homepage: https://github.com/graylog-labs/gelf-rb
134
134
  licenses:
135
135
  - MIT
136
136
  metadata: {}
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.4.8
153
+ rubygems_version: 2.7.7
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Library to send GELF messages to Graylog logging server.