fluent-plugin-logmatic 0.8.3 → 0.9.0
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 +4 -2
- data/fluent-plugin-logmatic.gemspec +2 -2
- data/lib/fluent/plugin/out_logmatic_http.rb +101 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49374af53808bfdd30a59f976c71fb1e161ceecb
|
4
|
+
data.tar.gz: 776691802f58b23f15ee374916b7e9b594796253
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 845f4a9a04e4ee16e8b3a2386cc452b990aa437c5be54eb9960ed8ea1a2384ac12770b09cd3caace07f31ac74da5c984bfc3b291821ac35dc5fb809a5945fcb8
|
7
|
+
data.tar.gz: 7c177051f77ae73a8f4f58912763a69547cdbe362e7db1e2c43c3aedeafc67347e880454e9e68e7caed6d82f0b4dc192bc83961d72a587dfc737854ecf320984
|
data/README.md
CHANGED
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-logmatic"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.9.0"
|
8
8
|
spec.authors = ["Logmatic support team"]
|
9
9
|
spec.email = ["support@logmatic.io"]
|
10
10
|
spec.summary = "Logmatic output plugin for Fluent event collector"
|
11
11
|
spec.homepage = "http://logmatic.io"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
14
|
-
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-logmatic.gemspec", "lib/fluent/plugin/out_logmatic.rb"]
|
14
|
+
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-logmatic.gemspec", "lib/fluent/plugin/out_logmatic.rb", "lib/fluent/plugin/out_logmatic_http.rb"]
|
15
15
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class Fluent::LogmaticOutput < Fluent::BufferedOutput
|
2
|
+
class ConnectionFailure < StandardError;
|
3
|
+
end
|
4
|
+
|
5
|
+
# Register the plugin
|
6
|
+
Fluent::Plugin.register_output('logmatic_http', self)
|
7
|
+
|
8
|
+
# Output settings
|
9
|
+
config_param :use_json, :bool, :default => true
|
10
|
+
config_param :include_tag_key, :bool, :default => false
|
11
|
+
config_param :tag_key, :string, :default => 'tag'
|
12
|
+
|
13
|
+
# API Settings
|
14
|
+
config_param :api_key, :string
|
15
|
+
|
16
|
+
# Connection settings
|
17
|
+
config_param :max_retries, :integer, :default => -1
|
18
|
+
config_param :endpoint, :string, :default => "https://api.logmatic.io/v1/input/"
|
19
|
+
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
require 'net/http'
|
24
|
+
require 'net/https'
|
25
|
+
require 'uri'
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure(conf)
|
29
|
+
super(conf)
|
30
|
+
# Http client
|
31
|
+
@uri = URI.parse(@endpoint + @api_key)
|
32
|
+
@https = Net::HTTP.new(@uri.host, @uri.port)
|
33
|
+
@https.use_ssl = true
|
34
|
+
log.trace("Setting new connection to https://#{@uri.host}:#{@uri.port}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def start
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def shutdown
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# This method is called when an event reaches Fluentd.
|
47
|
+
def format(tag, time, record)
|
48
|
+
return [tag, record].to_msgpack
|
49
|
+
end
|
50
|
+
|
51
|
+
# NOTE! This method is called by internal thread, not Fluentd's main thread.
|
52
|
+
# 'chunk' is a buffer chunk that includes multiple formatted events.
|
53
|
+
def write(chunk)
|
54
|
+
|
55
|
+
messages = Array.new
|
56
|
+
|
57
|
+
# Pack messages
|
58
|
+
chunk.msgpack_each do |tag, record|
|
59
|
+
next unless record.is_a? Hash
|
60
|
+
next unless @use_json or record.has_key? "message"
|
61
|
+
|
62
|
+
if @include_tag_key
|
63
|
+
record[@tag_key] = tag
|
64
|
+
end
|
65
|
+
messages.push record.to_json
|
66
|
+
end
|
67
|
+
|
68
|
+
# Send them
|
69
|
+
log.trace("Sending #{messages.length} messages")
|
70
|
+
retries = 0
|
71
|
+
begin
|
72
|
+
|
73
|
+
req = Net::HTTP::Post.new(@uri.path)
|
74
|
+
req['Content-Type'] = 'application/json'
|
75
|
+
req.body = data
|
76
|
+
log.trace("Posting data")
|
77
|
+
res = @https.request(messages.to_json)
|
78
|
+
log.trace("Status code: #{res.code}")
|
79
|
+
|
80
|
+
if (res.code != 0 && res.code != 400)
|
81
|
+
if retries < @max_retries || max_retries == -1
|
82
|
+
|
83
|
+
a_couple_of_seconds = retries ** 2
|
84
|
+
a_couple_of_seconds = 30 unless a_couple_of_seconds < 30
|
85
|
+
retries += 1
|
86
|
+
log.warn "Could not push logs to Logmatic, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{res.code}"
|
87
|
+
|
88
|
+
sleep a_couple_of_seconds
|
89
|
+
|
90
|
+
raise "Status code: #{res.code}"
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
rescue => e
|
95
|
+
# Handle some failures
|
96
|
+
retry
|
97
|
+
raise ConnectionFailure, "Could not push logs to Logmatic after #{retries} retries, #{e.message}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-logmatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logmatic support team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- fluent-plugin-logmatic.gemspec
|
54
54
|
- lib/fluent/plugin/out_logmatic.rb
|
55
|
+
- lib/fluent/plugin/out_logmatic_http.rb
|
55
56
|
homepage: http://logmatic.io
|
56
57
|
licenses:
|
57
58
|
- MIT
|
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
75
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.6.8
|
76
77
|
signing_key:
|
77
78
|
specification_version: 4
|
78
79
|
summary: Logmatic output plugin for Fluent event collector
|