fluent-plugin-amqp 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fluent/plugin/out_amqp.rb +89 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 768712aa2801509d6676bd5afbed81f5871296b4
|
4
|
+
data.tar.gz: f0020715d5163ed87e160f2cd13f54e2ff2e549f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4686083f14b7481987362864ddc535733b7c827d3839d91ecf08726afd24ff571bee3a9e8259db28f068cfa17698a4e9e85b9cdb7f4ef55442df60c83b327eca
|
7
|
+
data.tar.gz: 0ed03675cdb45f9c6d4723cb3135decf2577d3d06e8bfe30a9ba9ad0a2f6f01c6e8bbe094e6917c6356a5a4986cd78d6075b677b9f38fdf6cd6a5a5bd76726f1
|
@@ -44,15 +44,66 @@ module Fluent::Plugin
|
|
44
44
|
config_param :tls_key, :string, default: nil
|
45
45
|
config_param :tls_ca_certificates, :array, default: nil
|
46
46
|
config_param :tls_verify_peer, :bool, default: true
|
47
|
+
config_param :content_type, :string, default: "application/octet"
|
48
|
+
config_param :content_encoding, :string, default: nil
|
49
|
+
|
50
|
+
config_section :header do
|
51
|
+
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
52
|
+
end
|
47
53
|
|
48
54
|
config_section :buffer do
|
49
55
|
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
50
56
|
end
|
51
57
|
|
58
|
+
|
59
|
+
class HeaderElement
|
60
|
+
include Fluent::Configurable
|
61
|
+
|
62
|
+
config_param :name, :string
|
63
|
+
config_param :default, :string, default: nil
|
64
|
+
config_param :source, default: nil do |val|
|
65
|
+
if val.start_with?('[')
|
66
|
+
JSON.load(val)
|
67
|
+
else
|
68
|
+
val.split('.')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Extract a header and value from the input data
|
73
|
+
# returning nil if value cannot be derived
|
74
|
+
def getValue(data)
|
75
|
+
val = getNestedValue(data, @source ) if @source
|
76
|
+
val ||= @default if @default
|
77
|
+
val
|
78
|
+
end
|
79
|
+
|
80
|
+
def getNestedValue(data, path)
|
81
|
+
temp_data = data
|
82
|
+
temp_path = path.dup
|
83
|
+
until temp_data.nil? or temp_path.empty?
|
84
|
+
temp_data = temp_data[temp_path.shift]
|
85
|
+
end
|
86
|
+
temp_data
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
52
90
|
def configure(conf)
|
53
91
|
compat_parameters_convert(conf, :buffer)
|
54
92
|
super
|
55
93
|
@conf = conf
|
94
|
+
|
95
|
+
# Extract the header configuration into a collection
|
96
|
+
@headers = conf.elements.select {|e|
|
97
|
+
e.name == 'header'
|
98
|
+
}.map {|e|
|
99
|
+
he = HeaderElement.new
|
100
|
+
he.configure(e)
|
101
|
+
unless he.source || he.default
|
102
|
+
raise Fluent::ConfigError, "At least 'default' or 'source' must must be defined in a header configuration section."
|
103
|
+
end
|
104
|
+
he
|
105
|
+
}
|
106
|
+
|
56
107
|
unless @host || @hosts
|
57
108
|
raise Fluent::ConfigError, "'host' or 'hosts' must be specified."
|
58
109
|
end
|
@@ -98,13 +149,27 @@ module Fluent::Plugin
|
|
98
149
|
begin
|
99
150
|
chunk.msgpack_each do |(tag, time, data)|
|
100
151
|
begin
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
152
|
+
msg_headers = headers(tag,time,data)
|
153
|
+
|
154
|
+
begin
|
155
|
+
data = JSON.dump( data ) unless data.is_a?( String )
|
156
|
+
rescue JSON::GeneratorError => e
|
157
|
+
log.warn "Failure converting data object to json string: #{e.message} - sending as raw object"
|
158
|
+
# Debug only - otherwise we may pollute the fluent logs with unparseable events and loop
|
159
|
+
log.debug "JSON.dump failure converting [#{data}]"
|
160
|
+
end
|
161
|
+
|
162
|
+
log.debug "Sending message #{data}, :key => #{routing_key( tag)} :headers => #{headers(tag,time,data)}"
|
163
|
+
@exch.publish(
|
164
|
+
data,
|
165
|
+
key: routing_key( tag ),
|
166
|
+
persistent: @persistent,
|
167
|
+
headers: msg_headers,
|
168
|
+
content_type: @content_type,
|
169
|
+
content_encoding: @content_encoding)
|
170
|
+
|
171
|
+
# :nocov:
|
172
|
+
# Hard to throw StandardError through test code
|
108
173
|
rescue StandardError => e
|
109
174
|
# This protects against invalid byteranges and other errors at a per-message level
|
110
175
|
log.error "Unexpected error during message publishing: #{e.message}"
|
@@ -119,6 +184,7 @@ module Fluent::Plugin
|
|
119
184
|
# Just in case theres any other errors during chunk loading.
|
120
185
|
log.error "Unexpected error during message publishing: #{e.message}"
|
121
186
|
end
|
187
|
+
# :nocov:
|
122
188
|
end
|
123
189
|
|
124
190
|
|
@@ -130,15 +196,25 @@ module Fluent::Plugin
|
|
130
196
|
end
|
131
197
|
end
|
132
198
|
|
133
|
-
def headers( tag, time )
|
134
|
-
{}
|
135
|
-
|
136
|
-
|
137
|
-
|
199
|
+
def headers( tag, time, data )
|
200
|
+
h = {}
|
201
|
+
|
202
|
+
log.debug "Processing Headers: #{@headers}"
|
203
|
+
# A little messy this...
|
204
|
+
# Trying to allow for header overrides where a header defined
|
205
|
+
# earlier will be used if a later header is returning nil (ie not found and no default)
|
206
|
+
h = Hash[ @headers
|
207
|
+
.collect{|v| [v.name, v.getValue(data) ]}
|
208
|
+
.delete_if{|x| x.last.nil?}
|
209
|
+
]
|
210
|
+
|
211
|
+
h[@tag_header] = tag if @tag_header
|
212
|
+
h[@time_header] = Time.at(time).utc.to_s if @time_header
|
213
|
+
|
214
|
+
h
|
138
215
|
end
|
139
216
|
|
140
217
|
|
141
|
-
private
|
142
218
|
def check_tls_configuration()
|
143
219
|
if @tls
|
144
220
|
unless @tls_key && @tls_cert
|
@@ -161,6 +237,5 @@ module Fluent::Plugin
|
|
161
237
|
opts[:tls_ca_certificates] = @tls_ca_certificates if @tls_ca_certificates
|
162
238
|
return opts
|
163
239
|
end
|
164
|
-
|
165
240
|
end
|
166
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiromi Ishii
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fluentd
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.6.10
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: AMQP input/output plugin or fluentd
|