Skip to content

Commit 61ccbf5

Browse files
committed
[XPACK] Adds logstash API
1 parent 5a0aae4 commit 61ccbf5

File tree

8 files changed

+328
-0
lines changed

8 files changed

+328
-0
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def snapshot_lifecycle_management
156156
def text_structure
157157
@text_structure ||= xpack.text_structure
158158
end
159+
160+
def logstash
161+
@logstash ||= xpack.logstash
162+
end
159163
end
160164
end
161165
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Logstash
22+
module Actions
23+
# Deletes Logstash Pipelines used by Central Management
24+
#
25+
# @option arguments [String] :id The ID of the Pipeline
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/logstash-api-delete-pipeline.html
29+
#
30+
def delete_pipeline(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_DELETE
40+
path = "_logstash/pipeline/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Logstash
22+
module Actions
23+
# Retrieves Logstash Pipelines used by Central Management
24+
#
25+
# @option arguments [String] :id A comma-separated list of Pipeline IDs
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/logstash-api-get-pipeline.html
29+
#
30+
def get_pipeline(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_GET
40+
path = "_logstash/pipeline/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Logstash
22+
module Actions
23+
# Adds and updates Logstash Pipelines used for Central Management
24+
#
25+
# @option arguments [String] :id The ID of the Pipeline
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
# @option arguments [Hash] :body The Pipeline to add or update (*Required*)
28+
#
29+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/logstash-api-put-pipeline.html
30+
#
31+
def put_pipeline(arguments = {})
32+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
33+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
34+
35+
headers = arguments.delete(:headers) || {}
36+
37+
arguments = arguments.clone
38+
39+
_id = arguments.delete(:id)
40+
41+
method = Elasticsearch::API::HTTP_PUT
42+
path = "_logstash/pipeline/#{Elasticsearch::API::Utils.__listify(_id)}"
43+
params = {}
44+
45+
body = arguments[:body]
46+
perform_request(method, path, params, body, headers).body
47+
end
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Logstash
22+
module Actions; end
23+
24+
class LogstashClient
25+
include Elasticsearch::API::Common::Client, Elasticsearch::API::Common::Client::Base, Logstash::Actions
26+
end
27+
28+
def logstash
29+
@logstash ||= LogstashClient.new(self)
30+
end
31+
end
32+
end
33+
end
34+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackLogstashDeletePipelineTest < Minitest::Test
23+
context 'Logstash: Delete Pipeline' do
24+
subject { FakeClient.new }
25+
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal 'DELETE', method
29+
assert_equal '_logstash/pipeline/foo', url
30+
assert_equal({}, params)
31+
assert_nil body
32+
true
33+
end.returns(FakeResponse.new)
34+
35+
subject.xpack.logstash.delete_pipeline(id: 'foo')
36+
end
37+
38+
should 'raise argument error without id' do
39+
assert_raises ArgumentError do
40+
subject.xpack.logstash.delete_pipeline
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackLogstashGetPipelineTest < Minitest::Test
23+
context 'Logstash: Get Pipeline' do
24+
subject { FakeClient.new }
25+
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal 'GET', method
29+
assert_equal '_logstash/pipeline/foo', url
30+
assert_equal({}, params)
31+
assert_nil body
32+
true
33+
end.returns(FakeResponse.new)
34+
35+
subject.xpack.logstash.get_pipeline(id: 'foo')
36+
end
37+
38+
should 'raise argument error without id' do
39+
assert_raises ArgumentError do
40+
subject.xpack.logstash.get_pipeline
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackLogstashPutPipelineTest < Minitest::Test
23+
context 'Logstash: Put Pipeline' do
24+
subject { FakeClient.new }
25+
26+
should 'perform correct request' do
27+
subject.expects(:perform_request).with do |method, url, params, body|
28+
assert_equal 'PUT', method
29+
assert_equal '_logstash/pipeline/foo', url
30+
assert_equal({}, params)
31+
assert_equal({}, body)
32+
true
33+
end.returns(FakeResponse.new)
34+
35+
subject.xpack.logstash.put_pipeline(id: 'foo', body: {})
36+
end
37+
38+
should 'raise argument error without body' do
39+
assert_raises ArgumentError do
40+
subject.xpack.logstash.put_pipeline(id: 'foo')
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)