logstash-output-monasca_log_api 0.3.3 → 0.4

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.
@@ -1,16 +1,16 @@
1
- =begin
2
- Copyright 2015 FUJITSU LIMITED
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
- in compliance with the License. You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software distributed under the License
10
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
- or implied. See the License for the specific language governing permissions and limitations under
12
- the License.
13
- =end
1
+ # Copyright 2016 FUJITSU LIMITED
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
+ # use this file except in compliance with the License. You may obtain a copy of
5
+ # the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations under
13
+ # the License.
14
14
 
15
15
  # encoding: utf-8
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-monasca_log_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fujitsu Enabling Software Technology GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -16,12 +16,12 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '2.0'
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: '1.5'
24
+ version: '2.0'
25
25
  prerelease: false
26
26
  type: :runtime
27
27
  - !ruby/object:Gem::Dependency
@@ -30,12 +30,12 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.6
33
+ version: '2.0'
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: 0.1.6
38
+ version: '2.0'
39
39
  prerelease: false
40
40
  type: :runtime
41
41
  - !ruby/object:Gem::Dependency
@@ -44,12 +44,12 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.6
47
+ version: '2.0'
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - ~>
51
51
  - !ruby/object:Gem::Version
52
- version: 0.1.6
52
+ version: '2.0'
53
53
  prerelease: false
54
54
  type: :runtime
55
55
  - !ruby/object:Gem::Dependency
@@ -108,6 +108,20 @@ dependencies:
108
108
  version: '0.10'
109
109
  prerelease: false
110
110
  type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.37.2
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 0.37.2
123
+ prerelease: false
124
+ type: :development
111
125
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
112
126
  email: kamil.choroba@est.fujitsu.com,tomasz.trebski@ts.fujitsu.com
113
127
  executables: []
@@ -126,8 +140,8 @@ files:
126
140
  - spec/outputs/helper/url_helper_spec.rb
127
141
  - spec/outputs/keystone/keystone_client_spec.rb
128
142
  - spec/outputs/keystone/token_spec.rb
129
- - spec/outputs/monasca/monasca_api_client_spec.rb
130
- - spec/outputs/monasca_api_spec.rb
143
+ - spec/outputs/monasca/monasca_log_api_client_spec.rb
144
+ - spec/outputs/monasca_log_api_spec.rb
131
145
  - spec/outputs/spec_helper.rb
132
146
  homepage: https://github.com/FujitsuEnablingSoftwareTechnologyGmbH/logstash-output-monasca_api
133
147
  licenses:
@@ -159,6 +173,6 @@ test_files:
159
173
  - spec/outputs/helper/url_helper_spec.rb
160
174
  - spec/outputs/keystone/keystone_client_spec.rb
161
175
  - spec/outputs/keystone/token_spec.rb
162
- - spec/outputs/monasca/monasca_api_client_spec.rb
163
- - spec/outputs/monasca_api_spec.rb
176
+ - spec/outputs/monasca/monasca_log_api_client_spec.rb
177
+ - spec/outputs/monasca_log_api_spec.rb
164
178
  - spec/outputs/spec_helper.rb
