fluent-plugin-lm-logs 1.0.1 → 1.0.4
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 +4 -4
- data/README.md +7 -2
- data/Rakefile +6 -0
- data/fluent-plugin-lm-logs.gemspec +1 -1
- data/lib/fluent/plugin/out_lm.rb +68 -17
- 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: 74ceac6a53b86efe8123cd6ec143d4839de6043815ebb10e763e2b3019122396
|
|
4
|
+
data.tar.gz: f72441fc5646c2cdc6f602f066fca505e1bb713371a90bdbf019ea6cf07c80b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee9e805c8fe449abca81d6fdfff713130359c7b3cb5c246a48fc37e8f6a6a93ab25c2203c1aa5ecfb441ca0a3e7223373ebad31b2a5314660eba5ab5bb31ed0c
|
|
7
|
+
data.tar.gz: a910b4872388fade3cf044e7f2c9e2562a23d5730a2faffc4f4daa9f942220a44c02fa3daead5e078e662eaddb8ecb27c034f3bb190324267b0b4a04e953cd87
|
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
|
|
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
data/lib/fluent/plugin/out_lm.rb
CHANGED
|
@@ -15,6 +15,10 @@ module Fluent
|
|
|
15
15
|
class LmOutput < BufferedOutput
|
|
16
16
|
Fluent::Plugin.register_output('lm', self)
|
|
17
17
|
|
|
18
|
+
RESOURCE_MAPPING_KEY = "_lm.resourceId".freeze
|
|
19
|
+
DEVICELESS_KEY_SERVICE = "resource.service.name".freeze
|
|
20
|
+
DEVICELESS_KEY_NAMESPACE = "resource.service.namespace".freeze
|
|
21
|
+
|
|
18
22
|
# config_param defines a parameter. You can refer a parameter via @path instance variable
|
|
19
23
|
|
|
20
24
|
config_param :access_id, :string, :default => "access_id"
|
|
@@ -26,6 +30,8 @@ module Fluent
|
|
|
26
30
|
config_param :resource_mapping, :hash, :default => {"host": "system.hostname", "hostname": "system.hostname"}
|
|
27
31
|
|
|
28
32
|
config_param :debug, :bool, :default => false
|
|
33
|
+
|
|
34
|
+
config_param :include_metadata, :bool, :default => false
|
|
29
35
|
|
|
30
36
|
config_param :force_encoding, :string, :default => ""
|
|
31
37
|
|
|
@@ -34,7 +40,9 @@ module Fluent
|
|
|
34
40
|
config_param :log_source, :string, :default => "lm-logs-fluentd"
|
|
35
41
|
|
|
36
42
|
config_param :version_id, :string, :default => "version_id"
|
|
37
|
-
|
|
43
|
+
|
|
44
|
+
config_param :device_less_logs, :bool, :default => false
|
|
45
|
+
|
|
38
46
|
# This method is called before starting.
|
|
39
47
|
# 'conf' is a Hash that includes configuration parameters.
|
|
40
48
|
# If the configuration is invalid, raise Fluent::ConfigError.
|
|
@@ -71,7 +79,9 @@ module Fluent
|
|
|
71
79
|
events = []
|
|
72
80
|
chunk.msgpack_each do |(tag, time, record)|
|
|
73
81
|
event = process_record(tag,time,record)
|
|
74
|
-
|
|
82
|
+
if event != nil
|
|
83
|
+
events.push(event)
|
|
84
|
+
end
|
|
75
85
|
end
|
|
76
86
|
send_batch(events)
|
|
77
87
|
end
|
|
@@ -79,24 +89,37 @@ module Fluent
|
|
|
79
89
|
def process_record(tag, time, record)
|
|
80
90
|
resource_map = {}
|
|
81
91
|
lm_event = {}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
lm_event["message"] = lm_event["message"].force_encoding(@force_encoding).encode("UTF-8")
|
|
92
|
+
|
|
93
|
+
if @include_metadata
|
|
94
|
+
lm_event = get_metadata(record)
|
|
86
95
|
end
|
|
87
96
|
|
|
88
|
-
if
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
if !@device_less_logs
|
|
98
|
+
# With devices
|
|
99
|
+
if record[RESOURCE_MAPPING_KEY] == nil
|
|
100
|
+
@resource_mapping.each do |key, value|
|
|
101
|
+
k = value
|
|
102
|
+
nestedVal = record
|
|
103
|
+
key.to_s.split('.').each { |x| nestedVal = nestedVal[x] }
|
|
104
|
+
if nestedVal != nil
|
|
105
|
+
resource_map[k] = nestedVal
|
|
106
|
+
end
|
|
95
107
|
end
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
lm_event[RESOURCE_MAPPING_KEY] = resource_map
|
|
109
|
+
else
|
|
110
|
+
lm_event[RESOURCE_MAPPING_KEY] = record[RESOURCE_MAPPING_KEY]
|
|
111
|
+
end
|
|
98
112
|
else
|
|
99
|
-
|
|
113
|
+
# Device less
|
|
114
|
+
if record[DEVICELESS_KEY_SERVICE]==nil
|
|
115
|
+
log.error "When device_less_logs is set \'true\', record must have \'service\'. Ignoring this event #{lm_event}."
|
|
116
|
+
return nil
|
|
117
|
+
else
|
|
118
|
+
lm_event[DEVICELESS_KEY_SERVICE] = encode_if_necessary(record[DEVICELESS_KEY_SERVICE])
|
|
119
|
+
if record[DEVICELESS_KEY_NAMESPACE]!=nil
|
|
120
|
+
lm_event[DEVICELESS_KEY_NAMESPACE] = encode_if_necessary(record[DEVICELESS_KEY_NAMESPACE])
|
|
121
|
+
end
|
|
122
|
+
end
|
|
100
123
|
end
|
|
101
124
|
|
|
102
125
|
if record["timestamp"] != nil
|
|
@@ -105,9 +128,37 @@ module Fluent
|
|
|
105
128
|
lm_event["timestamp"] = Time.at(time).utc.to_datetime.rfc3339
|
|
106
129
|
end
|
|
107
130
|
|
|
131
|
+
lm_event["message"] = encode_if_necessary(record["message"])
|
|
132
|
+
|
|
108
133
|
return lm_event
|
|
109
134
|
end
|
|
110
135
|
|
|
136
|
+
def get_metadata(record)
|
|
137
|
+
#if encoding is not defined we will skip going through each key val
|
|
138
|
+
#and return the whole record for performance reasons in case of a bulky record.
|
|
139
|
+
if @force_encoding == ""
|
|
140
|
+
return record
|
|
141
|
+
else
|
|
142
|
+
lm_event = {}
|
|
143
|
+
record.each do |key, value|
|
|
144
|
+
lm_event["#{key}"] = get_encoded_string(value)
|
|
145
|
+
end
|
|
146
|
+
return lm_event
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def encode_if_necessary(str)
|
|
151
|
+
if @force_encoding != ""
|
|
152
|
+
return get_encoded_string(str)
|
|
153
|
+
else
|
|
154
|
+
return str
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def get_encoded_string(str)
|
|
159
|
+
return str.force_encoding(@force_encoding).encode("UTF-8")
|
|
160
|
+
end
|
|
161
|
+
|
|
111
162
|
def send_batch(events)
|
|
112
163
|
url = "https://#{@company_name}.logicmonitor.com/rest/log/ingest"
|
|
113
164
|
body = events.to_json
|
|
@@ -159,4 +210,4 @@ module Fluent
|
|
|
159
210
|
"LMv1 #{@access_id}:#{signature}:#{timestamp}"
|
|
160
211
|
end
|
|
161
212
|
end
|
|
162
|
-
end
|
|
213
|
+
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.
|
|
4
|
+
version: 1.0.4
|
|
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-05-16 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
|