Skip to content

Commit c642afc

Browse files
DEV-118714:Adding support to include/exclude metadata using flag
1 parent 2ee5edf commit c642afc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ output {
3333
| keep_timestamp | If false, LM Logs will use the ingestion timestamp as the event timestamp | true |
3434
| timestamp_is_key | If true, LM Logs will use a specified key as the event timestamp | false |
3535
| timestamp_key | If timestamp_is_key is set, LM Logs will use this key in the event as the timestamp | "logtimestamp" |
36+
| include_metadata | If false, the metadata fields will not be sent to LM Logs | true |
3637

3738
See the [source code](lib/logstash/outputs/lmlogs.rb) for the full list of options
3839

lib/logstash/outputs/lmlogs.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,13 @@ class InvalidHTTPConfigError < StandardError; end
9393
# Username to use for HTTP auth.
9494
config :access_id, :validate => :string, :required => true
9595

96+
config :include_metadata, :validate => :boolean, :default => true
97+
9698
# Password to use for HTTP auth
9799
config :access_key, :validate => :password, :required => true
98100

101+
config :exclude_metadata, :validate => :array, :default => []
102+
99103
@@MAX_PAYLOAD_SIZE = 8*1024*1024
100104

101105
# For developer debugging.
@@ -258,12 +262,15 @@ def multi_receive(events)
258262
documents = []
259263
chunk.each do |event|
260264
event_json = JSON.parse(event.to_json)
261-
lmlogs_event = event_json
262-
lmlogs_event.delete("@timestamp") # remove redundant timestamp field
263-
lmlogs_event["event"].delete("original") # remove redundant log field
265+
lmlogs_event = {}
264266

265-
lmlogs_event["message"] = event.get(@message_key).to_s
267+
if @include_metadata
268+
lmlogs_event = event_json
269+
lmlogs_event.delete("@timestamp") # remove redundant timestamp field
270+
lmlogs_event["event"].delete("original") # remove redundant log field
271+
end
266272

273+
lmlogs_event["message"] = event.get(@message_key).to_s
267274
lmlogs_event["_lm.resourceId"] = {}
268275
lmlogs_event["_lm.resourceId"]["#{@lm_property}"] = event.get(@property_key.to_s)
269276

logstash-output-lmlogs.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-lmlogs'
3-
s.version = '1.1.0'
3+
s.version = '1.2.0'
44
s.licenses = ['Apache-2.0']
55
s.summary = "Logstash output plugin for LM Logs"
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)