fluent-plugin-lm-logs 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbacc1e0e4eb5389c11d4b23c28eda6100919da6d7de0abbda9edf13dffbf682
4
- data.tar.gz: 3bffdba784febf493f69ba0be9c1745f53d7aebb8f66ef92bf23b252fb91d2bb
3
+ metadata.gz: d615e41f382455dbcae73e2449a311c57bf2a9acc24e55d27127737e162a9469
4
+ data.tar.gz: e789739f1b6407674a89cb0fe6f54a91c5fdd6936158952113b53d5bf0f0a6fd
5
5
  SHA512:
6
- metadata.gz: 34362b69e402d439ee415089540a5f3d1532bb5f44c997bca79437e57a64286579b3e9c8349ebb44095bf86e976e2b197ddd9f7f20a32600e2c164685310b62e
7
- data.tar.gz: '0631937f8f545e675735e207d6e6137748ef0bc1445cdab27c1b0179f0513daa271fbee4bcbe9000aa8fea1df155e5f208f82fdb6002a6e58f133f09c2616e57'
6
+ metadata.gz: c99d630c5cf20b75afd1759ca6628dbe833e3cd3ff2d98c481651295f4dc8bae538e72dbf7f35acddcf23643385fc76e3463df35c9adb39494e2140987568733
7
+ data.tar.gz: 74d559060251b796f8ed252eab5a3df58daddf9f0cc467cefc266ff4f7b4f2944026390292b938eb8248c9cb07bd3f4abc0a039ba6c40dafb77109ad4a3fd9c1
@@ -2,10 +2,15 @@
2
2
  # under the Apache License Version 2.0.
3
3
  # This product includes software developed at LogicMonitor (https://www.logicmonitor.com).
4
4
  # Copyright 2020 LogicMonitor, Inc.
