Skip to content

Commit 2bbddea

Browse files
committed
Add Elasticsearch shield support
1 parent e78402f commit 2bbddea

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

manifests/integrations/elasticsearch.pp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,31 @@
1313
# }
1414
#
1515
class datadog_agent::integrations::elasticsearch(
16-
$url = 'http://localhost:9200'
16+
$cluster_stats = false,
17+
$password = undef,
18+
$pending_task_stats = true,
19+
$pshard_stats = false,
20+
$ssl_cert = undef,
21+
$ssl_key = undef,
22+
$ssl_verify = true,
23+
$tags = [],
24+
$url = 'http://localhost:9200',
25+
$username = undef,
1726
) inherits datadog_agent::params {
1827
include datadog_agent
1928

29+
validate_array($tags)
30+
# $ssl_verify can be a bool or a string
31+
# https://github.com/DataDog/dd-agent/blob/master/checks.d/elastic.py#L454-L455
32+
if is_bool($ssl_verify) {
33+
validate_bool($ssl_verify)
34+
} elsif $ssl_verify != undef {
35+
validate_string($ssl_verify)
36+
validate_absolute_path($ssl_verify)
37+
}
38+
validate_bool($cluster_stats, $pending_task_stats, $pshard_stats)
39+
validate_string($password, $ssl_cert, $ssl_key, $url, $username)
40+
2041
file { "${datadog_agent::params::conf_dir}/elastic.yaml":
2142
ensure => file,
2243
owner => $datadog_agent::params::dd_user,

spec/classes/datadog_agent_integrations_elasticsearch_spec.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,36 @@
2222
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
2323

2424
context 'with default parameters' do
25-
it { should contain_file(conf_file).with_content(%r{url: http://localhost:9200}) }
25+
it { should contain_file(conf_file).with_content(%r{ - url: http://localhost:9200}) }
26+
it { should contain_file(conf_file).with_content(%r{ cluster_stats: false}) }
27+
it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) }
28+
it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) }
29+
it { should_not contain_file(conf_file).with_content(%r{ username}) }
30+
it { should_not contain_file(conf_file).with_content(%r{ password}) }
31+
it { should_not contain_file(conf_file).with_content(%r{ ssl_verify}) }
32+
it { should_not contain_file(conf_file).with_content(%r{ ssl_cert}) }
33+
it { should_not contain_file(conf_file).with_content(%r{ ssl_key}) }
34+
it { should_not contain_file(conf_file).with_content(%r{ tags:}) }
2635
end
27-
28-
context 'with parameters set' do
36+
context 'with parameters set' do
2937
let(:params) {{
30-
url: 'http://foo:4242',
38+
password: 'password',
39+
pending_task_stats: false,
40+
url: 'https://foo:4242',
41+
username: 'username',
42+
ssl_cert: '/etc/ssl/certs/client.pem',
43+
ssl_key: '/etc/ssl/private/client.key',
44+
tags: ['tag1:key1'],
3145
}}
32-
it { should contain_file(conf_file).with_content(%r{http://foo:4242}) }
46+
it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) }
47+
it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) }
48+
it { should contain_file(conf_file).with_content(%r{ username: username}) }
49+
it { should contain_file(conf_file).with_content(%r{ password: password}) }
50+
it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) }
51+
it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) }
52+
it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) }
53+
it { should contain_file(conf_file).with_content(%r{ tags:}) }
54+
it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) }
3355
end
3456

3557
end

templates/agent-conf.d/elastic.yaml.erb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ init_config:
66

77
instances:
88
- url: <%= @url %>
9+
<%- if @username -%>
10+
username: <%= @username %>
11+
<%- end -%>
12+
<%- if @password -%>
13+
password: <%= @password %>
14+
<%- end -%>
15+
cluster_stats: <%= @cluster_stats %>
16+
pshard_stats: <%= @pshard_stats %>
17+
pending_task_stats: <%= @pending_task_stats %>
18+
<%- if @url.match(/^https/) -%>
19+
ssl_verify: <%= @ssl_verify %>
20+
<%- end -%>
21+
<%- if @ssl_cert -%>
22+
ssl_cert: <%= @ssl_cert %>
23+
<%- end -%>
24+
<%- if @ssl_key -%>
25+
ssl_key: <%= @ssl_key %>
26+
<%- end -%>
27+
<%- unless @tags.empty? -%>
28+
tags:
29+
<%- @tags.each do |tag| -%>
30+
- <%= tag %>
31+
<%- end -%>
32+
<%- end -%>

0 commit comments

Comments
 (0)