fluent-plugin-logentries-simple-config 0.2.14v

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb450db161d7878aafd61bdcd42f6481ed9a0840
4
+ data.tar.gz: fb37be304bb52f868451f26dc11253419814867b
5
+ SHA512:
6
+ metadata.gz: 9d0ccb3ee80c420931ced7d7129302f7d059ba0995a9228f6ef5b13a6020e3700ee28fa148cdd6969caec3fb1c94a1877dbf92da5e33edf3da473708dca8a94b
7
+ data.tar.gz: bb94434d3f76fd5626fc5c79e3b7c8d2b160e2b7660c46bddddc6810cc2e434c2e0a8b02e596c958847d672d3a77ca48c5dac6d473c406c3304657a0221dfd30
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-logentries.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Fluent::Plugin::Logentries
2
+ Forward logs to Logentries.
3
+
4
+ Looks at the tag/message to find out where the log should go.
5
+
6
+ ## Installation
7
+
8
+ install with gem or fluent-gem command as:
9
+
10
+ ### native gem
11
+ $ gem install fluent-plugin-logentries-simple-config
12
+
13
+ ### fluentd gem
14
+ $ /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-logentries-simple-config
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ <match pattern>
20
+ @type logentries-simple-config
21
+ token ACBD-....
22
+ </match>
23
+ ```
24
+
25
+ ## Parameters
26
+
27
+ ### type (required)
28
+ The value must be `logentries-simple-config`.
29
+
30
+ ### token (required)
31
+ Logentries token.
32
+
33
+ ### protocol
34
+ The default is `tcp`.
35
+
36
+ ### use_ssl
37
+ Enable/disable SSL for data transfers between Fluentd and Logentries. The default is `true`.
38
+
39
+ ### port
40
+ Only in case you don't use SSL, the value must be `80`, `514`, or `10000`. The default is `20000` (SSL)
41
+
42
+ ### max_retries
43
+ Number of retries on failure.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/notmaxx/fluent-plugin-logentries/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+ ## MIT
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
60
+ THE SOFTWARE.
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-logentries-simple-config"
7
+ spec.version = "0.2.14v"
8
+ spec.authors = ["notmaxx"]
9
+ spec.email = ["example@example.com"]
10
+ spec.summary = "Logentries output plugin for Fluent event"
11
+ spec.homepage = "https://github.com/notmaxx/fluent-plugin-logentries"
12
+ spec.description = "Logentries output plugin for Fluent event without Logentries config file, just with simple token"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ end
@@ -0,0 +1,154 @@
1
+ require 'socket'
2
+ require 'yaml'
3
+ require 'openssl'
4
+
5
+ class Fluent::LogentriesOutput < Fluent::BufferedOutput
6
+ class ConnectionFailure < StandardError; end
7
+ # First, register the plugin. NAME is the name of this plugin
8
+ # and identifies the plugin in the configuration file.
9
+ Fluent::Plugin.register_output('logentries-simple-config', self)
10
+
11
+ config_param :use_ssl, :bool, :default => true
12
+ config_param :use_json, :bool, :default => false
13
+ config_param :port, :integer, :default => 20000
14
+ config_param :protocol, :string, :default => 'tcp'
15
+ config_param :token, :string
16
+ config_param :extra_tokens, :string, :default => nil # "token1:app1,app2,app3 token2:app11,app12,app13"
17
+ config_param :max_retries, :integer, :default => 3
18
+
19
+ SSL_HOST = "api.logentries.com"
20
+ NO_SSL_HOST = "data.logentries.com"
21
+
22
+ def configure(conf)
23
+ super
24
+ end
25
+
26
+ def start
27
+ @app_tokens = if @extra_tokens.present?
28
+ puts "extra_tokens: #{@extra_tokens}"
29
+ token_apps = (@extra_tokens.split(' ')&.select { |v| v&.strip&.presence })&.compact
30
+ puts "token_apps: #{token_apps}"
31
+ if token_apps.present?
32
+ {}.tap do |total_apps|
33
+ token_apps.each do |token_app|
34
+ puts "token_app: #{token_app}"
35
+ token, apps = token_app.split(':')
36
+ puts "token, apps: #{token}, #{apps}"
37
+ if token.present? && apps.present?
38
+ apps_list = (apps&.split(',')&.select { |v| v&.strip&.presence })&.compact
39
+ puts "apps_list: #{apps_list}"
40
+ if apps_list.present?
41
+ apps_list.each { |app| total_apps[app] = token }
42
+ puts "total_apps: #{total_apps}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end || {}
49
+
50
+ puts "app_tokens: #{@app_tokens}"
51
+
52
+ super
53
+ end
54
+
55
+ def shutdown
56
+ super
57
+ end
58
+
59
+ def client
60
+ @_socket ||= if @use_ssl
61
+ context = OpenSSL::SSL::SSLContext.new
62
+ socket = TCPSocket.new SSL_HOST, @port
63
+ ssl_client = OpenSSL::SSL::SSLSocket.new socket, context
64
+
65
+ ssl_client.connect
66
+ else
67
+ if @protocol == 'tcp'
68
+ TCPSocket.new NO_SSL_HOST, @port
69
+ else
70
+ udp_client = UDPSocket.new
71
+ udp_client.connect NO_SSL_HOST, @port
72
+
73
+ udp_client
74
+ end
75
+ end
76
+ end
77
+
78
+ # This method is called when an event reaches Fluentd.
79
+ def format(tag, time, record)
80
+ return [tag, record].to_msgpack
81
+ end
82
+
83
+ # NOTE! This method is called by internal thread, not Fluentd's main thread. So IO wait doesn't affect other plugins.
84
+ def write(chunk)
85
+ return if @token.blank?
86
+
87
+ le_app_token = nil
88
+
89
+ chunk.msgpack_each do |tag, record|
90
+ next unless record.is_a? Hash
91
+
92
+ message = if @use_json
93
+ record.to_json
94
+ else
95
+ r = record.dup
96
+ r.merge!({ "tag" => tag }) if tag.present?
97
+ # main message
98
+ msg = (r.delete('message')&.to_s&.rstrip || '')
99
+ # time
100
+ t = if r['time'].is_a?(String)
101
+ Time.parse(r['time']).strftime('%Y-%m-%dT%H:%M:%S.%6N%:z')
102
+ elsif r['time'].is_a?(Time)
103
+ r['time'].strftime('%Y-%m-%dT%H:%M:%S.%6N%:z')
104
+ else
105
+ ''
106
+ end
107
+ # application & role
108
+ app, role = if r['kubernetes_pod'].is_a?(String) && (fullapp = r['kubernetes_pod'].split('-')).present?
109
+ [fullapp[0], fullapp[1..fullapp.size-1].join('-')]
110
+ else
111
+ [nil, nil]
112
+ end
113
+ # custom prefix built from application and role
114
+ prefix = if app.present? && role.present? && t.present?
115
+ le_app_token = @app_tokens[app]
116
+ pid = '<000>0'
117
+ spacer = ' - - '
118
+ "#{pid} #{t} #{app} #{role} #{spacer} "
119
+ else
120
+ ""
121
+ end
122
+ # extra tags
123
+ tags = r.map{ |k,v| "#{k}: #{v}" }.join(', ')
124
+ # final message
125
+ prefix + msg + (tags.present? && msg.present? ? ", " + tags : tags)
126
+ end
127
+
128
+ send_logentries(le_app_token || @token, message)
129
+ end
130
+ end
131
+
132
+ def send_logentries(token, data)
133
+ retries = 0
134
+ begin
135
+ client.write("#{token} #{data} \n")
136
+ rescue Errno::EMSGSIZE
137
+ str_length = data.length
138
+ send_logentries(token, data[0..str_length/2])
139
+ send_logentries(token, data[(str_length/2)+1..str_length])
140
+
141
+ log.warn "Message Too Long, re-sending it in two part..."
142
+ rescue => e
143
+ if retries < @max_retries
144
+ retries += 1
145
+ @_socket = nil
146
+ log.warn "Could not push logs to Logentries, resetting connection and trying again. #{e.message}"
147
+ sleep 5**retries
148
+ retry
149
+ end
150
+ raise ConnectionFailure, "Could not push logs to Logentries after #{retries} retries. #{e.message}"
151
+ end
152
+ end
153
+
154
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-logentries-simple-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.14v
5
+ platform: ruby
6
+ authors:
7
+ - notmaxx
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-25 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
+ description: Logentries output plugin for Fluent event without Logentries config file,
28
+ just with simple token
29
+ email:
30
+ - example@example.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - fluent-plugin-logentries-simple-config.gemspec
41
+ - lib/fluent/plugin/out_logentries-simple-config.rb
42
+ homepage: https://github.com/notmaxx/fluent-plugin-logentries
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">"
58
+ - !ruby/object:Gem::Version
59
+ version: 1.3.1
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.8
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Logentries output plugin for Fluent event
66
+ test_files: []