@@ -1,105 +0,0 @@
1
- =begin
2
- Copyright 2015 FUJITSU LIMITED
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
- in compliance with the License. You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software distributed under the License
10
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
- or implied. See the License for the specific language governing permissions and limitations under
12
- the License.
13
- =end
14
-
15
- # encoding: utf-8
16
-
17
- require_relative '../spec_helper'
18
-
19
- describe LogStash::Outputs::Monasca::MonascaLogApiClient do
20
- let (:version) { "v2.0" }
21
-
22
- let (:auth_hash) { "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"domain\":{\"id\":\"1051bd27b9394120b26d8b08847325c0\"},\"name\":\"csi-operator\",\"password\":\"password\"}}},\"scope\":{\"project\":{\"domain\":{\"id\":\"1051bd27b9394120b26d8b08847325c0\"},\"name\":\"csi\"}}}}" }
23
-
24
- let (:ok_response) { stub_response(201, {:x_subject_token => "f8cdafb7dce94444ad781a53ddaff693"}, "{\"token\":{\"methods\":[\"password\"],\"roles\":[{\"id\":\"9fe2ff9ee4384b1894a90878d3e92bab\",\"name\":\"_member_\"},{\"id\":\"4e9ef1ffe73446c6b02f8fce0585c307\",\"name\":\"monasca-user\"}],\"expires_at\":\"2015-05-26T08:55:36.774122Z\",\"project\":{\"domain\":{\"id\":\"default\",\"name\":\"Default\"},\"id\":\"1051bd27b9394120b26d8b08847325c0\",\"name\":\"mini-mon\"},\"user\":{\"domain\":{\"id\":\"default\",\"name\":\"Default\"},\"id\":\"06ecc9869b8e4846b2fce3e5759ba4af\",\"name\":\"mini-mon\"},\"audit_ids\":[\"ORap7R56S2S-p6tFVeMkpg\"],\"issued_at\":\"2015-05-26T07:55:36.774146Z\"}}") }
25
-
26
- let (:failed_response) { stub_response(401, {:x_subject_token => "f8cdafb7dce94444ad781a53ddaff693"}, "{\"error\": {\"message\": \"Could not find project: f8cdafb7dce94444ad781a53ddaff693 (Disable debug mode to suppress these details.)\", \"code\": 401, \"title\": \"Unauthorized\"}}") }
27
-
28
- let (:data) { LogStash::Event.new({'message' => '2015-08-13 08:36:59,316 INFO monasca_notification.main Received signal 17, beginning graceful shutdown.',
29
- '@version' => '1',
30
- '@timestamp' => '2015-08-13T08:37:00.287Z',
31
- 'type' => 'notification',
32
- 'service' => 'notification',
33
- 'host' => 'monasca',
34
- 'path' => '/var/log/monasca/notification/notification.log'}) }
35
-
36
- let (:token) { LogStash::Outputs::Keystone::Token.new('abc', DateTime.now + Rational(5, 1440)) }
37
-
38
- let (:dimensions) { { 'hostname' => 'monasca' } }
39
-
40
- context 'when initializing' do
41
- it 'then it should register without exceptions' do
42
- expect {LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', version)}.to_not raise_error
43
- end
44
-
45
- it "returns a failure if arguments are missing" do
46
- # noinspection RubyArgCount
47
- expect {LogStash::Outputs::Monasca::MonascaLogApiClient.new}.to raise_exception(ArgumentError)
48
- end
49
- end
50
-
51
- context 'when sending events' do
52
- it 'with dimensions then it should request monasca' do
53
- expect_any_instance_of(RestClient::Resource).to receive(:post)
54
- .with(data, :x_auth_token => token, :content_type => 'application/json', :x_dimensions => dimensions)
55
- monasca_log_api_client = LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', version)
56
- monasca_log_api_client.send_event(nil, data, token, dimensions)
57
- end
58
-
59
- it 'without dimensions then it should request monasca' do
60
- expect_any_instance_of(RestClient::Resource).to receive(:post)
61
- .with(data, :x_auth_token => token, :content_type => 'application/json')
62
- monasca_log_api_client = LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', version)
63
- monasca_log_api_client.send_event(nil, data, token, nil)
64
- end
65
-
66
- it 'with application_type then it should request monasca with that value' do
67
- app_type = 'someapp'
68
- expect_any_instance_of(RestClient::Resource).to receive(:post)
69
- .with(data, :x_auth_token => token, :content_type => 'application/json', :x_application_type => app_type)
70
- monasca_log_api_client = LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', version)
71
- monasca_log_api_client.send_event(nil, data, token, nil, app_type)
72
- end
73
- end
74
-
75
- context 'when sending events failes' do
76
- it 'then it should be rescued and a warn log printed' do
77
- expect_any_instance_of(Cabin::Channel).to receive(:warn)
78
- monasca_log_api_client = LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', version)
79
- allow(monasca_log_api_client).to receive(:request).and_raise('an_error')
80
- monasca_log_api_client.send_event(nil, data, token, dimensions)
81
- end
82
- end
83
-
84
- context 'api version checking' do
85
-
86
- let (:supported_version) { %w(v2.0) }
87
-
88
- it 'should pass for correct version' do
89
- supported_version.each { |ver|
90
- expect {LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', ver)}.to_not raise_error
91
- }
92
- end
93
-
94
- it 'should pass if version does not specify v' do
95
- ver = '2.0'
96
- expect {LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', ver)}.to_not raise_error
97
- end
98
-
99
- it 'should fail for unsupported version' do
100
- ver = 'v4.0'
101
- expect {LogStash::Outputs::Monasca::MonascaLogApiClient.new('hostname:8080', ver)}.to raise_exception
102
- end
103
- end
104
-
105
- end
@@ -1,131 +0,0 @@
1
- =begin
2
- Copyright 2015 FUJITSU LIMITED
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
- in compliance with the License. You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software distributed under the License
10
- is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
- or implied. See the License for the specific language governing permissions and limitations under
12
- the License.
13
- =end
14
-
15
- # encoding: utf-8
16
-
17
- require_relative 'spec_helper'
18
-
19
- describe 'outputs/monasca_log_api' do
20
-
21
- let (:expected_application_type) { 'notification' }
22
-
23
- let (:event) { LogStash::Event.new({'message' => '2015-08-13 08:36:59,316 INFO monasca_notification.main Received signal 17, beginning graceful shutdown.',
24
- '@version' => '1',
25
- '@timestamp' => '2015-08-13T08:37:00.287Z',
26
- 'type' => expected_application_type,
27
- 'service' => 'notification',
28
- 'host' => 'monasca',
29
- 'path' => '/var/log/monasca/notification/notification.log'}) }
30
-
31
- let (:shutdown_event) { LogStash::SHUTDOWN }
32
-
33
- let (:simple_config) { {'monasca_log_api' => 'http://192.168.10.4:8080',
34
- 'keystone_api' => 'http://192.168.10.5:5000',
35
- 'domain_id' => 'abadcf984cf7401e88579d393317b0d9',
36
- 'username' => 'username',
37
- 'password' => 'password',
38
- 'project_name' => 'project_name'} }
39
-
40
- let (:token_id) { LogStash::Outputs::Keystone::Token.new('abc', DateTime.now + Rational(5, 1440)) }
41
-
42
- let (:old_token_id) { LogStash::Outputs::Keystone::Token.new('def', DateTime.now - Rational(5, 1440)) }
43
-
44
- context 'when initializing' do
45
- it 'then it should register without exceptions' do
46
- monasca_log_api = LogStash::Plugin.lookup('output', 'monasca_log_api').new(simple_config)
47
- allow(monasca_log_api).to receive(:get_token).and_return(token_id)
48
- expect {monasca_log_api.register}.to_not raise_error
49
- end
50
-
51
- it "should set a default application_type_key to \"type\"" do
52
- monasca_log_api = LogStash::Plugin.lookup('output', 'monasca_log_api').new(simple_config)
53
- expect(monasca_log_api.instance_variable_get('@application_type_key')).to eq("type")
54
- end
55
-
56
- it 'should use passed variable from config as application_type_key' do
57
- expected_key = 'mountain_dew'
58
- simple_config_copy = simple_config.clone
59
- simple_config_copy['application_type_key'] = expected_key
60
- monasca_log_api = LogStash::Plugin.lookup('output', 'monasca_log_api').new(simple_config_copy)
61
-
62
- expect(monasca_log_api.instance_variable_get('@application_type_key')).to eq(expected_key)
63
- end
64
-
65
- end
66
-
67
- context 'when receiving messages' do
68
- it 'then it should be send to monasca-log-api' do
69
- expect_any_instance_of(LogStash::Outputs::Monasca::MonascaLogApiClient).to receive(:send_event)
70
- .with(event, event.to_hash.to_json, token_id.id, nil, expected_application_type)
71
- monasca_log_api = LogStash::Outputs::MonascaLogApi.new(simple_config)
72
-
73
- allow(monasca_log_api).to receive(:get_token).and_return(token_id)
74
- allow(monasca_log_api).to receive(:get_application_type).and_call_original
75
-
76
- monasca_log_api.register
77
- monasca_log_api.receive(event)
78
- end
79
-
80
- it 'then it should check the token_id and renew it when its deprecated' do
81
- expect_any_instance_of(LogStash::Outputs::Keystone::KeystoneClient).to receive(:authenticate)
82
- .with(simple_config['domain_id'], simple_config['username'], simple_config['password'], simple_config['project_name'])
83
- monasca_log_api = LogStash::Outputs::MonascaLogApi.new(simple_config)
84
- allow(monasca_log_api).to receive(:get_token).and_return(old_token_id)
85
- monasca_log_api.register
86
- allow(monasca_log_api).to receive(:get_token).and_call_original
87
- allow(monasca_log_api).to receive(:send_event)
88
- monasca_log_api.receive(event)
89
- end
90
- end
91
-
92
- context 'when given dictionary as type in received message' do
93
- it 'should read application_type from it properly' do
94
- type_dict = {
95
- "application_type" => 'notification'
96
- }
97
- config = simple_config.merge({"application_type_key" => 'type.application_type'})
98
-
99
- event = LogStash::Event.new({"message" => '2015-08-13 08:36:59,316 INFO monasca_notification.main Received signal 17, beginning graceful shutdown.',
100
- "@version" => '1',
101
- "@timestamp" => '2015-08-13T08:37:00.287Z',
102
- "type" => type_dict,
103
- "service" => 'notification',
104
- "host" => 'monasca',
105
- "path" => '/var/log/monasca/notification/notification.log',
106
- })
107
- expect_any_instance_of(LogStash::Outputs::Monasca::MonascaLogApiClient).to receive(:send_event)
108
- .with(event, event.to_hash.to_json, token_id.id, nil, expected_application_type)
109
- monasca_log_api = LogStash::Outputs::MonascaLogApi.new(config)
110
-
111
- allow(monasca_log_api).to receive(:get_token).and_return(token_id)
112
- allow(monasca_log_api).to receive(:get_application_type).and_call_original
113
-
114
- monasca_log_api.register
115
- monasca_log_api.receive(event)
116
- end
117
-
118
- end
119
-
120
- context 'when receiving SHUTDOWN message' do
121
- it 'then it should be send to monasca-log-api' do
122
- expect_any_instance_of(LogStash::Outputs::Monasca::MonascaLogApiClient).to_not receive(:send_event)
123
- .with(shutdown_event, nil, token_id.id, nil)
124
- monasca_log_api = LogStash::Outputs::MonascaLogApi.new(simple_config)
125
- allow(monasca_log_api).to receive(:get_token).and_return(token_id)
126
- monasca_log_api.register
127
- monasca_log_api.receive(shutdown_event)
128
- end
129
- end
130
-
131
- end