Skip to content

Commit 078aa89

Browse files
author
Thomas Andrejak
committed
Add support for logstash codecs
1 parent 2cca9dc commit 078aa89

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.2.5
2+
- Add support for logstash codecs
3+
14
## 5.2.4
25
- Relax dependency on http_client mixin since current major works on both
36

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Contributors:
99
* Kurt Hurtado (kurtado)
1010
* Pier-Hugues Pellerin (ph)
1111
* Richard Pijnenburg (electrical)
12+
* Thomas Andrejak (ToToL)
1213

1314
Note: If you've sent us patches, bug reports, or otherwise contributed to
1415
Logstash, and you aren't on the list above and want to be, please let us know

docs/index.asciidoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Consider this when tuning this plugin for performance.
2929
Additionally, note that when parallel execution is used strict ordering of events is not
3030
guaranteed!
3131

32-
Beware, this gem does not yet support codecs. Please use the 'format' option for now.
32+
Beware, to use codecs, please use the 'format' option for now.
3333

3434
[id="plugins-{type}s-{plugin}-options"]
3535
==== Http Output Configuration Options
@@ -47,7 +47,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
4747
| <<plugins-{type}s-{plugin}-content_type>> |<<string,string>>|No
4848
| <<plugins-{type}s-{plugin}-cookies>> |<<boolean,boolean>>|No
4949
| <<plugins-{type}s-{plugin}-follow_redirects>> |<<boolean,boolean>>|No
50-
| <<plugins-{type}s-{plugin}-format>> |<<string,string>>, one of `["json", "json_batch", "form", "message"]`|No
50+
| <<plugins-{type}s-{plugin}-format>> |<<string,string>>, one of `["json", "json_batch", "form", "message", "codec"]`|No
5151
| <<plugins-{type}s-{plugin}-headers>> |<<hash,hash>>|No
5252
| <<plugins-{type}s-{plugin}-http_compression>> |<<boolean,boolean>>|No
5353
| <<plugins-{type}s-{plugin}-http_method>> |<<string,string>>, one of `["put", "post", "patch", "delete", "get", "head"]`|Yes
@@ -136,6 +136,7 @@ If not specified, this defaults to the following:
136136
* if format is "json", "application/json"
137137
* if format is "json_batch", "application/json". Each Logstash batch of events will be concatenated into a single array and sent in one request.
138138
* if format is "form", "application/x-www-form-urlencoded"
139+
* if format is "codec", "text/xml"
139140

140141
[id="plugins-{type}s-{plugin}-cookies"]
141142
===== `cookies`
@@ -157,7 +158,7 @@ Should redirects be followed? Defaults to `true`
157158
[id="plugins-{type}s-{plugin}-format"]
158159
===== `format`
159160

160-
* Value can be any of: `json`, `json_batch`, `form`, `message`
161+
* Value can be any of: `json`, `json_batch`, `form`, `message`, `codec`
161162
* Default value is `"json"`
162163

163164
Set the format of the http body.
@@ -171,6 +172,8 @@ into a query parameter string, e.g. `foo=bar&baz=fizz...`
171172

172173
If message, then the body will be the result of formatting the event according to message
173174

175+
If codec, then the body will be the result of executing the specified codec
176+
174177
Otherwise, the event is sent as json.
175178

176179
[id="plugins-{type}s-{plugin}-headers"]

lib/logstash/outputs/http.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ class LogStash::Outputs::Http < LogStash::Outputs::Base
8181
# If message, then the body will be the result of formatting the event according to message
8282
#
8383
# Otherwise, the event is sent as json.
84-
config :format, :validate => ["json", "json_batch", "form", "message"], :default => "json"
84+
config :format, :validate => ["json", "json_batch", "form", "message", "codec"], :default => "json"
8585

8686
# Set this to true if you want to enable gzip compression for your http requests
8787
config :http_compression, :validate => :boolean, :default => false
8888

8989
config :message, :validate => :string
9090

91+
default :codec, :validate => :string, :default => "json"
92+
9193
def register
94+
@codec.on_event do |event, payload|
95+
payload
96+
end
97+
9298
@http_method = @http_method.to_sym
9399

94100
# We count outstanding requests with this queue
@@ -106,6 +112,7 @@ def register
106112
when "json" ; @content_type = "application/json"
107113
when "json_batch" ; @content_type = "application/json"
108114
when "message" ; @content_type = "text/plain"
115+
when "codec" ; @content_type = "text/plain"
109116
end
110117
end
111118

@@ -298,11 +305,12 @@ def log_failure(message, opts)
298305

299306
# Format the HTTP body
300307
def event_body(event)
301-
# TODO: Create an HTTP post data codec, use that here
302308
if @format == "json"
303309
LogStash::Json.dump(map_event(event))
304310
elsif @format == "message"
305311
event.sprintf(@message)
312+
elsif @format == "codec"
313+
@codec.encode(event)
306314
elsif @format == "json_batch"
307315
LogStash::Json.dump(event.map {|e| map_event(e) })
308316
else

logstash-output-http.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-http'
3-
s.version = '5.2.4'
3+
s.version = '5.2.5'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Sends events to a generic HTTP or HTTPS endpoint"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

0 commit comments

Comments
 (0)