fluent-plugin-sensu 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/fluent-plugin-sensu.gemspec +1 -1
- data/lib/fluent/plugin/out_sensu.rb +13 -1
- data/test/plugin/test_out_sensu.rb +18 -0
- metadata +5 -4
data/CHANGELOG.md
ADDED
data/fluent-plugin-sensu.gemspec
CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "fluent-plugin-sensu"
|
9
|
-
spec.version = '1.0.
|
9
|
+
spec.version = '1.0.1'
|
10
10
|
spec.authors = ["MIYAKAWA Taku"]
|
11
11
|
spec.email = ["miyakawa.taku@gmail.com"]
|
12
12
|
spec.description = 'Fluentd output plugin to send checks' +
|
@@ -186,7 +186,7 @@ module Fluent
|
|
186
186
|
# Send a check result to sensu-client.
|
187
187
|
private
|
188
188
|
def send_check(server, port, check_result)
|
189
|
-
json = check_result
|
189
|
+
json = to_json(check_result)
|
190
190
|
sensu_client = TCPSocket.open(@server, @port)
|
191
191
|
begin
|
192
192
|
sensu_client.puts(json)
|
@@ -195,6 +195,18 @@ module Fluent
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
+
# Make a json from the data.
|
199
|
+
public
|
200
|
+
def to_json(data)
|
201
|
+
raw_json = data.to_json.force_encoding(Encoding::BINARY)
|
202
|
+
regex = /[\xc0-\xdf][\x80-\xbf]
|
203
|
+
|[\xe0-\xef][\x80-\xbf]{2}
|
204
|
+
|[\xf0-\xf7][\x80-\xbf]{3}/nx
|
205
|
+
return raw_json.gsub(regex) { |ch|
|
206
|
+
ch.unpack('U*').pack('n*').unpack('H*')[0].gsub(/.+/, %q(\\\\u\&))
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
198
210
|
# Adds an attribute to the check result if present.
|
199
211
|
private
|
200
212
|
def add_attribute_if_present(check_result, name, value)
|
@@ -674,5 +674,23 @@ class SensuOutputTest < Test::Unit::TestCase
|
|
674
674
|
end
|
675
675
|
|
676
676
|
# }}}1
|
677
|
+
# JSON serialization {{{1
|
678
|
+
|
679
|
+
# ASCII characters are serialized literally.
|
680
|
+
def test_serialize_ascii_data_to_json
|
681
|
+
data = {"foo" => "FOO"}
|
682
|
+
driver = create_driver('')
|
683
|
+
assert_equal('{"foo":"FOO"}', driver.instance.to_json(data))
|
684
|
+
end
|
685
|
+
|
686
|
+
# Non-ASCII characters are Unicode-escaped.
|
687
|
+
def test_serialize_non_ascii_data_to_json
|
688
|
+
data = {"foo" => "\u3042\u4e9c\u03b1"}
|
689
|
+
driver = create_driver('')
|
690
|
+
assert_equal(%q({"foo":"\u3042\u4e9c\u03b1"}), driver.instance.to_json(data))
|
691
|
+
end
|
692
|
+
|
693
|
+
# }}}1
|
694
|
+
|
677
695
|
|
678
696
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -84,6 +84,7 @@ extra_rdoc_files: []
|
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
86
|
- .travis.yml
|
87
|
+
- CHANGELOG.md
|
87
88
|
- Gemfile
|
88
89
|
- LICENSE.txt
|
89
90
|
- README.md
|
@@ -107,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
segments:
|
109
110
|
- 0
|
110
|
-
hash:
|
111
|
+
hash: 2209701766942156983
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
none: false
|
113
114
|
requirements:
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
segments:
|
118
119
|
- 0
|
119
|
-
hash:
|
120
|
+
hash: 2209701766942156983
|
120
121
|
requirements: []
|
121
122
|
rubyforge_project:
|
122
123
|
rubygems_version: 1.8.23
|