fluent-plugin-logmatic 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4a8ae2452e547650e5139666b2e11e16a849552
4
+ data.tar.gz: 952cf838c0ebd948448569299680347196791456
5
+ SHA512:
6
+ metadata.gz: 7cc21ad106c3f519700cbc4e0b4b2434abe7ed124b2f3ea0bca8c63623499afab82f4288bdbf7cea43235fed946cadaf8f8d34c3ada4b7c5706618f3ee99b521
7
+ data.tar.gz: 228734eba5ef3240140ac6903d4c18a3764fbefbd3a96f394e2185a399267e64c80e088225fe7b554f6e47d16162b32c722844c737268ebab28aadd862bcb258
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-logmatic.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Logmatic.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ fluent-plugin-logmatic
2
+ ===============
3
+
4
+ Fluentd output plugin for Logmatic.io.
5
+
6
+ It mainly contains a proper JSON formatter and a socket handler that
7
+ streams logs directly to Logmatic.io - so no need to use a log shipper
8
+ if you don't wan't to.
9
+
10
+ Pre-requirements
11
+ ================
12
+
13
+ To add the plugin to your fluentd agent, use the following command:
14
+
15
+ gem install fluent-plugin-logmatic
16
+
17
+ Usage
18
+ =====
19
+
20
+ "match" Tell fluentd how to send to Logmatic.io
21
+ --------------------------
22
+
23
+ To match events tagged logmatic, simply add the following code to your configuration file.
24
+
25
+ ```xml
26
+ # Match events tagged with "logmatic.**" and
27
+ # send them to Logmatic.io
28
+ <match logmatic.**>
29
+
30
+ @type logmatic
31
+ @id awesome_agent
32
+
33
+ api_key <your_api_key>
34
+
35
+ </match>
36
+
37
+ ```
38
+
39
+ Once this setup is done, any child events tagged with `logmatic` will be ship to your plateform.
40
+
41
+ Let's make a simple test.
42
+
43
+ ```bash
44
+ echo '{"message":"hello world from fluentd"}' | fluent-cat logmatic.demo
45
+ ```
46
+
47
+ This will produce the following event:
48
+
49
+ ```javascript
50
+ {
51
+ "custom": {
52
+ "message": "hello world from fluentd"
53
+ }
54
+ }
55
+ ```
56
+
57
+ fluent-plugin-logmatic properties
58
+ ======
59
+ Let's go deeper on the plugin configuration.
60
+
61
+ As fluent-plugin-logmatic is an output_buffer, you can set all output_buffer properties like it's describe in the [fluentd documentation](http://docs.fluentd.org/articles/output-plugin-overview#buffered-output-parameters "documentation").
62
+
63
+ api_key
64
+ --------
65
+ This parameter is required in order to authenticate your fluent agent. The agent won't started until set your key.
66
+
67
+ use_json
68
+ --------
69
+ If it's set to true, the event will be send to json format. If it's set to false, only the key `message` of the record will be sent to Logmatic.io. Set to true by default.
70
+
71
+ use_ssl
72
+ --------
73
+ If it's set to true, the agent initialize a secure connection to Logmatic. Set to true by default.
74
+
75
+
76
+ max_retries
77
+ --------
78
+ The number of retries before raised an error. By default, this parameter is set to 3.
79
+
80
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-logmatic"
7
+ spec.version = "0.7"
8
+ spec.authors = ["Logmatic support team"]
9
+ spec.email = ["support@logmatic.io"]
10
+ spec.summary = "Logmatic output plugin for Fluent event collector"
11
+ spec.homepage = "https://github.com/logmatic/fluent-plugin-logmatic"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1,90 @@
1
+ require 'socket'
2
+ require 'openssl'
3
+
4
+ class Fluent::LogmaticOutput < Fluent::BufferedOutput
5
+ class ConnectionFailure < StandardError; end
6
+
7
+ # Register the plugin
8
+ Fluent::Plugin.register_output('logmatic', self)
9
+
10
+ # Output settings
11
+ config_param :use_json, :bool, :default => true
12
+
13
+ # Connection settings
14
+ config_param :host, :string, :default => 'api.logmatic.io'
15
+ config_param :use_ssl, :bool, :default => true
16
+ config_param :port, :integer, :default => 10514
17
+ config_param :ssl_port, :integer, :default => 10515
18
+ config_param :max_retries, :integer, :default => 3
19
+
20
+ # API Settings
21
+ config_param :api_key, :string
22
+
23
+ def configure(conf)
24
+ super
25
+ @last_edit = Time.at(0)
26
+ end
27
+
28
+ def start
29
+ super
30
+ end
31
+
32
+ def shutdown
33
+ super
34
+ end
35
+
36
+ def client
37
+
38
+ @_socket ||= if @use_ssl
39
+ context = OpenSSL::SSL::SSLContext.new
40
+ socket = TCPSocket.new @host, @ssl_port
41
+ ssl_client = OpenSSL::SSL::SSLSocket.new socket, context
42
+ ssl_client.connect
43
+ else
44
+ TCPSocket.new @host, @port
45
+ end
46
+
47
+ end
48
+
49
+ # This method is called when an event reaches Fluentd.
50
+ def format(tag, time, record)
51
+ return [tag, record].to_msgpack
52
+ end
53
+
54
+ # NOTE! This method is called by internal thread, not Fluentd's main thread.
55
+ # 'chunk' is a buffer chunk that includes multiple formatted events.
56
+ def write(chunk)
57
+
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
+ message = @use_json ? record.to_json : record["message"].rstrip()
62
+ send_to_logmatic(message)
63
+ end
64
+
65
+ end
66
+
67
+ def send_to_logmatic(data)
68
+
69
+ retries = 0
70
+
71
+ begin
72
+
73
+ client.write("#{api_key} #{data}\n")
74
+
75
+ # Handle some failures
76
+ rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE => e
77
+
78
+ if retries < @max_retries
79
+ retries += 1
80
+ @_socket = nil
81
+ a_couple_of_seconds = 5**retries
82
+ log.warn "Could not push logs to Logmatic, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{e.message}"
83
+ sleep a_couple_of_seconds
84
+ retry
85
+ end
86
+ raise ConnectionFailure, "Could not push logs to Logmatic after #{retries} retries, #{e.message}"
87
+ end
88
+ end
89
+
90
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-logmatic
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.7'
5
+ platform: ruby
6
+ authors:
7
+ - Logmatic support team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - support@logmatic.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - fluent-plugin-logmatic.gemspec
54
+ - lib/fluent/plugin/out_logmatic.rb
55
+ homepage: https://github.com/logmatic/fluent-plugin-logmatic
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Logmatic output plugin for Fluent event collector
79
+ test_files: []