diff --git a/manifests/integrations/elasticsearch.pp b/manifests/integrations/elasticsearch.pp index bbfa3c91..6ad46255 100644 --- a/manifests/integrations/elasticsearch.pp +++ b/manifests/integrations/elasticsearch.pp @@ -9,9 +9,20 @@ # Sample Usage: # # class { 'datadog_agent::integrations::elasticsearch' : -# url => "http://localhost:9201" +# instances => [{ +# url => "http://localhost:9201" +# }, +# { +# url => "http://elastic.acme.com:9201" +# }] # } # +# Or for a single instance: +# +# class { 'datadog_agent::integrations::elasticsearch' : +# url => "http://localhost:9201" +# } +# class datadog_agent::integrations::elasticsearch( $cluster_stats = false, $password = undef, @@ -23,6 +34,7 @@ $tags = [], $url = 'http://localhost:9200', $username = undef, + $instances = undef ) inherits datadog_agent::params { include datadog_agent @@ -38,6 +50,25 @@ validate_bool($cluster_stats, $pending_task_stats, $pshard_stats) validate_string($password, $ssl_cert, $ssl_key, $url, $username) + if !$instances and $url { + $_instances = [{ + 'cluster_stats' => $cluster_stats, + 'password' => $password, + 'pending_task_stats' => $pending_task_stats, + 'pshard_stats' => $pshard_stats, + 'ssl_cert' => $ssl_cert, + 'ssl_key' => $ssl_key, + 'ssl_verify' => $ssl_verify, + 'tags' => $tags, + 'url' => $url, + 'username' => $username + }] + } elsif !$instances { + $_instances = [] + } else { + $_instances = $instances + } + file { "${datadog_agent::params::conf_dir}/elastic.yaml": ensure => file, owner => $datadog_agent::params::dd_user, diff --git a/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb index 84edf3b3..1cd7c0d2 100644 --- a/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb +++ b/spec/classes/datadog_agent_integrations_elasticsearch_spec.rb @@ -33,7 +33,8 @@ it { should_not contain_file(conf_file).with_content(%r{ ssl_key}) } it { should_not contain_file(conf_file).with_content(%r{ tags:}) } end -context 'with parameters set' do + + context 'with parameters set' do let(:params) {{ password: 'password', pending_task_stats: false, @@ -54,4 +55,59 @@ it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } end + context 'with multiple instances set' do + let(:params) { + { + instances: [ + { + 'cluster_stats' => true, + 'password' => 'password', + 'pending_task_stats' => false, + 'pshard_stats' => false, + 'url' => 'https://foo:4242', + 'username' => 'username', + 'ssl_verify' => true, + 'ssl_cert' => '/etc/ssl/certs/client.pem', + 'ssl_key' => '/etc/ssl/private/client.key', + 'tags' => ['tag1:key1'], + }, + { + 'cluster_stats' => true, + 'password' => 'password_2', + 'pending_task_stats' => true, + 'pshard_stats' => false, + 'url' => 'https://bar:2424', + 'username' => 'username_2', + 'ssl_verify' => false, + 'ssl_cert' => '/etc/ssl/certs/client.pem', + 'ssl_key' => '/etc/ssl/private/client.key', + 'tags' => ['tag2:key2'], + } + ] + } + } + it { should contain_file(conf_file).with_content(%r{instances:}) } + it { should contain_file(conf_file).with_content(%r{ - url: https://foo:4242}) } + it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ username: username}) } + it { should contain_file(conf_file).with_content(%r{ password: password}) } + it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_verify: true}) } + it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } + it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag1:key1}) } + it { should contain_file(conf_file).with_content(%r{ - url: https://bar:2424}) } + it { should contain_file(conf_file).with_content(%r{ cluster_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ pending_task_stats: true}) } + it { should contain_file(conf_file).with_content(%r{ username: username_2}) } + it { should contain_file(conf_file).with_content(%r{ password: password_2}) } + it { should contain_file(conf_file).with_content(%r{ pshard_stats: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_verify: false}) } + it { should contain_file(conf_file).with_content(%r{ ssl_cert: /etc/ssl/certs/client.pem}) } + it { should contain_file(conf_file).with_content(%r{ ssl_key: /etc/ssl/private/client.key}) } + it { should contain_file(conf_file).with_content(%r{ tags:}) } + it { should contain_file(conf_file).with_content(%r{ - tag2:key2}) } + end end diff --git a/templates/agent-conf.d/elastic.yaml.erb b/templates/agent-conf.d/elastic.yaml.erb index c976915d..1f917f41 100644 --- a/templates/agent-conf.d/elastic.yaml.erb +++ b/templates/agent-conf.d/elastic.yaml.erb @@ -5,28 +5,30 @@ init_config: instances: - - url: <%= @url %> -<%- if @username -%> - username: <%= @username %> +<%- (Array(@_instances)).each do |instance| -%> + - url: <%= instance['url'] %> +<%- if instance['username'] && instance['username'] != :undef -%> + username: <%= instance['username'] %> <%- end -%> -<%- if @password -%> - password: <%= @password %> +<%- if instance['password'] && instance['password'] != :undef -%> + password: <%= instance['password'] %> <%- end -%> - cluster_stats: <%= @cluster_stats %> - pshard_stats: <%= @pshard_stats %> - pending_task_stats: <%= @pending_task_stats %> -<%- if @url.match(/^https/) -%> - ssl_verify: <%= @ssl_verify %> + cluster_stats: <%= instance['cluster_stats'] %> + pshard_stats: <%= instance['pshard_stats'] %> + pending_task_stats: <%= instance['pending_task_stats'] %> +<%- if instance['url'].match(/^https/) -%> + ssl_verify: <%= instance['ssl_verify'] %> <%- end -%> -<%- if @ssl_cert -%> - ssl_cert: <%= @ssl_cert %> +<%- if instance['ssl_cert'] && instance['ssl_cert'] != :undef -%> + ssl_cert: <%= instance['ssl_cert'] %> <%- end -%> -<%- if @ssl_key -%> - ssl_key: <%= @ssl_key %> +<%- if instance['ssl_key'] && instance['ssl_key'] != :undef -%> + ssl_key: <%= instance['ssl_key'] %> <%- end -%> -<%- unless @tags.empty? -%> +<%- unless instance['tags'].empty? -%> tags: - <%- @tags.each do |tag| -%> + <%- instance['tags'].each do |tag| -%> - <%= tag %> <%- end -%> <%- end -%> +<%- end -%>