fluent-plugin-vmware-log-intelligence 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,154 +1,154 @@
1
- # Copyright 2018 VMware, Inc.
2
- # SPDX-License-Identifier: MIT
3
-
4
- require 'helper'
5
- require 'yaml'
6
-
7
- class LogIntelligenceOutputTest < Test::Unit::TestCase
8
- def setup
9
- Fluent::Test.setup
10
- end
11
-
12
- def create_driver(conf)
13
- Fluent::Test::Driver::Output.new(Fluent::Plugin::LogIntelligenceOutput).configure(conf)
14
- end
15
-
16
- def test_configure
17
- config = %[
18
- endpoint_url http://localhost:9200/li
19
- ]
20
-
21
- instance = create_driver(config).instance
22
- assert_equal 'http://localhost:9200/li', instance.endpoint_url
23
- assert_equal '', instance.instance_eval { @http_retry_statuses }
24
- assert_equal [], instance.instance_eval { @statuses }
25
- assert_equal 60, instance.instance_eval { @read_timeout }
26
- assert_equal 60, instance.instance_eval { @open_timeout }
27
- assert_equal({}, instance.instance_eval { @headers })
28
- end
29
-
30
- def test_full_configure
31
- config = %[
32
- @type http_buffered
33
- endpoint_url https://local.endpoint:3000/dummy/xyz
34
- verify_ssl false
35
- <headers>
36
- Content-Type application/json
37
- Authorization Bearer EdaNNN68y
38
- structure simple
39
- format syslog
40
- </headers>
41
- <buffer>
42
- chunk_limit_records 3
43
- flush_interval 12s
44
- retry_max_times 3
45
- </buffer>
46
- ]
47
-
48
- instance = create_driver(config).instance
49
- assert_equal 'https://local.endpoint:3000/dummy/xyz', instance.endpoint_url
50
- assert_equal '', instance.http_retry_statuses
51
- assert_equal [], instance.instance_eval { @statuses }
52
- assert_equal 60, instance.read_timeout
53
- assert_equal 60, instance.open_timeout
54
- assert_equal({
55
- "Authorization"=>"Bearer EdaNNN68y",
56
- "Content-Type"=>"application/json",
57
- "structure"=>"simple",
58
- "format"=>"syslog"}, instance.instance_eval { @headers })
59
- end
60
-
61
- def test_invalid_endpoint
62
- assert_raise Fluent::ConfigError do
63
- create_driver('endpoint_url \\@3')
64
- end
65
-
66
- assert_raise Fluent::ConfigError do
67
- create_driver('endpoint_url google.com')
68
- end
69
- end
70
-
71
- def test_json_with_special_char1
72
- $log = Logger.new(STDOUT)
73
- $log.level = Logger::DEBUG
74
- input = {"host" => "192.168.0.1", "log" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 822.573\xC2\xB5s)"}
75
- output = [{"host" => "192.168.0.1", "text" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 822.573\xC2\xB5s)"}]
76
- $log.debug("INPUT: #{input}")
77
- $log.debug("OUTPUT: #{output}")
78
- verify_write(input, output)
79
- end
80
-
81
- def test_json_with_special_char2
82
- $log = Logger.new(STDOUT)
83
- $log.level = Logger::DEBUG
84
- input = {"host" => "192.168.0.1", "log" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 678.559µs)"}
85
- output = [{"host" => "192.168.0.1", "text" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 678.559µs)"}]
86
- $log.debug("INPUT: #{input}")
87
- $log.debug("OUTPUT: #{output}")
88
- verify_write(input, output)
89
- end
90
-
91
- def test_json_with_log
92
- input = {"host" => "192.168.0.1", "log" => "machine reboot"}
93
- output = [{"host" => "192.168.0.1", "text" => "machine reboot"}]
94
- verify_write(input, output)
95
- end
96
-
97
- def test_json_with_msg
98
- input = {"host" => "192.168.0.1", "msg" => "machine reboot"}
99
- output = [{"host" => "192.168.0.1", "text" => "machine reboot"}]
100
- verify_write(input, output)
101
- end
102
-
103
- def test_nested_json
104
- input = {"host" => "192.168.0.1", "properties" => {"type" => "windows"}, "msg" => "machine reboot"}
105
- output = [{"host" => "192.168.0.1", "properties_type" => "windows", "text" => "machine reboot"}]
106
- verify_write(input, output)
107
- end
108
-
109
- def test_nested_json_with_log
110
- input = {"host" => "192.168.0.1", "properties" => {"type" => "windows"}, "message" => "machine reboot"}
111
- output = [{"host" => "192.168.0.1", "properties_type" => "windows", "text" => "machine reboot"}]
112
- verify_write(input, output)
113
- end
114
-
115
- def test_json_with_new_line
116
- input = {"host" => "192.168.0.1", "log" => "\\n"}
117
- output = [{}]
118
- verify_write(input, output)
119
- end
120
-
121
- def test_json_with_multiple_log_formats
122
- input = {"host" => "192.168.0.1", "log" => "custom log:1", "message" => "custom message:2", "msg" => "custom msg:3"}
123
- output = [{"host" => "192.168.0.1", "text" => "custom log:1 custom message:2 custom msg:3"}]
124
- verify_write(input, output)
125
- end
126
-
127
- # For any null values, its key and values are not being populated to output.
128
- def test_json_with_null_value
129
- input = {"host" => "192.168.0.1", "source" => nil, "log" => "abc"}
130
- output = [{"host" => "192.168.0.1", "text" => "abc"}]
131
- verify_write(input, output)
132
- end
133
-
134
- # like '/', '-', '\', '.', etc. replace with '_'
135
- def test_json_with_sperators
136
- input = {"host" => "192.168.0.1", "/properties" => {"type-" => "windows"}, "msg" => "123"}
137
- output = [{"host" => "192.168.0.1", "_properties_type_" => "windows", "text" => "123"}]
138
- verify_write(input, output)
139
- end
140
-
141
- def verify_write(input, output)
142
- config = %[
143
- endpoint_url http://localhost:9200/li
144
- ]
145
- stub = stub_request(:post, "http://localhost:9200/li").with(body: output.to_json).
146
- to_return(status: 200, body: "", headers: {})
147
-
148
- driver = create_driver(config)
149
- driver.run(default_tag: 'test') do
150
- driver.feed(input)
151
- end
152
- assert_requested(stub)
153
- end
1
+ # Copyright 2018 VMware, Inc.
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ require 'helper'
5
+ require 'yaml'
6
+
7
+ class LogIntelligenceOutputTest < Test::Unit::TestCase
8
+ def setup
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ def create_driver(conf)
13
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::LogIntelligenceOutput).configure(conf)
14
+ end
15
+
16
+ def test_configure
17
+ config = %[
18
+ endpoint_url http://localhost:9200/li
19
+ ]
20
+
21
+ instance = create_driver(config).instance
22
+ assert_equal 'http://localhost:9200/li', instance.endpoint_url
23
+ assert_equal '', instance.instance_eval { @http_retry_statuses }
24
+ assert_equal [], instance.instance_eval { @statuses }
25
+ assert_equal 60, instance.instance_eval { @read_timeout }
26
+ assert_equal 60, instance.instance_eval { @open_timeout }
27
+ assert_equal({}, instance.instance_eval { @headers })
28
+ end
29
+
30
+ def test_full_configure
31
+ config = %[
32
+ @type http_buffered
33
+ endpoint_url https://local.endpoint:3000/dummy/xyz
34
+ verify_ssl false
35
+ <headers>
36
+ Content-Type application/json
37
+ Authorization Bearer EdaNNN68y
38
+ structure simple
39
+ format syslog
40
+ </headers>
41
+ <buffer>
42
+ chunk_limit_records 3
43
+ flush_interval 12s
44
+ retry_max_times 3
45
+ </buffer>
46
+ ]
47
+
48
+ instance = create_driver(config).instance
49
+ assert_equal 'https://local.endpoint:3000/dummy/xyz', instance.endpoint_url
50
+ assert_equal '', instance.http_retry_statuses
51
+ assert_equal [], instance.instance_eval { @statuses }
52
+ assert_equal 60, instance.read_timeout
53
+ assert_equal 60, instance.open_timeout
54
+ assert_equal({
55
+ "Authorization"=>"Bearer EdaNNN68y",
56
+ "Content-Type"=>"application/json",
57
+ "structure"=>"simple",
58
+ "format"=>"syslog"}, instance.instance_eval { @headers })
59
+ end
60
+
61
+ def test_invalid_endpoint
62
+ assert_raise Fluent::ConfigError do
63
+ create_driver('endpoint_url \\@3')
64
+ end
65
+
66
+ assert_raise Fluent::ConfigError do
67
+ create_driver('endpoint_url google.com')
68
+ end
69
+ end
70
+
71
+ def test_json_with_special_char1
72
+ $log = Logger.new(STDOUT)
73
+ $log.level = Logger::DEBUG
74
+ input = {"host" => "192.168.0.1", "log" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 822.573\xC2\xB5s)"}
75
+ output = [{"host" => "192.168.0.1", "text" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 822.573\xC2\xB5s)"}]
76
+ $log.debug("INPUT: #{input}")
77
+ $log.debug("OUTPUT: #{output}")
78
+ verify_write(input, output)
79
+ end
80
+
81
+ def test_json_with_special_char2
82
+ $log = Logger.new(STDOUT)
83
+ $log.level = Logger::DEBUG
84
+ input = {"host" => "192.168.0.1", "log" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 678.559µs)"}
85
+ output = [{"host" => "192.168.0.1", "text" => "2019-12-02 02:04:13.556787 I | mvcc: finished scheduled compaction at 2259 (took 678.559µs)"}]
86
+ $log.debug("INPUT: #{input}")
87
+ $log.debug("OUTPUT: #{output}")
88
+ verify_write(input, output)
89
+ end
90
+
91
+ def test_json_with_log
92
+ input = {"host" => "192.168.0.1", "log" => "machine reboot"}
93
+ output = [{"host" => "192.168.0.1", "text" => "machine reboot"}]
94
+ verify_write(input, output)
95
+ end
96
+
97
+ def test_json_with_msg
98
+ input = {"host" => "192.168.0.1", "msg" => "machine reboot"}
99
+ output = [{"host" => "192.168.0.1", "text" => "machine reboot"}]
100
+ verify_write(input, output)
101
+ end
102
+
103
+ def test_nested_json
104
+ input = {"host" => "192.168.0.1", "properties" => {"type" => "windows"}, "msg" => "machine reboot"}
105
+ output = [{"host" => "192.168.0.1", "properties_type" => "windows", "text" => "machine reboot"}]
106
+ verify_write(input, output)
107
+ end
108
+
109
+ def test_nested_json_with_log
110
+ input = {"host" => "192.168.0.1", "properties" => {"type" => "windows"}, "message" => "machine reboot"}
111
+ output = [{"host" => "192.168.0.1", "properties_type" => "windows", "text" => "machine reboot"}]
112
+ verify_write(input, output)
113
+ end
114
+
115
+ def test_json_with_new_line
116
+ input = {"host" => "192.168.0.1", "log" => "\\n"}
117
+ output = [{}]
118
+ verify_write(input, output)
119
+ end
120
+
121
+ def test_json_with_multiple_log_formats
122
+ input = {"host" => "192.168.0.1", "log" => "custom log:1", "message" => "custom message:2", "msg" => "custom msg:3"}
123
+ output = [{"host" => "192.168.0.1", "text" => "custom log:1 custom message:2 custom msg:3"}]
124
+ verify_write(input, output)
125
+ end
126
+
127
+ # For any null values, its key and values are not being populated to output.
128
+ def test_json_with_null_value
129
+ input = {"host" => "192.168.0.1", "source" => nil, "log" => "abc"}
130
+ output = [{"host" => "192.168.0.1", "text" => "abc"}]
131
+ verify_write(input, output)
132
+ end
133
+
134
+ # like '/', '-', '\', '.', etc. replace with '_'
135
+ def test_json_with_sperators
136
+ input = {"host" => "192.168.0.1", "/properties" => {"type-" => "windows"}, "msg" => "123"}
137
+ output = [{"host" => "192.168.0.1", "_properties_type_" => "windows", "text" => "123"}]
138
+ verify_write(input, output)
139
+ end
140
+
141
+ def verify_write(input, output)
142
+ config = %[
143
+ endpoint_url http://localhost:9200/li
144
+ ]
145
+ stub = stub_request(:post, "http://localhost:9200/li").with(body: output.to_json).
146
+ to_return(status: 200, body: "", headers: {})
147
+
148
+ driver = create_driver(config)
149
+ driver.run(default_tag: 'test') do
150
+ driver.feed(input)
151
+ end
152
+ assert_requested(stub)
153
+ end
154
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-vmware-log-intelligence
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Blagoev
@@ -231,7 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  - !ruby/object:Gem::Version
232
232
  version: '0'
233
233
  requirements: []
234
- rubygems_version: 3.1.4
234
+ rubyforge_project:
235
+ rubygems_version: 2.7.6
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: Fluentd buffered output plugin for VMware Log Intelligence