fluent-plugin-logentries-tmpfix 0.2.10.pre.tmpfix
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +1 -0
- data/fluent-plugin-logentries.gemspec +21 -0
- data/lib/fluent/plugin/out_logentries.rb +149 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 483abaa7da4f4eb1d3bd6f12470c9d385a27e7e8
|
4
|
+
data.tar.gz: 59b89ed3653568fac42b0cb33a500273091e652f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 143f965cf7a6359df1668850e1c65a569ef8417cc65e8498ea72d4cb52c43ac0e34893a5b75f7497e7e888e72ff9b98e191a1de82bb643c625f03b8c40c69cdf
|
7
|
+
data.tar.gz: 08ae4f751959c754fa98cd041c45984a7fd9609450eaf750f462c43d681f9834e11b8973fda53f8f1e60390db4f4e798ea00bac961cdbca1e0492bb9f7e6a195
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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,78 @@
|
|
1
|
+
# Fluent::Plugin::Logentries
|
2
|
+
Forward logs to Logentries, using token based input.
|
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
|
12
|
+
|
13
|
+
### fluentd gem
|
14
|
+
$ /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-logentries
|
15
|
+
|
16
|
+
## Configruation file (YML)
|
17
|
+
|
18
|
+
```yaml
|
19
|
+
My-Awesome-App:
|
20
|
+
app: MY-LOGENTRIES-TOKEN
|
21
|
+
access: ANOTHER-LOGENTRIES-TOKEN (*)
|
22
|
+
error: ANOTHER-LOGENTRIES-TOKEN-1 (*)
|
23
|
+
Another-app:
|
24
|
+
app: 2bfbea1e-10c3-4419-bdad-7e6435882e1f
|
25
|
+
access: 5deab21c-04b1-9122-abdc-09adb2eda22 (*)
|
26
|
+
error: 9acfbeba-c92c-1229-ccac-12c58d82ecc (*)
|
27
|
+
```
|
28
|
+
(*) `access` and `error` are optional, if you don't use multiple log per host just provide an app token.
|
29
|
+
|
30
|
+
This file is read on changes, it allows on fly modifications.
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```
|
34
|
+
<match pattern>
|
35
|
+
type logentries
|
36
|
+
config_path /path/to/logentries-tokens.conf
|
37
|
+
</match>
|
38
|
+
```
|
39
|
+
|
40
|
+
## Parameters
|
41
|
+
|
42
|
+
### type (required)
|
43
|
+
The value must be `logentries`.
|
44
|
+
|
45
|
+
### config_path (required)
|
46
|
+
Path of your configuration file, e.g. `/opt/logentries/tokens.conf`
|
47
|
+
|
48
|
+
### protocol
|
49
|
+
The default is `tcp`.
|
50
|
+
|
51
|
+
### use_ssl
|
52
|
+
Enable/disable SSL for data transfers between Fluentd and Logentries. The default is `true`.
|
53
|
+
|
54
|
+
### port
|
55
|
+
Only in case you don't use SSL, the value must be `80`, `514`, or `10000`. The default is `20000` (SSL)
|
56
|
+
|
57
|
+
### max_retries
|
58
|
+
Number of retries on failure.
|
59
|
+
|
60
|
+
### tag_access_log, tag_error_log
|
61
|
+
This is use in case you tag your access/error log and want them to be push into another log.
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it ( http://github.com/woorank/fluent-plugin-logentries/fork )
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
70
|
+
|
71
|
+
## MIT
|
72
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
73
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
74
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
75
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
76
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
77
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
78
|
+
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-tmpfix"
|
7
|
+
spec.version = "0.2.10-tmpfix"
|
8
|
+
spec.authors = ["bigwheel"]
|
9
|
+
spec.email = ["example@example.com"]
|
10
|
+
spec.summary = "Logentries output plugin for Fluent event collector"
|
11
|
+
spec.homepage = "https://github.com/bigwheel/fluent-plugin-logentries"
|
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,149 @@
|
|
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-tmpfix', 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 :config_path, :string
|
16
|
+
config_param :max_retries, :integer, :default => 3
|
17
|
+
config_param :tag_access_log, :string, :default => 'logs-access'
|
18
|
+
config_param :tag_error_log, :string, :default => 'logs-error'
|
19
|
+
config_param :default_token, :string, :default => nil
|
20
|
+
|
21
|
+
SSL_HOST = "api.logentries.com"
|
22
|
+
NO_SSL_HOST = "data.logentries.com"
|
23
|
+
|
24
|
+
def configure(conf)
|
25
|
+
super
|
26
|
+
|
27
|
+
@tokens = nil
|
28
|
+
@last_edit = Time.at(0)
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def shutdown
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def client
|
40
|
+
@_socket ||= if @use_ssl
|
41
|
+
context = OpenSSL::SSL::SSLContext.new
|
42
|
+
socket = TCPSocket.new SSL_HOST, @port
|
43
|
+
ssl_client = OpenSSL::SSL::SSLSocket.new socket, context
|
44
|
+
|
45
|
+
ssl_client.connect
|
46
|
+
else
|
47
|
+
if @protocol == 'tcp'
|
48
|
+
TCPSocket.new NO_SSL_HOST, @port
|
49
|
+
else
|
50
|
+
udp_client = UDPSocket.new
|
51
|
+
udp_client.connect NO_SSL_HOST, @port
|
52
|
+
|
53
|
+
udp_client
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# This method is called when an event reaches Fluentd.
|
59
|
+
def format(tag, time, record)
|
60
|
+
return [tag, record].to_msgpack
|
61
|
+
end
|
62
|
+
|
63
|
+
# Parse an YML file and generate a list of tokens.
|
64
|
+
# It will only re-generate the list on changes.
|
65
|
+
def generate_tokens_list
|
66
|
+
begin
|
67
|
+
edit_time = File.mtime(@config_path)
|
68
|
+
|
69
|
+
if edit_time > @last_edit
|
70
|
+
@tokens = YAML::load_file(@config_path)
|
71
|
+
@last_edit = edit_time
|
72
|
+
|
73
|
+
log.info "Token(s) list updated."
|
74
|
+
end
|
75
|
+
rescue Exception => e
|
76
|
+
log.warn "Could not load configuration. #{e.message}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the correct token to use for a given tag / records
|
81
|
+
def get_token(tag, record)
|
82
|
+
app_name = record["app_name"] || ''
|
83
|
+
|
84
|
+
# Config Structure
|
85
|
+
# -----------------------
|
86
|
+
# app-name:
|
87
|
+
# app: TOKEN
|
88
|
+
# access: TOKEN (optional)
|
89
|
+
# error: TOKEN (optional)
|
90
|
+
@tokens.each do |key, value|
|
91
|
+
if app_name == key || tag.index(key) != nil
|
92
|
+
default = value['app']
|
93
|
+
|
94
|
+
case tag
|
95
|
+
when @tag_access_log
|
96
|
+
return value['access'] || default
|
97
|
+
when @tag_error_log
|
98
|
+
return value['error'] || default
|
99
|
+
|
100
|
+
else
|
101
|
+
return default
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
return default_token
|
107
|
+
end
|
108
|
+
|
109
|
+
# NOTE! This method is called by internal thread, not Fluentd's main thread. So IO wait doesn't affect other plugins.
|
110
|
+
def write(chunk)
|
111
|
+
generate_tokens_list()
|
112
|
+
return unless @tokens.is_a? Hash
|
113
|
+
|
114
|
+
chunk.msgpack_each do |tag, record|
|
115
|
+
next unless record.is_a? Hash
|
116
|
+
next unless @use_json or record.has_key? "message"
|
117
|
+
|
118
|
+
token = get_token(tag, record)
|
119
|
+
next if token.nil?
|
120
|
+
|
121
|
+
# Clean up the string to avoid blank line in logentries
|
122
|
+
message = @use_json ? record.to_json : record["message"].rstrip()
|
123
|
+
send_logentries(token, message)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def send_logentries(token, data)
|
128
|
+
retries = 0
|
129
|
+
begin
|
130
|
+
client.write("#{token} #{data} \n")
|
131
|
+
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::ETIMEDOUT, Errno::EPIPE => e
|
132
|
+
if retries < @max_retries
|
133
|
+
retries += 1
|
134
|
+
@_socket = nil
|
135
|
+
log.warn "Could not push logs to Logentries, resetting connection and trying again. #{e.message}"
|
136
|
+
sleep 5**retries
|
137
|
+
retry
|
138
|
+
end
|
139
|
+
raise ConnectionFailure, "Could not push logs to Logentries after #{retries} retries. #{e.message}"
|
140
|
+
rescue Errno::EMSGSIZE
|
141
|
+
str_length = data.length
|
142
|
+
send_logentries(token, data[0..str_length/2])
|
143
|
+
send_logentries(token, data[(str_length/2)+1..str_length])
|
144
|
+
|
145
|
+
log.warn "Message Too Long, re-sending it in two part..."
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-logentries-tmpfix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.10.pre.tmpfix
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bigwheel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-31 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
|
+
- example@example.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- fluent-plugin-logentries.gemspec
|
54
|
+
- lib/fluent/plugin/out_logentries.rb
|
55
|
+
homepage: https://github.com/bigwheel/fluent-plugin-logentries
|
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: 1.3.1
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.5.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Logentries output plugin for Fluent event collector
|
79
|
+
test_files: []
|