fluent-plugin-lm-logs 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a22de1423e4cac56363b99b31828c5add123ac4f843d4aeae4112aab02c4b6b4
4
- data.tar.gz: e35849d3c43ef4f83fdeecae137b2d4e38f5c69ec52a7bf147191ac46773e61c
3
+ metadata.gz: fbacc1e0e4eb5389c11d4b23c28eda6100919da6d7de0abbda9edf13dffbf682
4
+ data.tar.gz: 3bffdba784febf493f69ba0be9c1745f53d7aebb8f66ef92bf23b252fb91d2bb
5
5
  SHA512:
6
- metadata.gz: f34bab74bbf201ca0af3ff2de35307560f5bb79a37b9ea549b5627f421c7214ea2a5ab7304efe6ddc54f774af161fa594aed8a6c4ce75b9dfb38f2eb2a852788
7
- data.tar.gz: 14341d2be42d2d7530cc964178f514a530adb3c8d3679ff60ab6cdef653f83eaf38f70b68bb1578a7393f7bd6172c63f9185623eb7acf450f4db343ca2f0abfb
6
+ metadata.gz: 34362b69e402d439ee415089540a5f3d1532bb5f44c997bca79437e57a64286579b3e9c8349ebb44095bf86e976e2b197ddd9f7f20a32600e2c164685310b62e
7
+ data.tar.gz: '0631937f8f545e675735e207d6e6137748ef0bc1445cdab27c1b0179f0513daa271fbee4bcbe9000aa8fea1df155e5f208f82fdb6002a6e58f133f09c2616e57'
data/README.md CHANGED
@@ -6,8 +6,8 @@ This output plugin sends Fluentd records to the configured LogicMonitor account.
6
6
  ## Prerequisites
7
7
 
8
8
  Install the plugin:
9
- * With gem: `gem install fluent-plugin-lm-logs`
10
- * For deb packages: `td-agent-gem install fluent-plugin-lm-logs`
9
+ * With gem (if td-agent/fluentd is installed along with native ruby): `gem install fluent-plugin-lm-logs`
10
+ * For native td-agent/fluentd plugin handling: `td-agent-gem install fluent-plugin-lm-logs`
11
11
 
12
12
  Alternatively, you can add `out_lm.rb` to your Fluentd plugins directory.
13
13
 
