syslog-sd 1.2.4 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - ree
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby
7
+
8
+ notifications:
9
+ irc: "irc.freenode.org#graylog2"
data/CHANGELOG CHANGED
@@ -1,12 +1,17 @@
1
- 1.2.4, 2010-05-20:
1
+ 1.3.1, 2011-11-03:
2
+ ++ Merge with `gelf` gem, synchronize versions.
3
+ + allow to rescue from network errors.
4
+ + allow to set timestamp manually.
5
+
6
+ 1.2.4, 2011-05-20:
2
7
  * Fix a bug with SD-ID.
3
8
 
4
- 1.2.3, 2010-05-18:
9
+ 1.2.3, 2011-05-18:
5
10
  + Allow to send timestamp as float if desired. It may improve server's parsing speed.
6
11
 
7
- 1.2.2, 2010-05-17:
12
+ 1.2.2, 2011-05-17:
8
13
  * Minor metadata update. Moved to http://github.com/Graylog2/syslog-sd-rb
9
14
  * Return actual message from SyslogSD::Notifier#notify.
10
15
 
11
- 1.2.0, 2010-05-17:
16
+ 1.2.0, 2011-05-17:
12
17
  + Initial version, based on master branch of `gelf` gem.
data/README.rdoc CHANGED
@@ -3,6 +3,8 @@
3
3
  Super-Duper library to send syslog messages over UDP to logging server such as Graylog2 (http://graylog2.org).
4
4
  Supports Structured Data elements as defined by RFC 5424.
5
5
 
6
+ API documentation: http://rubydoc.info/github/Graylog2/syslog-sd-rb/master/frames
7
+
6
8
  Based on GELF gem (https://github.com/graylog2/gelf-rb).
7
9
 
8
10
  Works with Ruby 1.8.7 and 1.9.2. 1.8.6 is not supported.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.3.1
@@ -1,7 +1,7 @@
1
1
  module SyslogSD
2
2
  # syslog notifier.
3
3
  class Notifier
4
- attr_accessor :enabled, :collect_file_and_line, :timestamp_as_float
4
+ attr_accessor :enabled, :collect_file_and_line, :rescue_network_errors, :timestamp_as_float
5
5
  attr_reader :level, :default_options, :level_mapping
6
6
 
7
7
  # +host+ and +port+ are host/ip and port of syslog server.
@@ -13,6 +13,7 @@ module SyslogSD
13
13
 
14
14
  self.level = SyslogSD::DEBUG
15
15
  self.timestamp_as_float = false
16
+ self.rescue_network_errors = false
16
17
 
17
18
  self.default_options = default_options
18
19
  self.default_options['host'] ||= Socket.gethostname
@@ -110,8 +111,11 @@ module SyslogSD
110
111
  private
111
112
  def notify_with_level(message_level, *args)
112
113
  notify_with_level!(message_level, *args)
114
+ rescue SocketError
115
+ raise unless self.rescue_network_errors
113
116
  rescue Exception => exception
114
117
  notify_with_level!(SyslogSD::UNKNOWN, exception)
118
+ exception
115
119
  end
116
120
 
117
121
  def notify_with_level!(message_level, *args)
@@ -139,6 +143,7 @@ module SyslogSD
139
143
  @hash = default_options.merge(self.class.stringify_keys(args.merge(primary_data)))
140
144
  convert_hoptoad_keys_to_graylog2
141
145
  set_file_and_line if @collect_file_and_line
146
+ set_timestamp
142
147
  check_presence_of_mandatory_attributes
143
148
  @hash
144
149
  end
@@ -170,6 +175,10 @@ module SyslogSD
170
175
  @hash['line'] = match[2].to_i
171
176
  end
172
177
 
178
+ def set_timestamp
179
+ @hash['timestamp'] = Time.now.utc.to_f if @hash['timestamp'].nil?
180
+ end
181
+
173
182
  def check_presence_of_mandatory_attributes
174
183
  %w(short_message host).each do |attribute|
175
184
  if @hash[attribute].to_s.empty?
data/syslog-sd.gemspec CHANGED
@@ -4,19 +4,20 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{syslog-sd}
8
- s.version = "1.2.4"
7
+ s.name = "syslog-sd"
8
+ s.version = "1.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Alexey Palazhchenko}, %q{Lennart Koopmann}]
12
- s.date = %q{2011-05-20}
13
- s.description = %q{Super-Duper library to send syslog messages over UDP to logging server such as Graylog2. Supports Structured Data elements as defined by RFC 5424.}
14
- s.email = %q{alexey.palazhchenko@gmail.com}
11
+ s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
12
+ s.date = "2011-11-03"
13
+ s.description = "Super-Duper library to send syslog messages over UDP to logging server such as Graylog2. Supports Structured Data elements as defined by RFC 5424."
14
+ s.email = "alexey.palazhchenko@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ ".travis.yml",
20
21
  "CHANGELOG",
21
22
  "LICENSE",
22
23
  "README.rdoc",
@@ -35,10 +36,10 @@ Gem::Specification.new do |s|
35
36
  "test/test_ruby_sender.rb",
36
37
  "test/test_severity.rb"
37
38
  ]
38
- s.homepage = %q{http://github.com/Graylog2/syslog-sd-rb}
39
- s.require_paths = [%q{lib}]
40
- s.rubygems_version = %q{1.8.2}
41
- s.summary = %q{Library to send syslog messages over UDP to logging server such as Graylog2. Supports Structured Data elements as defined by RFC 5424.}
39
+ s.homepage = "http://github.com/Graylog2/syslog-sd-rb"
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.11"
42
+ s.summary = "Library to send syslog messages over UDP to logging server such as Graylog2. Supports Structured Data elements as defined by RFC 5424."
42
43
 
43
44
  if s.respond_to? :specification_version then
44
45
  s.specification_version = 3
@@ -108,6 +108,19 @@ class TestNotifier < Test::Unit::TestCase
108
108
  assert_match /test_notifier.rb/, hash['file']
109
109
  assert_equal line + 1, hash['line']
110
110
  end
111
+
112
+ should "set timestamp to current time if not set" do
113
+ hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
114
+ assert_instance_of Float, hash['timestamp']
115
+ now = Time.now.utc.to_f
116
+ assert ((now - 1)..(now + 1)).include?(hash['timestamp'])
117
+ end
118
+
119
+ should "set timestamp to specified time" do
120
+ timestamp = 1319799449.13765
121
+ hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message', 'timestamp' => timestamp })
122
+ assert_equal timestamp, hash['timestamp']
123
+ end
111
124
  end
112
125
 
113
126
  context "serialize_hash" do
@@ -164,12 +177,12 @@ class TestNotifier < Test::Unit::TestCase
164
177
 
165
178
  should "not send notifications with level below threshold" do
166
179
  @sender.expects(:send_datagram).never
167
- @notifier.notify!(@hash.merge('level' => SyslogSD::DEBUG))
180
+ assert_nil @notifier.notify!(@hash.merge('level' => SyslogSD::DEBUG))
168
181
  end
169
182
 
170
183
  should "not notifications with level equal or above threshold" do
171
184
  @sender.expects(:send_datagram).once
172
- @notifier.notify!(@hash.merge('level' => SyslogSD::WARN))
185
+ assert_kind_of String, @notifier.notify!(@hash.merge('level' => SyslogSD::WARN))
173
186
  end
174
187
  end
175
188
 
@@ -181,7 +194,7 @@ class TestNotifier < Test::Unit::TestCase
181
194
  should "not send datagram" do
182
195
  @sender.expects(:send_datagram).never
183
196
  @notifier.expects(:extract_hash).never
184
- @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
197
+ assert_nil @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
185
198
  end
186
199
 
187
200
  context "and enabled again" do
@@ -191,7 +204,7 @@ class TestNotifier < Test::Unit::TestCase
191
204
 
192
205
  should "send datagram" do
193
206
  @sender.expects(:send_datagram)
194
- @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
207
+ assert_kind_of String, @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
195
208
  end
196
209
  end
197
210
  end
@@ -200,7 +213,7 @@ class TestNotifier < Test::Unit::TestCase
200
213
  @sender.expects(:send_datagram).with do |datagram|
201
214
  datagram.is_a?(String)
202
215
  end
203
- @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
216
+ assert_kind_of String, @notifier.notify!({ 'version' => '1.0', 'short_message' => 'message' })
204
217
  end
205
218
 
206
219
  SyslogSD::Levels.constants.each do |const|
@@ -217,7 +230,22 @@ class TestNotifier < Test::Unit::TestCase
217
230
  should "rescue from invalid invocation of #notify" do
218
231
  @notifier.expects(:notify_with_level!).with(nil, instance_of(Hash)).raises(ArgumentError)
219
232
  @notifier.expects(:notify_with_level!).with(SyslogSD::UNKNOWN, instance_of(ArgumentError))
220
- assert_nothing_raised { @notifier.notify(:no_short_message => 'too bad') }
233
+ assert_kind_of ArgumentError, @notifier.notify(:no_short_message => 'too bad')
234
+ end
235
+ end
236
+
237
+ context "with notifier with real sender" do
238
+ setup do
239
+ @notifier = SyslogSD::Notifier.new('no_such_host_321')
240
+ end
241
+
242
+ should "raise exception" do
243
+ assert_raise(SocketError) { @notifier.notify('Hello!') }
244
+ end
245
+
246
+ should "not raise exception if asked" do
247
+ @notifier.rescue_network_errors = true
248
+ assert_nothing_raised { @notifier.notify('Hello!') }
221
249
  end
222
250
  end
223
251
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syslog-sd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 4
10
- version: 1.2.4
8
+ - 3
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexey Palazhchenko
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-20 00:00:00 Z
19
+ date: 2011-11-03 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: shoulda
@@ -70,6 +70,7 @@ extra_rdoc_files:
70
70
  - LICENSE
71
71
  - README.rdoc
72
72
  files:
73
+ - .travis.yml
73
74
  - CHANGELOG
74
75
  - LICENSE
75
76
  - README.rdoc
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements: []
117
118
 
118
119
  rubyforge_project:
119
- rubygems_version: 1.8.2
120
+ rubygems_version: 1.8.11
120
121
  signing_key:
121
122
  specification_version: 3
122
123
  summary: Library to send syslog messages over UDP to logging server such as Graylog2. Supports Structured Data elements as defined by RFC 5424.