fluent-plugin-sumologic_output 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +1 -0
- data/Rakefile +11 -0
- data/fluent-plugin-sumologic_output.gemspec +2 -1
- data/lib/fluent/plugin/out_sumologic.rb +46 -7
- data/test/helper.rb +2 -0
- data/test/plugin/test_out_sumologic.rb +41 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e311e7b4512f25f99942f69fdf4c90405d2351
|
4
|
+
data.tar.gz: ff095f8c1176898c8a7f97c65abc5a0c816f88db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c2c9c4a24a557cecb6e426b5069d5dfa6f6750996a262f8448cd5d79ec7192836ee1c9a0c332c93b2cd54596d48f01e0d032c8ff9b7777ca2ba939d7ba1c20e
|
7
|
+
data.tar.gz: 472fb4fa5312d2734704164e49b073a1b44e378690c9471c95be6f7696103f4e1daf6304c124353c6de128cd46986eda808fa91e41cecab154da1ceab5efc76c
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Configuration options for fluent.conf are:
|
|
21
21
|
* json - Logs will appear in SumoLogic in json format.
|
22
22
|
* json_merge - Same as json but merge content of `log_key` into the top level and strip `log_key`
|
23
23
|
* `log_key` - Used to specify the key when merging json or sending logs in text format (default `message`)
|
24
|
+
* `open_timeout` - Set timeout seconds to wait until connection is opened.
|
24
25
|
|
25
26
|
Reading from the JSON formatted log files with `in_tail` and wildcard filenames:
|
26
27
|
```
|
data/Rakefile
ADDED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "fluent-plugin-sumologic_output"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.7"
|
8
8
|
gem.authors = ["Steven Adams"]
|
9
9
|
gem.email = ["stevezau@gmail.com"]
|
10
10
|
gem.description = %q{Output plugin to SumoLogic HTTP Endpoint}
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
gem.add_development_dependency "rake"
|
25
25
|
gem.add_runtime_dependency "fluentd"
|
26
|
+
gem.add_development_dependency 'test-unit', '~> 3.1.0'
|
26
27
|
end
|
@@ -3,9 +3,10 @@ require 'net/https'
|
|
3
3
|
require 'yajl'
|
4
4
|
|
5
5
|
class SumologicConnection
|
6
|
-
def initialize(endpoint, verify_ssl)
|
6
|
+
def initialize(endpoint, verify_ssl, open_timeout)
|
7
7
|
@endpoint_uri = URI.parse(endpoint.strip)
|
8
8
|
@verify_ssl = verify_ssl
|
9
|
+
@open_timeout = open_timeout
|
9
10
|
end
|
10
11
|
|
11
12
|
def publish(raw_data, source_host=nil, source_category=nil, source_name=nil)
|
@@ -30,6 +31,7 @@ class SumologicConnection
|
|
30
31
|
client = Net::HTTP.new(@endpoint_uri.host, @endpoint_uri.port)
|
31
32
|
client.use_ssl = true
|
32
33
|
client.verify_mode = @verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
34
|
+
client.open_timeout = @open_timeout
|
33
35
|
client
|
34
36
|
end
|
35
37
|
end
|
@@ -47,6 +49,8 @@ class Sumologic < Fluent::BufferedOutput
|
|
47
49
|
config_param :source_name_key, :string, :default => 'source_name'
|
48
50
|
config_param :source_host, :string, :default => nil
|
49
51
|
config_param :verify_ssl, :bool, :default => true
|
52
|
+
config_param :delimiter, :string, :default => "."
|
53
|
+
config_param :open_timeout, :integer, :default => 60
|
50
54
|
|
51
55
|
# This method is called before starting.
|
52
56
|
def configure(conf)
|
@@ -58,7 +62,7 @@ class Sumologic < Fluent::BufferedOutput
|
|
58
62
|
raise Fluent::ConfigError, "Invalid log_format #{conf['log_format']} must be text, json or json_merge"
|
59
63
|
end
|
60
64
|
|
61
|
-
@sumo_conn = SumologicConnection.new(conf['endpoint'],
|
65
|
+
@sumo_conn = SumologicConnection.new(conf['endpoint'], conf['verify_ssl'], conf['open_timeout'].to_i)
|
62
66
|
super
|
63
67
|
end
|
64
68
|
|
@@ -98,10 +102,16 @@ class Sumologic < Fluent::BufferedOutput
|
|
98
102
|
[tag, time, record].to_msgpack
|
99
103
|
end
|
100
104
|
|
101
|
-
def sumo_key(
|
102
|
-
source_name =
|
103
|
-
|
104
|
-
|
105
|
+
def sumo_key(sumo_metadata, record, tag)
|
106
|
+
source_name = sumo_metadata['source'] || @source_name
|
107
|
+
source_name = expand_param(source_name, tag, nil, record)
|
108
|
+
|
109
|
+
source_category = sumo_metadata['category'] || @source_category
|
110
|
+
source_category = expand_param(source_category, tag, nil, record)
|
111
|
+
|
112
|
+
source_host = sumo_metadata['host'] || @source_host
|
113
|
+
source_host = expand_param(source_host, tag, nil, record)
|
114
|
+
|
105
115
|
"#{source_name}:#{source_category}:#{source_host}"
|
106
116
|
end
|
107
117
|
|
@@ -110,6 +120,35 @@ class Sumologic < Fluent::BufferedOutput
|
|
110
120
|
time.to_s.length == 13 ? time : time * 1000
|
111
121
|
end
|
112
122
|
|
123
|
+
# copy from https://github.com/uken/fluent-plugin-elasticsearch/commit/1722c58758b4da82f596ecb0a5075d3cb6c99b2e#diff-33bfa932bf1443760673c69df745272eR221
|
124
|
+
def expand_param(param, tag, time, record)
|
125
|
+
# check for '${ ... }'
|
126
|
+
# yes => `eval`
|
127
|
+
# no => return param
|
128
|
+
return param if (param =~ /\${.+}/).nil?
|
129
|
+
|
130
|
+
# check for 'tag_parts[]'
|
131
|
+
# separated by a delimiter (default '.')
|
132
|
+
tag_parts = tag.split(@delimiter) unless (param =~ /tag_parts\[.+\]/).nil? || tag.nil?
|
133
|
+
|
134
|
+
# pull out section between ${} then eval
|
135
|
+
inner = param.clone
|
136
|
+
while inner.match(/\${.+}/)
|
137
|
+
to_eval = inner.match(/\${(.+?)}/){$1}
|
138
|
+
|
139
|
+
if !(to_eval =~ /record\[.+\]/).nil? && record.nil?
|
140
|
+
return to_eval
|
141
|
+
elsif !(to_eval =~/tag_parts\[.+\]/).nil? && tag_parts.nil?
|
142
|
+
return to_eval
|
143
|
+
elsif !(to_eval =~/time/).nil? && time.nil?
|
144
|
+
return to_eval
|
145
|
+
else
|
146
|
+
inner.sub!(/\${.+?}/, eval( to_eval ))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
inner
|
150
|
+
end
|
151
|
+
|
113
152
|
# This method is called every flush interval. Write the buffer chunk
|
114
153
|
def write(chunk)
|
115
154
|
messages_list = {}
|
@@ -120,7 +159,7 @@ class Sumologic < Fluent::BufferedOutput
|
|
120
159
|
# https://github.com/uken/fluent-plugin-elasticsearch/commit/8597b5d1faf34dd1f1523bfec45852d380b26601#diff-ae62a005780cc730c558e3e4f47cc544R94
|
121
160
|
next unless record.is_a? Hash
|
122
161
|
sumo_metadata = record.fetch('_sumo_metadata', {'source' => record[@source_name_key]})
|
123
|
-
key = sumo_key(sumo_metadata)
|
162
|
+
key = sumo_key(sumo_metadata, record, tag)
|
124
163
|
log_format = sumo_metadata['log_format'] || @log_format
|
125
164
|
|
126
165
|
# Strip any unwanted newlines
|
data/test/helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/test/driver/output'
|
3
|
+
|
4
|
+
class SumologicOutput < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
require 'fluent/plugin/out_sumologic'
|
8
|
+
@driver = nil
|
9
|
+
log = Fluent::Engine.log
|
10
|
+
log.out.logs.slice!(0, log.out.logs.length)
|
11
|
+
end
|
12
|
+
|
13
|
+
def driver(conf='')
|
14
|
+
@driver ||= Fluent::Test::Driver::Output.new(Sumologic).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_configure
|
18
|
+
config = %{
|
19
|
+
endpoint https://SUMOLOGIC_URL
|
20
|
+
log_format text
|
21
|
+
log_key LOG_KEY
|
22
|
+
source_category SOURCE_CATEGORY
|
23
|
+
source_name SOURCE_NAME
|
24
|
+
source_name_key SOURCE_NAME_KEY
|
25
|
+
source_host SOURCE_HOST
|
26
|
+
verify_ssl false
|
27
|
+
open_timeout 10
|
28
|
+
}
|
29
|
+
instance = driver(config).instance
|
30
|
+
|
31
|
+
assert_equal instance.endpoint, 'https://SUMOLOGIC_URL'
|
32
|
+
assert_equal instance.log_format, 'text'
|
33
|
+
assert_equal instance.log_key, 'LOG_KEY'
|
34
|
+
assert_equal instance.source_category, 'SOURCE_CATEGORY'
|
35
|
+
assert_equal instance.source_name, 'SOURCE_NAME'
|
36
|
+
assert_equal instance.source_name_key, 'SOURCE_NAME_KEY'
|
37
|
+
assert_equal instance.source_host, 'SOURCE_HOST'
|
38
|
+
assert_equal instance.verify_ssl, false
|
39
|
+
assert_equal instance.open_timeout, 10
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sumologic_output
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Adams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
55
69
|
description: Output plugin to SumoLogic HTTP Endpoint
|
56
70
|
email:
|
57
71
|
- stevezau@gmail.com
|
@@ -60,10 +74,14 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- Gemfile
|
63
78
|
- LICENSE
|
64
79
|
- README.md
|
80
|
+
- Rakefile
|
65
81
|
- fluent-plugin-sumologic_output.gemspec
|
66
82
|
- lib/fluent/plugin/out_sumologic.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/plugin/test_out_sumologic.rb
|
67
85
|
homepage: https://github.com/SumoLogic/fluentd-output-sumologic
|
68
86
|
licenses:
|
69
87
|
- Apache-2.0
|
@@ -88,4 +106,6 @@ rubygems_version: 2.6.12
|
|
88
106
|
signing_key:
|
89
107
|
specification_version: 4
|
90
108
|
summary: Output plugin to SumoLogic HTTP Endpoint
|
91
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- test/helper.rb
|
111
|
+
- test/plugin/test_out_sumologic.rb
|