fluent-plugin-scalyr 0.8.10 → 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +20 -1
- data/Rakefile +9 -6
- data/VERSION +1 -1
- data/fluent-plugin-scalyr.gemspec +11 -7
- data/lib/fluent/plugin/out_scalyr.rb +185 -215
- data/lib/fluent/plugin/{scalyr-exceptions.rb → scalyr_exceptions.rb} +2 -2
- data/test/helper.rb +12 -6
- data/test/test_config.rb +19 -30
- data/test/test_events.rb +156 -154
- data/test/test_handle_response.rb +34 -35
- data/test/test_ssl_verify.rb +101 -10
- metadata +47 -33
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# Scalyr Output Plugin for Fluentd
|
3
5
|
#
|
@@ -15,76 +17,73 @@
|
|
15
17
|
# See the License for the specific language governing permissions and
|
16
18
|
# limitations under the License.
|
17
19
|
|
20
|
+
require "helper"
|
21
|
+
require "flexmock/test_unit"
|
18
22
|
|
19
|
-
|
20
|
-
require 'flexmock/test_unit'
|
21
|
-
|
23
|
+
# rubocop:disable Layout/LineLength
|
22
24
|
class HandleResponseTest < Scalyr::ScalyrOutTest
|
23
|
-
|
24
25
|
def test_handle_response_missing_status
|
25
26
|
d = create_driver
|
26
|
-
response = flexmock(
|
27
|
-
exception = assert_raise(
|
28
|
-
d.instance.handle_response(
|
27
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message" }')
|
28
|
+
exception = assert_raise(Scalyr::ServerError, "Server error not raised for missing status") {
|
29
|
+
d.instance.handle_response(response)
|
29
30
|
}
|
30
31
|
|
31
|
-
assert_equal(
|
32
|
+
assert_equal("JSON response does not contain status message", exception.message)
|
32
33
|
end
|
33
34
|
|
34
35
|
def test_handle_response_discard_buffer
|
35
36
|
d = create_driver
|
36
|
-
response = flexmock(
|
37
|
-
logger = flexmock(
|
38
|
-
logger.should_receive(
|
39
|
-
assert_nothing_raised(
|
40
|
-
d.instance.handle_response(
|
37
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/server/discardBuffer" }')
|
38
|
+
logger = flexmock($log)
|
39
|
+
logger.should_receive(:warn).once.with(/buffer dropped/i)
|
40
|
+
assert_nothing_raised(Scalyr::ServerError, Scalyr::ClientError, "Nothing should be raised when discarding the buffer") {
|
41
|
+
d.instance.handle_response(response)
|
41
42
|
}
|
42
|
-
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_handle_response_unknown_error
|
46
46
|
d = create_driver
|
47
|
-
response = flexmock(
|
48
|
-
exception = assert_raise(
|
49
|
-
d.instance.handle_response(
|
47
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/other" }')
|
48
|
+
exception = assert_raise(Scalyr::ServerError, "Server error not raised for error status") {
|
49
|
+
d.instance.handle_response(response)
|
50
50
|
}
|
51
|
-
assert_equal(
|
51
|
+
assert_equal("error/other", exception.message)
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_handle_response_client_error
|
55
55
|
d = create_driver
|
56
|
-
response = flexmock(
|
57
|
-
exception = assert_raise(
|
58
|
-
d.instance.handle_response(
|
56
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/client/test" }')
|
57
|
+
exception = assert_raise(Scalyr::ClientError, "Client error not raised for error status") {
|
58
|
+
d.instance.handle_response(response)
|
59
59
|
}
|
60
|
-
assert_equal(
|
60
|
+
assert_equal("error/client/test", exception.message)
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_handle_response_server_error
|
64
64
|
d = create_driver
|
65
|
-
response = flexmock(
|
66
|
-
exception = assert_raise(
|
67
|
-
d.instance.handle_response(
|
65
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/server/test" }')
|
66
|
+
exception = assert_raise(Scalyr::ServerError, "Server error not raised for error status") {
|
67
|
+
d.instance.handle_response(response)
|
68
68
|
}
|
69
|
-
assert_equal(
|
69
|
+
assert_equal("error/server/test", exception.message)
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_handle_response_code_4xx
|
73
73
|
d = create_driver
|
74
|
-
response = flexmock(
|
75
|
-
exception = assert_raise(
|
76
|
-
d.instance.handle_response(
|
74
|
+
response = flexmock(Net::HTTPResponse, code: "404", body: '{ "status":"error/server/fileNotFound" }')
|
75
|
+
exception = assert_raise(Scalyr::Client4xxError, "No 4xx exception raised") {
|
76
|
+
d.instance.handle_response(response)
|
77
77
|
}
|
78
|
-
assert_equal(
|
78
|
+
assert_equal("error/server/fileNotFound", exception.message)
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_handle_response_code_200
|
82
82
|
d = create_driver
|
83
|
-
response = flexmock(
|
84
|
-
|
85
|
-
d.instance.handle_response(
|
83
|
+
response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
|
84
|
+
assert_nothing_raised(Scalyr::ServerError, Scalyr::ClientError, "Error raised on success") {
|
85
|
+
d.instance.handle_response(response)
|
86
86
|
}
|
87
87
|
end
|
88
|
-
|
89
88
|
end
|
90
|
-
|
89
|
+
# rubocop:enable Layout/LineLength
|
data/test/test_ssl_verify.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# Scalyr Output Plugin for Fluentd
|
3
5
|
#
|
@@ -15,21 +17,110 @@
|
|
15
17
|
# See the License for the specific language governing permissions and
|
16
18
|
# limitations under the License.
|
17
19
|
|
18
|
-
|
19
|
-
require
|
20
|
+
require "helper"
|
21
|
+
require "flexmock/test_unit"
|
20
22
|
|
21
23
|
class SSLVerifyTest < Scalyr::ScalyrOutTest
|
24
|
+
def test_good_ssl_certificates
|
25
|
+
d = create_driver CONFIG
|
26
|
+
|
27
|
+
d.run(default_tag: "test") do
|
28
|
+
time = event_time("2015-04-01 10:00:00 UTC")
|
29
|
+
d.feed(time, {"a" => 1})
|
30
|
+
|
31
|
+
logger = flexmock($log)
|
32
|
+
logger.should_receive(:warn).times(0).with(/certificate verification failed/i)
|
33
|
+
logger.should_receive(:warn).times(0).with(/certificate verify failed/i)
|
34
|
+
logger.should_receive(:warn).once.with(/discarding buffer/i)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_no_ssl_certificates
|
39
|
+
d = create_driver %(
|
40
|
+
api_write_token test_token
|
41
|
+
)
|
42
|
+
|
43
|
+
d.run(default_tag: "test") do
|
44
|
+
time = event_time("2015-04-01 10:00:00 UTC")
|
45
|
+
d.feed(time, {"a" => 1})
|
46
|
+
|
47
|
+
logger = flexmock($log)
|
48
|
+
logger.should_receive(:warn).times(0).with(/certificate verification failed/i)
|
49
|
+
logger.should_receive(:warn).times(0).with(/certificate verify failed/i)
|
50
|
+
logger.should_receive(:warn).once.with(/discarding buffer/i)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
22
54
|
def test_bad_ssl_certificates
|
23
|
-
d = create_driver CONFIG +
|
55
|
+
d = create_driver CONFIG + "ssl_ca_bundle_path /home/invalid"
|
56
|
+
|
57
|
+
d.run(default_tag: "test") do
|
58
|
+
time = event_time("2015-04-01 10:00:00 UTC")
|
59
|
+
d.feed(time, {"a" => 1})
|
60
|
+
|
61
|
+
logger = flexmock($log)
|
62
|
+
logger.should_receive(:warn).once.with(/certificate verification failed/i)
|
63
|
+
logger.should_receive(:warn).once.with(/certificate verify failed/i)
|
64
|
+
logger.should_receive(:warn).once.with(/discarding buffer/i)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_bad_system_ssl_certificates
|
69
|
+
`sudo mv #{OpenSSL::X509::DEFAULT_CERT_FILE} /tmp/system_cert.pem`
|
70
|
+
`sudo mv #{OpenSSL::X509::DEFAULT_CERT_DIR} /tmp/system_certs`
|
71
|
+
|
72
|
+
begin
|
73
|
+
d = create_driver %(
|
74
|
+
api_write_token test_token
|
75
|
+
)
|
76
|
+
|
77
|
+
d.run(default_tag: "test") do
|
78
|
+
time = event_time("2015-04-01 10:00:00 UTC")
|
79
|
+
d.feed(time, {"a" => 1})
|
80
|
+
|
81
|
+
logger = flexmock($log)
|
82
|
+
logger.should_receive(:warn).once.with(/certificate verification failed/i)
|
83
|
+
logger.should_receive(:warn).once.with(/certificate verify failed/i)
|
84
|
+
logger.should_receive(:warn).once.with(/discarding buffer/i)
|
85
|
+
end
|
86
|
+
ensure
|
87
|
+
`sudo mv /tmp/system_certs #{OpenSSL::X509::DEFAULT_CERT_DIR}`
|
88
|
+
`sudo mv /tmp/system_cert.pem #{OpenSSL::X509::DEFAULT_CERT_FILE}`
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_hostname_verification
|
93
|
+
agent_scalyr_com_ip = `dig +short agent.scalyr.com 2> /dev/null | tail -n 1 | tr -d "\n"`
|
94
|
+
if agent_scalyr_com_ip.empty?
|
95
|
+
agent_scalyr_com_ip = `getent hosts agent.scalyr.com \
|
96
|
+
| awk '{ print $1 }' | tail -n 1 | tr -d "\n"`
|
97
|
+
end
|
98
|
+
mock_host = "invalid.mitm.should.fail.test.agent.scalyr.com"
|
99
|
+
etc_hosts_entry = "#{agent_scalyr_com_ip} #{mock_host}"
|
100
|
+
hosts_bkp = `sudo cat /etc/hosts`
|
101
|
+
hosts_bkp = hosts_bkp.chomp
|
102
|
+
# Add mock /etc/hosts entry and config scalyr_server entry
|
103
|
+
`echo "#{etc_hosts_entry}" | sudo tee -a /etc/hosts`
|
24
104
|
|
25
|
-
|
26
|
-
|
105
|
+
begin
|
106
|
+
d = create_driver %(
|
107
|
+
api_write_token test_token
|
108
|
+
scalyr_server https://invalid.mitm.should.fail.test.agent.scalyr.com:443
|
109
|
+
)
|
27
110
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
logger.should_receive( :warn ).with( /discarding buffer/i )
|
111
|
+
d.run(default_tag: "test") do
|
112
|
+
time = event_time("2015-04-01 10:00:00 UTC")
|
113
|
+
d.feed(time, {"a" => 1})
|
32
114
|
|
33
|
-
|
115
|
+
logger = flexmock($log)
|
116
|
+
logger.should_receive(:warn).once.with(/certificate verification failed/i)
|
117
|
+
logger.should_receive(:warn).once.with(/certificate verify failed/i)
|
118
|
+
logger.should_receive(:warn).once.with(/discarding buffer/i)
|
119
|
+
end
|
120
|
+
ensure
|
121
|
+
# Clean up the hosts file
|
122
|
+
`sudo truncate -s 0 /etc/hosts`
|
123
|
+
`echo "#{hosts_bkp}" | sudo tee -a /etc/hosts`
|
124
|
+
end
|
34
125
|
end
|
35
126
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-scalyr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Imron Alston
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.9.25
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.9.25
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: fluentd
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,20 +44,6 @@ dependencies:
|
|
30
44
|
- - "<"
|
31
45
|
- !ruby/object:Gem::Version
|
32
46
|
version: '2'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: ffi
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - '='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 1.9.25
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - '='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.9.25
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rbzip2
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,61 +73,75 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: bundler
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '1.9'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '1.9'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: flexmock
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '1.2'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '1.2'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: rake
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '0.9'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '0.9'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: rubocop
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
123
|
+
version: '0.4'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
130
|
+
version: '0.4'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: test-unit
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.0'
|
131
145
|
description: Sends log data collected by fluentd to Scalyr (http://www.scalyr.com)
|
132
146
|
email: imron@scalyr.com
|
133
147
|
executables: []
|
@@ -143,7 +157,7 @@ files:
|
|
143
157
|
- fluent-plugin-scalyr.gemspec
|
144
158
|
- fluent.conf.sample
|
145
159
|
- lib/fluent/plugin/out_scalyr.rb
|
146
|
-
- lib/fluent/plugin/
|
160
|
+
- lib/fluent/plugin/scalyr_exceptions.rb
|
147
161
|
- test/helper.rb
|
148
162
|
- test/test_config.rb
|
149
163
|
- test/test_events.rb
|
@@ -168,13 +182,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
182
|
- !ruby/object:Gem::Version
|
169
183
|
version: '0'
|
170
184
|
requirements: []
|
171
|
-
rubygems_version: 3.0.
|
185
|
+
rubygems_version: 3.0.3
|
172
186
|
signing_key:
|
173
187
|
specification_version: 4
|
174
188
|
summary: Scalyr plugin for fluentd
|
175
189
|
test_files:
|
190
|
+
- test/helper.rb
|
191
|
+
- test/test_events.rb
|
176
192
|
- test/test_handle_response.rb
|
177
|
-
- test/test_ssl_verify.rb
|
178
193
|
- test/test_config.rb
|
179
|
-
- test/
|
180
|
-
- test/helper.rb
|
194
|
+
- test/test_ssl_verify.rb
|