5
+ lib = File.expand_path('../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ require "fluent/plugin/version.rb"
9
+
5
10
 
6
11
  Gem::Specification.new do |spec|
7
12
  spec.name = "fluent-plugin-lm-logs"
8
- spec.version = '1.0.3'
13
+ spec.version = LmLogsFluentPlugin::VERSION
9
14
  spec.authors = ["LogicMonitor"]
10
15
  spec.email = "rubygems@logicmonitor.com"
11
16
  spec.summary = "LogicMonitor logs fluentd output plugin"
@@ -16,9 +21,10 @@ Gem::Specification.new do |spec|
16
21
  spec.metadata["source_code_uri"] = "https://github.com/logicmonitor/lm-logs-fluentd"
17
22
  spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/lm-logs-fluentd"
18
23
 
19
- spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-lm-logs.gemspec", "lib/fluent/plugin/out_lm.rb"]
24
+ spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-lm-logs.gemspec", "lib/fluent/plugin/version.rb", "lib/fluent/plugin/out_lm.rb"]
20
25
  spec.require_paths = ["lib"]
21
26
  spec.required_ruby_version = '>= 2.0.0'
22
27
 
23
28
  spec.add_runtime_dependency "fluentd", [">= 1", "< 2"]
29
+ spec.add_runtime_dependency "net-http-persistent", '~> 4.0.1'
24
30
  end
@@ -7,14 +7,22 @@ require 'json'
7
7
  require 'openssl'
8
8
  require 'base64'
9
9
  require 'net/http'
10
+ require 'net/http/persistent'
10
11
  require 'net/https'
11
12
  require('zlib')
12
13
 
14
+ require_relative "version"
15
+
16
+
13
17
 
14
18
  module Fluent
15
19
  class LmOutput < BufferedOutput
16
20
  Fluent::Plugin.register_output('lm', self)
17
21
 
22
+ RESOURCE_MAPPING_KEY = "_lm.resourceId".freeze
23
+ DEVICELESS_KEY_SERVICE = "resource.service.name".freeze
24
+ DEVICELESS_KEY_NAMESPACE = "resource.service.namespace".freeze
25
+
18
26
  # config_param defines a parameter. You can refer a parameter via @path instance variable
19
27
 
20
28
  config_param :access_id, :string, :default => "access_id"
@@ -50,12 +58,18 @@ module Fluent
50
58
  # Open sockets or files here.
51
59
  def start
52
60
  super
61
+ @http_client = Net::HTTP::Persistent.new name: "fluent-plugin-lm-logs"
62
+ @http_client.override_headers["Content-Type"] = "application/json"
63
+ @http_client.override_headers["User-Agent"] = log_source + "/" + LmLogsFluentPlugin::VERSION
64
+ @url = "https://#{@company_name}.logicmonitor.com/rest/log/ingest"
65
+ @uri = URI.parse(@url)
53
66
  end
54
67
 
55
68
  # This method is called when shutting down.
56
69
  # Shutdown the thread and close sockets or files here.
57
70
  def shutdown
58
71
  super
72
+ @http_client.shutdown
59
73
  end
60
74
 
61
75
  # This method is called when an event reaches to Fluentd.
@@ -91,7 +105,8 @@ module Fluent
91
105
  end
92
106
 
93
107
  if !@device_less_logs
94
- if record["_lm.resourceId"] == nil
108
+ # With devices
109
+ if record[RESOURCE_MAPPING_KEY] == nil
95
110
  @resource_mapping.each do |key, value|
96
111
  k = value
97
112
  nestedVal = record
@@ -100,17 +115,21 @@ module Fluent
100
115
  resource_map[k] = nestedVal
101
116
  end
102
117
  end
103
- lm_event["_lm.resourceId"] = resource_map
118
+ lm_event[RESOURCE_MAPPING_KEY] = resource_map
104
119
  else
105
- lm_event["_lm.resourceId"] = record["_lm.resourceId"]
120
+ lm_event[RESOURCE_MAPPING_KEY] = record[RESOURCE_MAPPING_KEY]
106
121
  end
107
122
  else
108
- if record["service"]==nil
123
+ # Device less
124
+ if record[DEVICELESS_KEY_SERVICE]==nil
109
125
  log.error "When device_less_logs is set \'true\', record must have \'service\'. Ignoring this event #{lm_event}."
110
126
  return nil
111
127
  else
112
- lm_event["service"] = encode_if_necessary(record["service"])
113
- end
128
+ lm_event[DEVICELESS_KEY_SERVICE] = encode_if_necessary(record[DEVICELESS_KEY_SERVICE])
129
+ if record[DEVICELESS_KEY_NAMESPACE]!=nil
130
+ lm_event[DEVICELESS_KEY_NAMESPACE] = encode_if_necessary(record[DEVICELESS_KEY_NAMESPACE])
131
+ end
132
+ end
114
133
  end
115
134
 
116
135
  if record["timestamp"] != nil
@@ -151,22 +170,15 @@ module Fluent
151
170
  end
152
171
 
153
172
  def send_batch(events)
154
- url = "https://#{@company_name}.logicmonitor.com/rest/log/ingest"
155
173
  body = events.to_json
156
- uri = URI.parse(url)
157
174
 
158
175
  if @debug
159
- log.info "Sending #{events.length} events to logic monitor at #{url}"
176
+ log.info "Sending #{events.length} events to logic monitor at #{@url}"
160
177
  log.info "Request json #{body}"
161
178
  end
162
179
 
163
- http = Net::HTTP.new(uri.host, uri.port)
164
- http.use_ssl = true
165
-
166
- request = Net::HTTP::Post.new(uri.request_uri)
180
+ request = Net::HTTP::Post.new(@uri.request_uri)
167
181
  request['authorization'] = generate_token(events)
168
- request['Content-type'] = "application/json"
169
- request['User-Agent'] = log_source + "/" + version_id
170
182
 
171
183
  if @compression == "gzip"
172
184
  request['Content-Encoding'] = "gzip"
@@ -182,7 +194,8 @@ module Fluent
182
194
  request.each_header {|key,value| log.info "#{key} = #{value}" }
183
195
  end
184
196
 
185
- resp = http.request(request)
197
+ resp = @http_client.request @uri, request
198
+
186
199
  if @debug || (!resp.kind_of? Net::HTTPSuccess)
187
200
  log.info "Status code:#{resp.code} Request Id:#{resp.header['x-request-id']}"
188
201
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LmLogsFluentPlugin
4
+ VERSION = '1.0.5'
5
+ 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.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - LogicMonitor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: net-http-persistent
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 4.0.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 4.0.1
33
47
  description: This output plugin sends fluentd records to the configured LogicMonitor
34
48
  account.
35
49
  email: rubygems@logicmonitor.com
@@ -44,6 +58,7 @@ files:
44
58
  - Rakefile
45
59
  - fluent-plugin-lm-logs.gemspec
46
60
  - lib/fluent/plugin/out_lm.rb
61
+ - lib/fluent/plugin/version.rb
47
62
  homepage: https://www.logicmonitor.com
48
63
  licenses:
49
64
  - Apache-2.0
@@ -65,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
80
  - !ruby/object:Gem::Version
66
81
  version: '0'
67
82
  requirements: []
68
- rubygems_version: 3.3.7
83
+ rubygems_version: 3.4.10
69
84
  signing_key:
70
85
  specification_version: 4
71
86
  summary: LogicMonitor logs fluentd output plugin