fluent-plugin-lm-logs 0.0.12 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/Rakefile +6 -0
- data/fluent-plugin-lm-logs.gemspec +1 -1
- data/lib/fluent/plugin/out_lm.rb +61 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c2298de6fe81e9eb49052ee49d55180193d254fee912339b9c8f6fad6c7aea1
|
4
|
+
data.tar.gz: 0a64fdb982ca4d8768175db534198b942d96fdcb22519913c5c077b7201bb6ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95fe45b670b97925e672ecad76a724ed9eef24fd1e1685a131a4375ac7e662161aa5612ec34f3fc99e0f5817b24e7d640481b457bd466f2d2b3455f8e004e394
|
7
|
+
data.tar.gz: c69f47a5aad81cb1fbf778f14bc3238ee0271cb9530516a31120e46829aa7cf28336d509f9d6be2ddb155794ec9926896b2fc9738f524a30cf222f31013e322c
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-lm-logs.svg)](http://badge.fury.io/rb/fluent-plugin-lm-logs)
|
3
|
-
# lm-logs-fluentd
|
3
|
+
# lm-logs-fluentd
|
4
4
|
This output plugin sends Fluentd records to the configured LogicMonitor account.
|
5
5
|
|
6
6
|
## Prerequisites
|
7
7
|
|
8
8
|
Install the plugin:
|
9
|
-
* With gem: `gem install fluent-plugin-lm-logs`
|
10
|
-
* For
|
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
|
|
@@ -68,4 +68,9 @@ See the [LogicMonitor Helm repository](https://github.com/logicmonitor/k8s-helm-
|
|
68
68
|
| `access_key` | LM API Token access key. |
|
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
|
-
| `force_encoding` | Specify charset when logs contains invalid utf-8 characters. |
|
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` and `namespace` when `true`. default `false`. |
|
74
|
+
| `metadata_to_exclude` | `String array` of keys of metadata to exclude. default `empty` |
|
75
|
+
|
76
|
+
|
data/Rakefile
CHANGED
data/lib/fluent/plugin/out_lm.rb
CHANGED
@@ -26,11 +26,21 @@ 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
|
|
32
34
|
config_param :compression, :string, :default => ""
|
33
35
|
|
36
|
+
config_param :log_source, :string, :default => "lm-logs-fluentd"
|
37
|
+
|
38
|
+
config_param :version_id, :string, :default => "version_id"
|
39
|
+
|
40
|
+
config_param :device_less_logs, :bool, :default => false
|
41
|
+
|
42
|
+
config_param :metadata_to_exclude, :array, default: [], value_type: :string
|
43
|
+
|
34
44
|
# This method is called before starting.
|
35
45
|
# 'conf' is a Hash that includes configuration parameters.
|
36
46
|
# If the configuration is invalid, raise Fluent::ConfigError.
|
@@ -67,7 +77,9 @@ module Fluent
|
|
67
77
|
events = []
|
68
78
|
chunk.msgpack_each do |(tag, time, record)|
|
69
79
|
event = process_record(tag,time,record)
|
70
|
-
|
80
|
+
if event != nil
|
81
|
+
events.push(event)
|
82
|
+
end
|
71
83
|
end
|
72
84
|
send_batch(events)
|
73
85
|
end
|
@@ -75,24 +87,20 @@ module Fluent
|
|
75
87
|
def process_record(tag, time, record)
|
76
88
|
resource_map = {}
|
77
89
|
lm_event = {}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
nestedVal = record
|
88
|
-
key.to_s.split('.').each { |x| nestedVal = nestedVal[x] }
|
89
|
-
if nestedVal != nil
|
90
|
-
resource_map[k] = nestedVal
|
90
|
+
if !@device_less_logs
|
91
|
+
if record["_lm.resourceId"] == nil
|
92
|
+
@resource_mapping.each do |key, value|
|
93
|
+
k = value
|
94
|
+
nestedVal = record
|
95
|
+
key.to_s.split('.').each { |x| nestedVal = nestedVal[x] }
|
96
|
+
if nestedVal != nil
|
97
|
+
resource_map[k] = nestedVal
|
98
|
+
end
|
91
99
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
100
|
+
lm_event["_lm.resourceId"] = resource_map
|
101
|
+
else
|
102
|
+
lm_event["_lm.resourceId"] = record["_lm.resourceId"]
|
103
|
+
end
|
96
104
|
end
|
97
105
|
|
98
106
|
if record["timestamp"] != nil
|
@@ -101,6 +109,34 @@ module Fluent
|
|
101
109
|
lm_event["timestamp"] = Time.at(time).utc.to_datetime.rfc3339
|
102
110
|
end
|
103
111
|
|
112
|
+
if @include_metadata
|
113
|
+
record.each do |key, value|
|
114
|
+
case key
|
115
|
+
when *@metadata_to_exclude.concat(["timestamp","_lm.resourceId","log","message"])
|
116
|
+
else
|
117
|
+
lm_event["#{key}"] = value
|
118
|
+
|
119
|
+
if @force_encoding != ""
|
120
|
+
lm_event["#{key}"] = lm_event["#{key}"].force_encoding(@force_encoding).encode("UTF-8")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
lm_event["message"] = record["message"]
|
126
|
+
|
127
|
+
if @force_encoding != ""
|
128
|
+
lm_event["message"] = lm_event["message"].force_encoding(@force_encoding).encode("UTF-8")
|
129
|
+
end
|
130
|
+
|
131
|
+
if @device_less_logs
|
132
|
+
if record["service"]==nil || record["namespace"] == nil
|
133
|
+
log.error "When device_less_logs is set \'true\', record must have \'service\' and \'namespace\'. Ignoring this event #{lm_event}."
|
134
|
+
return nil
|
135
|
+
else
|
136
|
+
lm_event["service"] = record["service"]
|
137
|
+
lm_event["namespace"] = record["namespace"]
|
138
|
+
end
|
139
|
+
end
|
104
140
|
return lm_event
|
105
141
|
end
|
106
142
|
|
@@ -120,6 +156,7 @@ module Fluent
|
|
120
156
|
request = Net::HTTP::Post.new(uri.request_uri)
|
121
157
|
request['authorization'] = generate_token(events)
|
122
158
|
request['Content-type'] = "application/json"
|
159
|
+
request['User-Agent'] = log_source + "/" + version_id
|
123
160
|
|
124
161
|
if @compression == "gzip"
|
125
162
|
request['Content-Encoding'] = "gzip"
|
@@ -130,6 +167,11 @@ module Fluent
|
|
130
167
|
request.body = body
|
131
168
|
end
|
132
169
|
|
170
|
+
if @debug
|
171
|
+
log.info "Sending the below request headers to logicmonitor:"
|
172
|
+
request.each_header {|key,value| log.info "#{key} = #{value}" }
|
173
|
+
end
|
174
|
+
|
133
175
|
resp = http.request(request)
|
134
176
|
if @debug || (!resp.kind_of? Net::HTTPSuccess)
|
135
177
|
log.info "Status code:#{resp.code} Request Id:#{resp.header['x-request-id']}"
|
@@ -149,4 +191,4 @@ module Fluent
|
|
149
191
|
"LMv1 #{@access_id}:#{signature}:#{timestamp}"
|
150
192
|
end
|
151
193
|
end
|
152
|
-
end
|
194
|
+
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:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LogicMonitor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-02 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.
|
68
|
+
rubygems_version: 3.3.7
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: LogicMonitor logs fluentd output plugin
|