gelf_redux 3.2.2 → 4.0.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 +4 -4
- data/README.md +1 -1
- data/lib/gelf/logger.rb +2 -1
- data/lib/gelf/notifier.rb +39 -24
- data/lib/gelf/transport/http.rb +34 -0
- data/lib/gelf/transport/https.rb +10 -0
- data/lib/gelf.rb +3 -2
- data/lib/gelf_redux.rb +1 -0
- metadata +36 -35
- data/.gemtest +0 -0
- data/CHANGELOG +0 -54
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -10
- data/Gemfile.lock +0 -24
- data/Rakefile +0 -41
- data/VERSION +0 -1
- data/benchmarks/notifier.rb +0 -39
- data/gelf.gemspec +0 -73
- data/test/helper.rb +0 -11
- data/test/test_logger.rb +0 -247
- data/test/test_notifier.rb +0 -317
- data/test/test_ruby_sender.rb +0 -28
- data/test/test_severity.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ef94954d82735b18011e82e2d8252c77ed68ebe75fabeec984499b83bea70e
|
4
|
+
data.tar.gz: b4762bac13ef37cc997a24cea8768497f7c5f6a7dee3442d763e7b12567370e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a961fd984224a309513b2717d50ebf3c9c0e6e65b563e36bb709ea9387d09756fd56b8508805bf34cdb6dc0fed07d9331126053e0477e32949fcab4ba371946a
|
7
|
+
data.tar.gz: aaacc6eb44d5db0dd09dd43bb9ee790db028941a3baef500039ecdf27d2a6eb6a2684bf3eb4520dd88164747e95fd739158d7be64028c61c1eb182bd653eb8c6
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## GELF (
|
1
|
+
## GELF (redux) Ruby library
|
2
2
|
This gem is intended to replace the existing and unmaintained gelf-rb https://github.com/graylog-labs/gelf-rb - since
|
3
3
|
the project went silent for a few years and there seems to be no intention in continuing any kind of support
|
4
4
|
(https://github.com/graylog-labs/gelf-rb/issues/93). So we decided to not just fork but set up a new gem.
|
data/lib/gelf/logger.rb
CHANGED
data/lib/gelf/notifier.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'gelf/transport/udp'
|
2
2
|
require 'gelf/transport/tcp'
|
3
3
|
require 'gelf/transport/tcp_tls'
|
4
|
+
require 'gelf/transport/http'
|
4
5
|
require 'gelf/transport/https'
|
5
6
|
|
6
7
|
# replace JSON and #to_json with Yajl if available
|
7
8
|
begin
|
8
|
-
require 'yajl
|
9
|
+
require 'yajl'
|
10
|
+
def json_dump(obj)
|
11
|
+
Yajl.dump(obj)
|
12
|
+
end
|
9
13
|
rescue LoadError
|
14
|
+
def json_dump(obj)
|
15
|
+
JSON.dump(obj)
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
module GELF
|
@@ -36,7 +43,6 @@ module GELF
|
|
36
43
|
self.default_options['version'] = SPEC_VERSION
|
37
44
|
self.default_options['host'] ||= Socket.gethostname
|
38
45
|
self.default_options['level'] ||= GELF::UNKNOWN
|
39
|
-
self.default_options['facility'] ||= 'gelf-rb'
|
40
46
|
self.default_options['protocol'] ||= GELF::Protocol::UDP
|
41
47
|
|
42
48
|
self.level_mapping = :logger
|
@@ -59,12 +65,12 @@ module GELF
|
|
59
65
|
# Default (safe) value is 'WAN'.
|
60
66
|
def max_chunk_size=(size)
|
61
67
|
case size.to_s.downcase
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
when 'wan'
|
69
|
+
@max_chunk_size = MAX_CHUNK_SIZE_WAN
|
70
|
+
when 'lan'
|
71
|
+
@max_chunk_size = MAX_CHUNK_SIZE_LAN
|
72
|
+
else
|
73
|
+
@max_chunk_size = size.to_int
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
@@ -84,12 +90,12 @@ module GELF
|
|
84
90
|
# Default (compatible) value is 'logger'.
|
85
91
|
def level_mapping=(mapping)
|
86
92
|
case mapping.to_s.downcase
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
when 'logger'
|
94
|
+
@level_mapping = GELF::LOGGER_MAPPING
|
95
|
+
when 'direct'
|
96
|
+
@level_mapping = GELF::DIRECT_MAPPING
|
97
|
+
else
|
98
|
+
@level_mapping = mapping
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
@@ -133,11 +139,12 @@ module GELF
|
|
133
139
|
end
|
134
140
|
end
|
135
141
|
|
136
|
-
|
142
|
+
private
|
137
143
|
|
138
144
|
def create_sender(host, port)
|
139
|
-
|
140
|
-
|
145
|
+
if [GELF::Protocol::HTTP, GELF::Protocol::HTTPS].include? default_options['protocol']
|
146
|
+
return create_http(host, port)
|
147
|
+
end
|
141
148
|
addresses = [[host, port]]
|
142
149
|
if default_options['protocol'] == GELF::Protocol::TCP
|
143
150
|
if default_options.key?('tls')
|
@@ -151,8 +158,13 @@ module GELF
|
|
151
158
|
end
|
152
159
|
end
|
153
160
|
|
154
|
-
def
|
155
|
-
|
161
|
+
def create_http(host, port)
|
162
|
+
klass = if default_options['protocol'] == GELF::Protocol::HTTPS
|
163
|
+
GELF::Transport::HTTPS
|
164
|
+
else
|
165
|
+
GELF::Transport::HTTP
|
166
|
+
end
|
167
|
+
klass.new host, port: port, path: default_options.delete('path'), headers: default_options.delete('headers')
|
156
168
|
end
|
157
169
|
|
158
170
|
def notify_with_level(message_level, *args)
|
@@ -168,11 +180,12 @@ module GELF
|
|
168
180
|
hash = extract_hash(*args)
|
169
181
|
hash['level'] = message_level unless message_level.nil?
|
170
182
|
if hash['level'] >= level
|
171
|
-
|
172
|
-
|
183
|
+
if [GELF::Protocol::HTTP, GELF::Protocol::HTTPS].include? default_options['protocol']
|
184
|
+
return @sender.transfer(hash)
|
185
|
+
end
|
173
186
|
if default_options['protocol'] == GELF::Protocol::TCP
|
174
187
|
validate_hash(hash)
|
175
|
-
@sender.send(hash
|
188
|
+
@sender.send(json_dump(hash) + "\0")
|
176
189
|
else
|
177
190
|
@sender.send_datagrams(datagrams_from_hash(hash))
|
178
191
|
end
|
@@ -190,7 +203,9 @@ module GELF
|
|
190
203
|
{ 'short_message' => object.to_s }
|
191
204
|
end
|
192
205
|
|
193
|
-
|
206
|
+
default_message_data = default_options.dup
|
207
|
+
default_message_data.delete('protocol')
|
208
|
+
hash = default_message_data.merge(self.class.stringify_keys(args.merge(primary_data)))
|
194
209
|
convert_hoptoad_keys_to_graylog2(hash)
|
195
210
|
set_file_and_line(hash) if @collect_file_and_line
|
196
211
|
set_timestamp(hash)
|
@@ -269,7 +284,7 @@ module GELF
|
|
269
284
|
def serialize_hash(hash)
|
270
285
|
validate_hash(hash)
|
271
286
|
|
272
|
-
Zlib::Deflate.deflate(hash
|
287
|
+
Zlib::Deflate.deflate(json_dump(hash)).bytes
|
273
288
|
end
|
274
289
|
|
275
290
|
def self.stringify_keys(data)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module GELF
|
2
|
+
module Transport
|
3
|
+
class HTTP
|
4
|
+
def initialize(host, port: 80, path: '', headers: nil)
|
5
|
+
@uri = URI::HTTP.build host: host, port: port
|
6
|
+
setup(headers, path)
|
7
|
+
end
|
8
|
+
def setup(headers, path)
|
9
|
+
path = "/#{path.to_s.delete_prefix('/')}"
|
10
|
+
@uri.path = path
|
11
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
12
|
+
@http.use_ssl = true if @uri.instance_of? URI::HTTPS
|
13
|
+
given_headers = headers || {}
|
14
|
+
@headers = default_headers.merge(given_headers)
|
15
|
+
end
|
16
|
+
def transfer(message)
|
17
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
18
|
+
request.body = json_dump(message)
|
19
|
+
@headers.each do |key, value|
|
20
|
+
# pass header only if value present -> allows clearing default headers
|
21
|
+
request[key] = value if value
|
22
|
+
end
|
23
|
+
@http.request(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_headers
|
27
|
+
{
|
28
|
+
'Accept' => 'application/json',
|
29
|
+
'Content-Type' => 'application/json'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/gelf.rb
CHANGED
data/lib/gelf_redux.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'gelf'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gelf_redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Palazhchenko
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2023-06-
|
16
|
+
date: 2023-06-22 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: shoulda
|
@@ -21,56 +21,70 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - "~>"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 4.0.0
|
25
25
|
type: :development
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - "~>"
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
31
|
+
version: 4.0.0
|
32
32
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
33
|
+
name: mocha
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- - "
|
36
|
+
- - "~>"
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
38
|
+
version: 2.0.4
|
39
39
|
type: :development
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
|
-
- - "
|
43
|
+
- - "~>"
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 2.0.4
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: test-unit
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 3.6.0
|
53
53
|
type: :development
|
54
54
|
prerelease: false
|
55
55
|
version_requirements: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 3.6.0
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
61
|
+
name: simplecov
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: 0.20.0
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
69
|
version_requirements: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: 0.20.0
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: webmock
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.18.1
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 3.18.1
|
74
88
|
- !ruby/object:Gem::Dependency
|
75
89
|
name: json
|
76
90
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,37 +100,24 @@ dependencies:
|
|
86
100
|
- !ruby/object:Gem::Version
|
87
101
|
version: '0'
|
88
102
|
description: Library to send GELF messages to Graylog logging server. Supports plain-text,
|
89
|
-
GELF messages and exceptions via UDP, TCP and
|
103
|
+
GELF messages and exceptions via UDP, TCP and HTTP(S)
|
90
104
|
email: admins@manet-marketing.de
|
91
105
|
executables: []
|
92
106
|
extensions: []
|
93
|
-
extra_rdoc_files:
|
94
|
-
- LICENSE
|
95
|
-
- README.md
|
107
|
+
extra_rdoc_files: []
|
96
108
|
files:
|
97
|
-
- ".gemtest"
|
98
|
-
- CHANGELOG
|
99
|
-
- CONTRIBUTING.md
|
100
|
-
- Gemfile
|
101
|
-
- Gemfile.lock
|
102
109
|
- LICENSE
|
103
110
|
- README.md
|
104
|
-
- Rakefile
|
105
|
-
- VERSION
|
106
|
-
- benchmarks/notifier.rb
|
107
|
-
- gelf.gemspec
|
108
111
|
- lib/gelf.rb
|
109
112
|
- lib/gelf/logger.rb
|
110
113
|
- lib/gelf/notifier.rb
|
111
114
|
- lib/gelf/severity.rb
|
115
|
+
- lib/gelf/transport/http.rb
|
116
|
+
- lib/gelf/transport/https.rb
|
112
117
|
- lib/gelf/transport/tcp.rb
|
113
118
|
- lib/gelf/transport/tcp_tls.rb
|
114
119
|
- lib/gelf/transport/udp.rb
|
115
|
-
-
|
116
|
-
- test/test_logger.rb
|
117
|
-
- test/test_notifier.rb
|
118
|
-
- test/test_ruby_sender.rb
|
119
|
-
- test/test_severity.rb
|
120
|
+
- lib/gelf_redux.rb
|
120
121
|
homepage: https://github.com/manet-marketing/gelf_redux
|
121
122
|
licenses:
|
122
123
|
- MIT
|
@@ -129,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
130
|
requirements:
|
130
131
|
- - ">="
|
131
132
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
133
|
+
version: '2.6'
|
133
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
135
|
requirements:
|
135
136
|
- - ">="
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
|
-
rubygems_version: 3.0.3
|
140
|
+
rubygems_version: 3.0.3.1
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: Library to send GELF messages to Graylog logging server.
|
data/.gemtest
DELETED
File without changes
|
data/CHANGELOG
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
3.0.0, 2016-08-21
|
2
|
-
+ Overhaul TCP support
|
3
|
-
+ Include automatic support for Celluloid::IO if available
|
4
|
-
+ Add TLS support to TCP transport
|
5
|
-
- Remove support for ancient Rubygems versions
|
6
|
-
- Remove support for Ruby 1.9.2 (1.9.3 works!)
|
7
|
-
- Remove already-deprecated `host` and `port` methods on GELF::Notifier
|
8
|
-
|
9
|
-
2.0.0, 2016-02-02
|
10
|
-
+ Added GELF TCP support.
|
11
|
-
|
12
|
-
1.3.2, 2011-12-02:
|
13
|
-
* support for rubygems-test.
|
14
|
-
* rescue from more network errors.
|
15
|
-
|
16
|
-
1.3.1, 2011-10-28:
|
17
|
-
+ allow to rescue from network errors.
|
18
|
-
|
19
|
-
1.3.0, 2011-07-27:
|
20
|
-
+ allow to set timestamp manually.
|
21
|
-
|
22
|
-
1.2.0.beta1, 2011-05-23:
|
23
|
-
+ compatibility with GELF specification 1.0:
|
24
|
-
* requires modern graylog2-server and graylog2-web-interface;
|
25
|
-
+ Notifier#default_options, Notifier#default_options=;
|
26
|
-
+ severity (level) threshold;
|
27
|
-
+ automatically set 'file', 'line' and 'timestamp' fields;
|
28
|
-
+ wrappers for GELF::Notifier#notify with severity:
|
29
|
-
+ GELF::Notifier.debug
|
30
|
-
+ GELF::Notifier.info
|
31
|
-
+ GELF::Notifier.warn
|
32
|
-
+ GELF::Notifier.error
|
33
|
-
+ GELF::Notifier.fatal
|
34
|
-
+ GELF::Notifier.unknown
|
35
|
-
+ full compatibility with Ruby Logger and other loggers:
|
36
|
-
+ GELF::Logger#fatal { "Argument 'foo' not given." }
|
37
|
-
+ GELF::Logger#error "Argument #{ @foo } mismatch."
|
38
|
-
+ GELF::Logger#info('initialize') { "Initializing..." }
|
39
|
-
+ GELF::Logger#add(GELF::FATAL) { 'Fatal error!' }
|
40
|
-
+ GELF::Logger#close
|
41
|
-
+ GELF::Logger#level = GELF::INFO
|
42
|
-
+ allow to change severity mapping;
|
43
|
-
+ send messages to receivers in round-robin;
|
44
|
-
* GELF::Notifier#host and #port are attr_readers now and deprecated (were attr_accessor);
|
45
|
-
+ allow to disable file and line collection (GELF::Notifier#collect_file_and_line = false);
|
46
|
-
- deprecated Gelf class removed.
|
47
|
-
|
48
|
-
1.0.2, 2010-11-29:
|
49
|
-
1.0.1, 2010-11-29:
|
50
|
-
- added more tests for chunking in attempt to locate not existing bug.
|
51
|
-
|
52
|
-
1.0.0, 2010-11-10:
|
53
|
-
+ initial stable version;
|
54
|
-
* deprecated Gelf class is still there.
|
data/CONTRIBUTING.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Please follow [the instructions on graylog.org](https://www.graylog.org/contributing-to-graylog/).
|
data/Gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
group :development do
|
4
|
-
gem "shoulda", "~> 2.11.3"
|
5
|
-
# Because of a dependency chain jeweler->github_api->oauth2->rack,
|
6
|
-
# pin the version: Rack 2.0.x doesn't work on < Ruby 2.2
|
7
|
-
gem 'rack', '< 2.0'
|
8
|
-
gem "mocha", "~> 1.1.0"
|
9
|
-
gem "test-unit", "~> 3.2.0"
|
10
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
metaclass (0.0.4)
|
5
|
-
mocha (1.1.0)
|
6
|
-
metaclass (~> 0.0.1)
|
7
|
-
power_assert (0.3.0)
|
8
|
-
rack (1.6.4)
|
9
|
-
shoulda (2.11.3)
|
10
|
-
test-unit (3.2.1)
|
11
|
-
power_assert
|
12
|
-
|
13
|
-
PLATFORMS
|
14
|
-
java
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
mocha (~> 1.1.0)
|
19
|
-
rack (< 2.0)
|
20
|
-
shoulda (~> 2.11.3)
|
21
|
-
test-unit (~> 3.2.0)
|
22
|
-
|
23
|
-
BUNDLED WITH
|
24
|
-
1.17.3
|
data/Rakefile
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'ci/reporter/rake/test_unit'
|
5
|
-
rescue LoadError
|
6
|
-
# nothing
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'rake/testtask'
|
10
|
-
Rake::TestTask.new(:test) do |test|
|
11
|
-
test.libs << 'lib' << 'test'
|
12
|
-
test.pattern = 'test/**/test_*.rb'
|
13
|
-
test.verbose = true
|
14
|
-
end
|
15
|
-
|
16
|
-
task :default => :test
|
17
|
-
|
18
|
-
begin
|
19
|
-
require 'rcov/rcovtask'
|
20
|
-
Rcov::RcovTask.new do |test|
|
21
|
-
test.libs << 'test'
|
22
|
-
test.pattern = 'test/**/test_*.rb'
|
23
|
-
test.rcov_opts << '--exclude gem'
|
24
|
-
test.verbose = true
|
25
|
-
end
|
26
|
-
rescue LoadError => e
|
27
|
-
task :rcov do
|
28
|
-
puts e
|
29
|
-
abort "rcov is not available. Run: gem install rcov"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
#require 'rake/rdoctask'
|
34
|
-
#Rake::RDocTask.new do |rdoc|
|
35
|
-
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
36
|
-
#
|
37
|
-
# rdoc.rdoc_dir = 'rdoc'
|
38
|
-
# rdoc.title = "gelf #{version}"
|
39
|
-
# rdoc.rdoc_files.include('README*')
|
40
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
-
#end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
3.1.0
|
data/benchmarks/notifier.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
puts "Loading..."
|
4
|
-
|
5
|
-
require 'benchmark'
|
6
|
-
require 'rubygems'
|
7
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
-
require 'gelf'
|
10
|
-
|
11
|
-
puts "Generating random data..."
|
12
|
-
srand(1)
|
13
|
-
RANDOM_DATA = ('A'..'z').to_a
|
14
|
-
k3_message = (1..3*1024).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join
|
15
|
-
|
16
|
-
TARGET_HOST = 'localhost'
|
17
|
-
TARGET_PORT = 12201
|
18
|
-
DEFAULT_OPTIONS = { '_host' => 'localhost' }
|
19
|
-
TIMES = 5000
|
20
|
-
|
21
|
-
SHORT_HASH = { 'short_message' => 'message' }
|
22
|
-
LONG_HASH = { 'short_message' => 'message', 'long_message' => k3_message }
|
23
|
-
|
24
|
-
|
25
|
-
notifier_lan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'LAN', DEFAULT_OPTIONS)
|
26
|
-
notifier_wan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'WAN', DEFAULT_OPTIONS)
|
27
|
-
|
28
|
-
# to create mongo collections, etc.
|
29
|
-
notifier_lan.notify!(LONG_HASH)
|
30
|
-
sleep(5)
|
31
|
-
|
32
|
-
puts "Sending #{TIMES} notifications...\n"
|
33
|
-
tms = Benchmark.bm(25) do |b|
|
34
|
-
b.report('lan, short data, 1 chunk ') { TIMES.times { notifier_lan.notify!(SHORT_HASH) } }
|
35
|
-
sleep(5)
|
36
|
-
b.report('lan, long data, 1 chunk ') { TIMES.times { notifier_lan.notify!(LONG_HASH) } }
|
37
|
-
sleep(5)
|
38
|
-
b.report('wan, long data, 2 chunks') { TIMES.times { notifier_wan.notify!(LONG_HASH) } }
|
39
|
-
end
|
data/gelf.gemspec
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "gelf_redux"
|
3
|
-
s.version = "3.2.2"
|
4
|
-
|
5
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
-
s.required_ruby_version = ">= 1.9"
|
7
|
-
s.require_paths = ["lib"]
|
8
|
-
s.authors = ["Alexey Palazhchenko", "Lennart Koopmann", "Zac Sprackett", "Marcus Ilgner", "Sebastian Seidel", "Christian Rolle"]
|
9
|
-
s.date = "2023-06-19"
|
10
|
-
s.description = "Library to send GELF messages to Graylog logging server. Supports plain-text, GELF messages and exceptions via UDP, TCP and HTTPS"
|
11
|
-
s.email = "admins@manet-marketing.de"
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
"LICENSE",
|
14
|
-
"README.md"
|
15
|
-
]
|
16
|
-
s.files = [
|
17
|
-
".gemtest",
|
18
|
-
"CHANGELOG",
|
19
|
-
"CONTRIBUTING.md",
|
20
|
-
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
|
-
"LICENSE",
|
23
|
-
"README.md",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"benchmarks/notifier.rb",
|
27
|
-
"gelf.gemspec",
|
28
|
-
"lib/gelf.rb",
|
29
|
-
"lib/gelf/logger.rb",
|
30
|
-
"lib/gelf/notifier.rb",
|
31
|
-
"lib/gelf/severity.rb",
|
32
|
-
"lib/gelf/transport/tcp.rb",
|
33
|
-
"lib/gelf/transport/tcp_tls.rb",
|
34
|
-
"lib/gelf/transport/udp.rb",
|
35
|
-
"test/helper.rb",
|
36
|
-
"test/test_logger.rb",
|
37
|
-
"test/test_notifier.rb",
|
38
|
-
"test/test_ruby_sender.rb",
|
39
|
-
"test/test_severity.rb"
|
40
|
-
]
|
41
|
-
s.homepage = "https://github.com/manet-marketing/gelf_redux"
|
42
|
-
s.licenses = ["MIT"]
|
43
|
-
s.rubygems_version = "2.5.1"
|
44
|
-
s.summary = "Library to send GELF messages to Graylog logging server."
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
s.specification_version = 4
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('3.2.0') then
|
50
|
-
s.add_development_dependency(%q<typhoeus>, ["~> 1.4.0"])
|
51
|
-
end
|
52
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
54
|
-
s.add_development_dependency(%q<rack>, ["< 2.0"])
|
55
|
-
s.add_development_dependency(%q<mocha>, ["~> 1.1.0"])
|
56
|
-
s.add_development_dependency(%q<test-unit>, ["~> 3.2.0"])
|
57
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
58
|
-
else
|
59
|
-
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
60
|
-
s.add_dependency(%q<rack>, ["< 2.0"])
|
61
|
-
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
|
62
|
-
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
|
63
|
-
s.add_dependency(%q<json>, [">= 0"])
|
64
|
-
end
|
65
|
-
else
|
66
|
-
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
67
|
-
s.add_dependency(%q<rack>, ["< 2.0"])
|
68
|
-
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
|
69
|
-
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
|
70
|
-
s.add_dependency(%q<json>, [">= 0"])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
data/test/helper.rb
DELETED
data/test/test_logger.rb
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestLogger < Test::Unit::TestCase
|
4
|
-
context "with logger with mocked sender" do
|
5
|
-
setup do
|
6
|
-
Socket.stubs(:gethostname).returns('stubbed_hostname')
|
7
|
-
@logger = GELF::Logger.new
|
8
|
-
@sender = mock
|
9
|
-
@logger.instance_variable_set('@sender', @sender)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "respond to #close" do
|
13
|
-
assert @logger.respond_to?(:close)
|
14
|
-
end
|
15
|
-
|
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
|
-
|
27
|
-
# logger.add(Logger::INFO, 'Message')
|
28
|
-
should "implement add method with level and message from parameters, facility from defaults" do
|
29
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
30
|
-
level == GELF::INFO &&
|
31
|
-
hash['short_message'] == 'Message' &&
|
32
|
-
hash['facility'] == 'gelf-rb'
|
33
|
-
end
|
34
|
-
@logger.add(GELF::INFO, nil, 'Message')
|
35
|
-
end
|
36
|
-
|
37
|
-
# logger.add(Logger::INFO, RuntimeError.new('Boom!'))
|
38
|
-
should "implement add method with level and exception from parameters, facility from defaults" do
|
39
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
40
|
-
level == GELF::INFO &&
|
41
|
-
hash['short_message'] == 'RuntimeError: Boom!' &&
|
42
|
-
hash['full_message'] =~ /^Backtrace/ &&
|
43
|
-
hash['facility'] == 'gelf-rb'
|
44
|
-
end
|
45
|
-
@logger.add(GELF::INFO, nil, RuntimeError.new('Boom!'))
|
46
|
-
end
|
47
|
-
|
48
|
-
# logger.add(Logger::INFO) { 'Message' }
|
49
|
-
should "implement add method with level from parameter, message from block, facility from defaults" do
|
50
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
51
|
-
level == GELF::INFO &&
|
52
|
-
hash['short_message'] == 'Message' &&
|
53
|
-
hash['facility'] == 'gelf-rb'
|
54
|
-
end
|
55
|
-
@logger.add(GELF::INFO, nil, nil) { 'Message' }
|
56
|
-
end
|
57
|
-
|
58
|
-
# logger.add(Logger::INFO) { RuntimeError.new('Boom!') }
|
59
|
-
should "implement add method with level from parameter, exception from block, facility from defaults" do
|
60
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
61
|
-
level == GELF::INFO &&
|
62
|
-
hash['short_message'] == 'RuntimeError: Boom!' &&
|
63
|
-
hash['full_message'] =~ /^Backtrace/ &&
|
64
|
-
hash['facility'] == 'gelf-rb'
|
65
|
-
end
|
66
|
-
@logger.add(GELF::INFO, nil, nil) { RuntimeError.new('Boom!') }
|
67
|
-
end
|
68
|
-
|
69
|
-
# logger.add(Logger::INFO, 'Message', 'Facility')
|
70
|
-
should "implement add method with level, message and facility from parameters" do
|
71
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
72
|
-
level == GELF::INFO &&
|
73
|
-
hash['short_message'] == 'Message' &&
|
74
|
-
hash['facility'] == 'Facility'
|
75
|
-
end
|
76
|
-
@logger.add(GELF::INFO, 'Message', 'Facility')
|
77
|
-
end
|
78
|
-
|
79
|
-
# logger.add(Logger::INFO, 'Message', nil)
|
80
|
-
should "use facility from initialization if facility is nil" do
|
81
|
-
logger = GELF::Logger.new('localhost', 12202, 'WAN', :facility => 'foo-bar')
|
82
|
-
logger.expects(:notify_with_level!).with do |level, hash|
|
83
|
-
level == GELF::INFO &&
|
84
|
-
hash['short_message'] == 'Message' &&
|
85
|
-
hash['facility'] == 'foo-bar'
|
86
|
-
end
|
87
|
-
logger.add(GELF::INFO, 'Message', nil)
|
88
|
-
end
|
89
|
-
|
90
|
-
# logger.add(Logger::INFO, 'Message', nil)
|
91
|
-
should "use default facility if facility is nil" do
|
92
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
93
|
-
level == GELF::INFO &&
|
94
|
-
hash['short_message'] == 'Message' &&
|
95
|
-
hash['facility'] == 'gelf-rb'
|
96
|
-
end
|
97
|
-
@logger.add(GELF::INFO, 'Message', nil)
|
98
|
-
end
|
99
|
-
|
100
|
-
# logger.add(Logger::INFO, RuntimeError.new('Boom!'), 'Facility')
|
101
|
-
should "implement add method with level, exception and facility from parameters" do
|
102
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
103
|
-
level == GELF::INFO &&
|
104
|
-
hash['short_message'] == 'RuntimeError: Boom!' &&
|
105
|
-
hash['full_message'] =~ /^Backtrace/ &&
|
106
|
-
hash['facility'] == 'Facility'
|
107
|
-
end
|
108
|
-
@logger.add(GELF::INFO, RuntimeError.new('Boom!'), 'Facility')
|
109
|
-
end
|
110
|
-
|
111
|
-
# logger.add(Logger::INFO, nil, 'Facility') { 'Message' }
|
112
|
-
should "implement add method with level and facility from parameters, message from block" do
|
113
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
114
|
-
level == GELF::INFO &&
|
115
|
-
hash['short_message'] == 'Message' &&
|
116
|
-
hash['facility'] == 'Facility'
|
117
|
-
end
|
118
|
-
@logger.add(GELF::INFO, nil, 'Facility') { 'Message' }
|
119
|
-
end
|
120
|
-
|
121
|
-
# logger.add(Logger::INFO, nil, 'Facility') { RuntimeError.new('Boom!') }
|
122
|
-
should "implement add method with level and facility from parameters, exception from block" do
|
123
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
124
|
-
level == GELF::INFO &&
|
125
|
-
hash['short_message'] == 'RuntimeError: Boom!' &&
|
126
|
-
hash['full_message'] =~ /^Backtrace/ &&
|
127
|
-
hash['facility'] == 'Facility'
|
128
|
-
end
|
129
|
-
@logger.add(GELF::INFO, nil, 'Facility') { RuntimeError.new('Boom!') }
|
130
|
-
end
|
131
|
-
|
132
|
-
# logger.add(Logger::INFO, { :short_message => "Some message" })
|
133
|
-
should "implement add method with level and message from hash, facility from defaults" do
|
134
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
135
|
-
level == GELF::INFO &&
|
136
|
-
hash['short_message'] == 'Some message' &&
|
137
|
-
hash['facility'] == 'gelf-rb'
|
138
|
-
end
|
139
|
-
@logger.add(GELF::INFO, { :short_message => "Some message" })
|
140
|
-
end
|
141
|
-
|
142
|
-
# logger.add(Logger::INFO, { :short_message => "Some message", :_foo => "bar", "_zomg" => "wat" })
|
143
|
-
should "implement add method with level and message from hash, facility from defaults and some additional fields" do
|
144
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
145
|
-
level == GELF::INFO &&
|
146
|
-
hash['short_message'] == 'Some message' &&
|
147
|
-
hash['facility'] == 'gelf-rb' &&
|
148
|
-
hash['_foo'] == 'bar' &&
|
149
|
-
hash['_zomg'] == 'wat'
|
150
|
-
end
|
151
|
-
@logger.add(GELF::INFO, { :short_message => "Some message", :_foo => "bar", "_zomg" => "wat"})
|
152
|
-
end
|
153
|
-
|
154
|
-
# logger.add(Logger::INFO, { :short_message => "Some message", :_foo => "bar", "_zomg" => "wat" }, 'somefac')
|
155
|
-
should "implement add method with level and message from hash, facility from parameters and some additional fields" do
|
156
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
157
|
-
level == GELF::INFO &&
|
158
|
-
hash['short_message'] == 'Some message' &&
|
159
|
-
hash['facility'] == 'somefac' &&
|
160
|
-
hash['_foo'] == 'bar' &&
|
161
|
-
hash['_zomg'] == 'wat'
|
162
|
-
end
|
163
|
-
@logger.add(GELF::INFO, { :short_message => "Some message", :_foo => "bar", "_zomg" => "wat"}, "somefac")
|
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
|
185
|
-
end
|
186
|
-
|
187
|
-
GELF::Levels.constants.each do |const|
|
188
|
-
# logger.error "Argument #{ @foo } mismatch."
|
189
|
-
should "call add with level #{const} from method name, message from parameter" do
|
190
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
191
|
-
level == GELF.const_get(const) &&
|
192
|
-
hash['short_message'] == 'message' &&
|
193
|
-
hash['facility'] == 'gelf-rb'
|
194
|
-
end
|
195
|
-
@logger.__send__(const.downcase, 'message')
|
196
|
-
end
|
197
|
-
|
198
|
-
# logger.fatal { "Argument 'foo' not given." }
|
199
|
-
should "call add with level #{const} from method name, message from block" do
|
200
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
201
|
-
level == GELF.const_get(const) &&
|
202
|
-
hash['short_message'] == 'message' &&
|
203
|
-
hash['facility'] == 'gelf-rb'
|
204
|
-
end
|
205
|
-
@logger.__send__(const.downcase) { 'message' }
|
206
|
-
end
|
207
|
-
|
208
|
-
# logger.info('initialize') { "Initializing..." }
|
209
|
-
should "call add with level #{const} from method name, facility from parameter, message from block" do
|
210
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
211
|
-
level == GELF.const_get(const) &&
|
212
|
-
hash['short_message'] == 'message' &&
|
213
|
-
hash['facility'] == 'facility'
|
214
|
-
end
|
215
|
-
@logger.__send__(const.downcase, 'facility') { 'message' }
|
216
|
-
end
|
217
|
-
|
218
|
-
should "respond to #{const.downcase}?" do
|
219
|
-
@logger.level = GELF.const_get(const) - 1
|
220
|
-
assert @logger.__send__(const.to_s.downcase + '?')
|
221
|
-
@logger.level = GELF.const_get(const)
|
222
|
-
assert @logger.__send__(const.to_s.downcase + '?')
|
223
|
-
@logger.level = GELF.const_get(const) + 1
|
224
|
-
assert !@logger.__send__(const.to_s.downcase + '?')
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
should "support Logger#<<" do
|
229
|
-
@logger.expects(:notify_with_level!).with do |level, hash|
|
230
|
-
level == GELF::UNKNOWN &&
|
231
|
-
hash['short_message'] == "Message"
|
232
|
-
end
|
233
|
-
@logger << "Message"
|
234
|
-
end
|
235
|
-
|
236
|
-
should "have formatter attribute" do
|
237
|
-
@logger.formatter
|
238
|
-
end
|
239
|
-
|
240
|
-
context "close" do
|
241
|
-
should "close socket" do
|
242
|
-
@sender.expects(:close).once
|
243
|
-
@logger.close
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
data/test/test_notifier.rb
DELETED
@@ -1,317 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
RANDOM_DATA = ('A'..'Z').to_a
|
4
|
-
|
5
|
-
class TestNotifier < Test::Unit::TestCase
|
6
|
-
should "allow access to host, port, max_chunk_size and default_options" do
|
7
|
-
Socket.expects(:gethostname).returns('default_hostname')
|
8
|
-
n = GELF::Notifier.new
|
9
|
-
assert_equal [[['localhost', 12201]], 1420], [n.addresses, n.max_chunk_size]
|
10
|
-
assert_equal( { 'version' => '1.0', 'level' => GELF::UNKNOWN, 'protocol' => 0,
|
11
|
-
'host' => 'default_hostname', 'facility' => 'gelf-rb' },
|
12
|
-
n.default_options )
|
13
|
-
n.addresses, n.max_chunk_size, n.default_options = [['graylog2.org', 7777]], :lan, {:host => 'grayhost'}
|
14
|
-
assert_equal [['graylog2.org', 7777]], n.addresses
|
15
|
-
assert_equal 8154, n.max_chunk_size
|
16
|
-
assert_equal({'host' => 'grayhost'}, n.default_options)
|
17
|
-
|
18
|
-
n.max_chunk_size = 1337.1
|
19
|
-
assert_equal 1337, n.max_chunk_size
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with notifier with mocked sender" do
|
23
|
-
setup do
|
24
|
-
Socket.stubs(:gethostname).returns('stubbed_hostname')
|
25
|
-
@notifier = GELF::Notifier.new('host', 12345)
|
26
|
-
@sender = mock
|
27
|
-
@notifier.instance_variable_set('@sender', @sender)
|
28
|
-
end
|
29
|
-
|
30
|
-
context "extract_hash" do
|
31
|
-
should "check arguments" do
|
32
|
-
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash) }
|
33
|
-
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, 1, 2, 3) }
|
34
|
-
end
|
35
|
-
|
36
|
-
should "work with hash" do
|
37
|
-
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
38
|
-
assert_equal '1.0', hash['version']
|
39
|
-
assert_equal 'message', hash['short_message']
|
40
|
-
end
|
41
|
-
|
42
|
-
should "work with any object which responds to #to_hash" do
|
43
|
-
o = Object.new
|
44
|
-
o.expects(:to_hash).returns({ 'version' => '1.0', 'short_message' => 'message' })
|
45
|
-
hash = @notifier.__send__(:extract_hash, o)
|
46
|
-
assert_equal '1.0', hash['version']
|
47
|
-
assert_equal 'message', hash['short_message']
|
48
|
-
end
|
49
|
-
|
50
|
-
should "work with exception with backtrace" do
|
51
|
-
e = RuntimeError.new('message')
|
52
|
-
e.set_backtrace(caller)
|
53
|
-
hash = @notifier.__send__(:extract_hash, e)
|
54
|
-
assert_equal 'RuntimeError: message', hash['short_message']
|
55
|
-
assert_match(/Backtrace/, hash['full_message'])
|
56
|
-
assert_equal GELF::ERROR, hash['level']
|
57
|
-
end
|
58
|
-
|
59
|
-
should "work with exception without backtrace" do
|
60
|
-
e = RuntimeError.new('message')
|
61
|
-
hash = @notifier.__send__(:extract_hash, e)
|
62
|
-
assert_match(/Backtrace is not available/, hash['full_message'])
|
63
|
-
end
|
64
|
-
|
65
|
-
should "work with exception and hash" do
|
66
|
-
e, h = RuntimeError.new('message'), {'param' => 1, 'level' => GELF::FATAL, 'short_message' => 'will be hidden by exception'}
|
67
|
-
hash = @notifier.__send__(:extract_hash, e, h)
|
68
|
-
assert_equal 'RuntimeError: message', hash['short_message']
|
69
|
-
assert_equal GELF::FATAL, hash['level']
|
70
|
-
assert_equal 1, hash['param']
|
71
|
-
end
|
72
|
-
|
73
|
-
should "work with plain text" do
|
74
|
-
hash = @notifier.__send__(:extract_hash, 'message')
|
75
|
-
assert_equal 'message', hash['short_message']
|
76
|
-
assert_equal GELF::INFO, hash['level']
|
77
|
-
end
|
78
|
-
|
79
|
-
should "work with plain text and hash" do
|
80
|
-
hash = @notifier.__send__(:extract_hash, 'message', 'level' => GELF::WARN)
|
81
|
-
assert_equal 'message', hash['short_message']
|
82
|
-
assert_equal GELF::WARN, hash['level']
|
83
|
-
end
|
84
|
-
|
85
|
-
should "covert hash keys to strings" do
|
86
|
-
hash = @notifier.__send__(:extract_hash, :short_message => :message)
|
87
|
-
assert hash.has_key?('short_message')
|
88
|
-
assert !hash.has_key?(:short_message)
|
89
|
-
end
|
90
|
-
|
91
|
-
should "not overwrite keys on convert" do
|
92
|
-
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :short_message => :message1, 'short_message' => 'message2') }
|
93
|
-
end
|
94
|
-
|
95
|
-
should "use default_options" do
|
96
|
-
@notifier.default_options = {:foo => 'bar', 'short_message' => 'will be hidden by explicit argument', 'host' => 'some_host'}
|
97
|
-
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
98
|
-
assert_equal 'bar', hash['foo']
|
99
|
-
assert_equal 'message', hash['short_message']
|
100
|
-
end
|
101
|
-
|
102
|
-
should "be compatible with HoptoadNotifier" do
|
103
|
-
# https://github.com/thoughtbot/hoptoad_notifier/blob/master/README.rdoc, section Going beyond exceptions
|
104
|
-
hash = @notifier.__send__(:extract_hash, :error_class => 'Class', :error_message => 'Message')
|
105
|
-
assert_equal 'Class: Message', hash['short_message']
|
106
|
-
end
|
107
|
-
|
108
|
-
should "set file and line" do
|
109
|
-
line = __LINE__
|
110
|
-
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
111
|
-
assert_match(/test_notifier.rb/, hash['file'])
|
112
|
-
assert_equal line + 1, hash['line']
|
113
|
-
end
|
114
|
-
|
115
|
-
should "set timestamp to current time if not set" do
|
116
|
-
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
117
|
-
assert_instance_of Float, hash['timestamp']
|
118
|
-
now = Time.now.utc.to_f
|
119
|
-
assert ((now - 1)..(now + 1)).include?(hash['timestamp'])
|
120
|
-
end
|
121
|
-
|
122
|
-
should "set timestamp to specified time" do
|
123
|
-
timestamp = 1319799449.13765
|
124
|
-
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message', 'timestamp' => timestamp })
|
125
|
-
assert_equal timestamp, hash['timestamp']
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "serialize_hash" do
|
130
|
-
setup do
|
131
|
-
@notifier.level_mapping = :direct
|
132
|
-
hash = { 'level' => GELF::WARN, 'field' => 'value' }
|
133
|
-
@data = @notifier.__send__(:serialize_hash, hash)
|
134
|
-
assert @data.respond_to?(:each) # Enumerable::Enumerator in 1.8, ::Enumerator in 1.9, so...
|
135
|
-
@deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
|
136
|
-
assert_instance_of Hash, @deserialized_hash
|
137
|
-
end
|
138
|
-
|
139
|
-
should "map level using mapping" do
|
140
|
-
assert_not_equal GELF::WARN, @deserialized_hash['level']
|
141
|
-
assert_not_equal GELF::LOGGER_MAPPING[GELF::WARN], @deserialized_hash['level']
|
142
|
-
assert_equal GELF::DIRECT_MAPPING[GELF::WARN], @deserialized_hash['level']
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "datagrams_from_hash" do
|
147
|
-
should "not split short data" do
|
148
|
-
hash = { 'version' => '1.0', 'short_message' => 'message' }
|
149
|
-
datagrams = @notifier.__send__(:datagrams_from_hash, hash)
|
150
|
-
assert_equal 1, datagrams.count
|
151
|
-
assert_instance_of String, datagrams[0]
|
152
|
-
|
153
|
-
asserted = "\x78\x9c"
|
154
|
-
if RUBY_VERSION[0,1].to_i >= 2
|
155
|
-
puts "I'm a Ruby > 2.0.0. Enforcing ASCII-8BIT. (#{RUBY_VERSION}/#{RUBY_VERSION[0,1].to_i})"
|
156
|
-
# lol well yeah, Rubby.
|
157
|
-
# http://stackoverflow.com/questions/15843684/binary-string-literals-in-ruby-2-0
|
158
|
-
asserted = asserted.b
|
159
|
-
end
|
160
|
-
|
161
|
-
assert_equal asserted, datagrams[0][0..1] # zlib header
|
162
|
-
end
|
163
|
-
|
164
|
-
should "split long data" do
|
165
|
-
srand(1) # for stable tests
|
166
|
-
hash = { 'version' => '1.0', 'short_message' => 'message' }
|
167
|
-
hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
|
168
|
-
datagrams = @notifier.__send__(:datagrams_from_hash, hash)
|
169
|
-
assert_equal 2, datagrams.count
|
170
|
-
datagrams.each_index do |i|
|
171
|
-
datagram = datagrams[i]
|
172
|
-
assert_instance_of String, datagram
|
173
|
-
assert datagram[0..1] == "\x1e\x0f" # chunked GELF magic number
|
174
|
-
# datagram[2..9] is a message id
|
175
|
-
assert_equal i, datagram[10].ord
|
176
|
-
assert_equal datagrams.count, datagram[11].ord
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
should "split long data when subclassed" do
|
181
|
-
class MyNotifier < GELF::Notifier; end
|
182
|
-
|
183
|
-
@notifier = MyNotifier.new('host', 1234)
|
184
|
-
@sender = mock
|
185
|
-
@notifier.instance_variable_set('@sender', @sender)
|
186
|
-
|
187
|
-
srand(1) # for stable tests
|
188
|
-
hash = { 'version' => '1.0', 'short_message' => 'message' }
|
189
|
-
hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
|
190
|
-
datagrams = @notifier.__send__(:datagrams_from_hash, hash)
|
191
|
-
assert_equal 2, datagrams.count
|
192
|
-
datagrams.each_index do |i|
|
193
|
-
datagram = datagrams[i]
|
194
|
-
assert_instance_of String, datagram
|
195
|
-
assert datagram[0..1] == "\x1e\x0f" # chunked GELF magic number
|
196
|
-
# datagram[2..9] is a message id
|
197
|
-
assert_equal i, datagram[10].ord
|
198
|
-
assert_equal datagrams.count, datagram[11].ord
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
should "throw an error if more than MAX_CHUNKS will be created" do
|
203
|
-
srand(1) # for stable tests
|
204
|
-
hash = { 'version' => '1.0', 'short_message' => 'message' }
|
205
|
-
hash.merge!('something' => (0..3000).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join) # or it will be compressed too good
|
206
|
-
@notifier.max_chunk_size = 10
|
207
|
-
@notifier.instance_variable_set('@hash', hash)
|
208
|
-
assert_raise(ArgumentError) do
|
209
|
-
@notifier.__send__(:datagrams_from_hash)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
context "level threshold" do
|
215
|
-
setup do
|
216
|
-
@notifier.level = GELF::WARN
|
217
|
-
@hash = { 'version' => '1.0', 'short_message' => 'message' }
|
218
|
-
end
|
219
|
-
|
220
|
-
['debug', 'DEBUG', :debug].each do |l|
|
221
|
-
should "allow to set threshold as #{l.inspect}" do
|
222
|
-
@notifier.level = l
|
223
|
-
assert_equal GELF::DEBUG, @notifier.level
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
should "not send notifications with level below threshold" do
|
228
|
-
@sender.expects(:send_datagrams).never
|
229
|
-
@notifier.notify!(@hash.merge('level' => GELF::DEBUG))
|
230
|
-
end
|
231
|
-
|
232
|
-
should "not notifications with level equal or above threshold" do
|
233
|
-
@sender.expects(:send_datagrams).once
|
234
|
-
@notifier.notify!(@hash.merge('level' => GELF::WARN))
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context "close" do
|
239
|
-
should "close sender" do
|
240
|
-
@sender.expects(:close).once
|
241
|
-
@notifier.close
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context "when disabled" do
|
246
|
-
setup do
|
247
|
-
@notifier.disable
|
248
|
-
end
|
249
|
-
|
250
|
-
should "not send datagrams" do
|
251
|
-
@sender.expects(:send_datagrams).never
|
252
|
-
@notifier.expects(:extract_hash).never
|
253
|
-
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
254
|
-
end
|
255
|
-
|
256
|
-
context "and enabled again" do
|
257
|
-
setup do
|
258
|
-
@notifier.enable
|
259
|
-
end
|
260
|
-
|
261
|
-
should "send datagrams" do
|
262
|
-
@sender.expects(:send_datagrams)
|
263
|
-
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
should "pass valid data to sender" do
|
269
|
-
@sender.expects(:send_datagrams).with do |datagrams|
|
270
|
-
datagrams.is_a?(Array) && datagrams[0].is_a?(String)
|
271
|
-
end
|
272
|
-
@notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
|
273
|
-
end
|
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
|
-
|
285
|
-
GELF::Levels.constants.each do |const|
|
286
|
-
should "call notify with level #{const} from method name" do
|
287
|
-
@notifier.expects(:notify_with_level).with(GELF.const_get(const), { 'version' => '1.0', 'short_message' => 'message' })
|
288
|
-
@notifier.__send__(const.downcase, { 'version' => '1.0', 'short_message' => 'message' })
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
should "not rescue from invalid invocation of #notify!" do
|
293
|
-
assert_raise(ArgumentError) { @notifier.notify!(:no_short_message => 'too bad') }
|
294
|
-
end
|
295
|
-
|
296
|
-
should "rescue from invalid invocation of #notify" do
|
297
|
-
@notifier.expects(:notify_with_level!).with(nil, instance_of(Hash)).raises(ArgumentError)
|
298
|
-
@notifier.expects(:notify_with_level!).with(GELF::UNKNOWN, instance_of(ArgumentError))
|
299
|
-
assert_nothing_raised { @notifier.notify(:no_short_message => 'too bad') }
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
context "with notifier with real sender" do
|
304
|
-
setup do
|
305
|
-
@notifier = GELF::Notifier.new('no_such_host_321')
|
306
|
-
end
|
307
|
-
|
308
|
-
should "raise exception" do
|
309
|
-
assert_raise(SocketError) { @notifier.notify('Hello!') }
|
310
|
-
end
|
311
|
-
|
312
|
-
should "not raise exception if asked" do
|
313
|
-
@notifier.rescue_network_errors = true
|
314
|
-
assert_nothing_raised { @notifier.notify('Hello!') }
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
data/test/test_ruby_sender.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestRubyUdpSender < Test::Unit::TestCase
|
4
|
-
context "with ruby sender" do
|
5
|
-
setup do
|
6
|
-
@addresses = [['localhost', 12201], ['localhost', 12202]]
|
7
|
-
@sender = GELF::Transport::UDP.new(@addresses)
|
8
|
-
@datagrams1 = %w(d1 d2 d3)
|
9
|
-
@datagrams2 = %w(e1 e2 e3)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "send_datagrams" do
|
13
|
-
setup do
|
14
|
-
@sender.send_datagrams(@datagrams1)
|
15
|
-
@sender.send_datagrams(@datagrams2)
|
16
|
-
end
|
17
|
-
|
18
|
-
before_should "be called 3 times with 1st and 2nd address" do
|
19
|
-
UDPSocket.any_instance.expects(:send).times(3).with do |datagram, _, host, port|
|
20
|
-
datagram.start_with?('d') && host == 'localhost' && port == 12201
|
21
|
-
end
|
22
|
-
UDPSocket.any_instance.expects(:send).times(3).with do |datagram, _, host, port|
|
23
|
-
datagram.start_with?('e') && host == 'localhost' && port == 12202
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/test_severity.rb
DELETED