@@ -69,3 +69,8 @@ See the [LogicMonitor Helm repository](https://github.com/logicmonitor/k8s-helm-
69
69
  | `flush_interval` | Defines the time in seconds to wait before sending batches of logs to LogicMonitor. Default is `60s`. |
70
70
  | `debug` | When `true`, logs more information to the fluentd console. |
71
71
  | `force_encoding` | Specify charset when logs contains invalid utf-8 characters. |
72
+ | `include_metadata` | When `true`, appends additional metadata to the log. default `false`. |
73
+ | `device_less_logs` | When `true`, do not map log with any resource. record must have `service` when `true`. default `false`. |
74
+
75
+
76
+
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ task default: "test"
4
+
5
+ Rake::TestTask.new do |task|
6
+ task.pattern = "test/plugin/*.rb"
7
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fluent-plugin-lm-logs"
8
- spec.version = '1.0.0'
8
+ spec.version = '1.0.3'
9
9
  spec.authors = ["LogicMonitor"]
10
10
  spec.email = "rubygems@logicmonitor.com"
11
11
  spec.summary = "LogicMonitor logs fluentd output plugin"
@@ -26,6 +26,8 @@ module Fluent
26
26
  config_param :resource_mapping, :hash, :default => {"host": "system.hostname", "hostname": "system.hostname"}
27
27
 
28
28
  config_param :debug, :bool, :default => false
29
+
30
+ config_param :include_metadata, :bool, :default => false
29
31
 
30
32
  config_param :force_encoding, :string, :default => ""
31
33
 
@@ -34,7 +36,9 @@ module Fluent
34
36
  config_param :log_source, :string, :default => "lm-logs-fluentd"
35
37
 
36
38
  config_param :version_id, :string, :default => "version_id"
37
-
39
+
40
+ config_param :device_less_logs, :bool, :default => false
41
+
38
42
  # This method is called before starting.
39
43
  # 'conf' is a Hash that includes configuration parameters.
40
44
  # If the configuration is invalid, raise Fluent::ConfigError.
@@ -71,7 +75,9 @@ module Fluent
71
75
  events = []
72
76
  chunk.msgpack_each do |(tag, time, record)|
73
77
  event = process_record(tag,time,record)
74
- events.push(event)
78
+ if event != nil
79
+ events.push(event)
80
+ end
75
81
  end
76
82
  send_batch(events)
77
83
  end
@@ -79,24 +85,32 @@ module Fluent
79
85
  def process_record(tag, time, record)
80
86
  resource_map = {}
81
87
  lm_event = {}
82
- lm_event["message"] = record["message"]
83
-
84
- if @force_encoding != ""
85
- lm_event["message"] = lm_event["message"].force_encoding(@force_encoding).encode("UTF-8")
88
+
89
+ if @include_metadata
90
+ lm_event = get_metadata(record)
86
91
  end
87
92
 
88
- if record["_lm.resourceId"] == nil
89
- @resource_mapping.each do |key, value|
90
- k = value
91
- nestedVal = record
92
- key.to_s.split('.').each { |x| nestedVal = nestedVal[x] }
93
- if nestedVal != nil
94
- resource_map[k] = nestedVal
93
+ if !@device_less_logs
94
+ if record["_lm.resourceId"] == nil
95
+ @resource_mapping.each do |key, value|
96
+ k = value
97
+ nestedVal = record
98
+ key.to_s.split('.').each { |x| nestedVal = nestedVal[x] }
99
+ if nestedVal != nil
100
+ resource_map[k] = nestedVal
101
+ end
95
102
  end
96
- end
97
- lm_event["_lm.resourceId"] = resource_map
103
+ lm_event["_lm.resourceId"] = resource_map
104
+ else
105
+ lm_event["_lm.resourceId"] = record["_lm.resourceId"]
106
+ end
98
107
  else
99
- lm_event["_lm.resourceId"] = record["_lm.resourceId"]
108
+ if record["service"]==nil
109
+ log.error "When device_less_logs is set \'true\', record must have \'service\'. Ignoring this event #{lm_event}."
110
+ return nil
111
+ else
112
+ lm_event["service"] = encode_if_necessary(record["service"])
113
+ end
100
114
  end
101
115
 
102
116
  if record["timestamp"] != nil
@@ -105,9 +119,37 @@ module Fluent
105
119
  lm_event["timestamp"] = Time.at(time).utc.to_datetime.rfc3339
106
120
  end
107
121
 
122
+ lm_event["message"] = encode_if_necessary(record["message"])
123
+
108
124
  return lm_event
109
125
  end
110
126
 
127
+ def get_metadata(record)
128
+ #if encoding is not defined we will skip going through each key val
129
+ #and return the whole record for performance reasons in case of a bulky record.
130
+ if @force_encoding == ""
131
+ return record
132
+ else
133
+ lm_event = {}
134
+ record.each do |key, value|
135
+ lm_event["#{key}"] = get_encoded_string(value)
136
+ end
137
+ return lm_event
138
+ end
139
+ end
140
+
141
+ def encode_if_necessary(str)
142
+ if @force_encoding != ""
143
+ return get_encoded_string(str)
144
+ else
145
+ return str
146
+ end
147
+ end
148
+
149
+ def get_encoded_string(str)
150
+ return str.force_encoding(@force_encoding).encode("UTF-8")
151
+ end
152
+
111
153
  def send_batch(events)
112
154
  url = "https://#{@company_name}.logicmonitor.com/rest/log/ingest"
113
155
  body = events.to_json
@@ -124,7 +166,7 @@ module Fluent
124
166
  request = Net::HTTP::Post.new(uri.request_uri)
125
167
  request['authorization'] = generate_token(events)
126
168
  request['Content-type'] = "application/json"
127
- request['User-Agent'] = log_source+version_id
169
+ request['User-Agent'] = log_source + "/" + version_id
128
170
 
129
171
  if @compression == "gzip"
130
172
  request['Content-Encoding'] = "gzip"
@@ -135,6 +177,11 @@ module Fluent
135
177
  request.body = body
136
178
  end
137
179
 
180
+ if @debug
181
+ log.info "Sending the below request headers to logicmonitor:"
182
+ request.each_header {|key,value| log.info "#{key} = #{value}" }
183
+ end
184
+
138
185
  resp = http.request(request)
139
186
  if @debug || (!resp.kind_of? Net::HTTPSuccess)
140
187
  log.info "Status code:#{resp.code} Request Id:#{resp.header['x-request-id']}"
@@ -154,4 +201,4 @@ module Fluent
154
201
  "LMv1 #{@access_id}:#{signature}:#{timestamp}"
155
202
  end
156
203
  end
157
- end
204
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-lm-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - LogicMonitor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 3.2.3
68
+ rubygems_version: 3.3.7
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: LogicMonitor logs fluentd output plugin