diff --git a/.kitchen.yml b/.kitchen.yml index a4efa261..6919e62b 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -124,6 +124,21 @@ suites: user: someuser password: somepass +- name: datadog_etcd + run_list: + - recipe[datadog::etcd] + attributes: + datadog: + <<: *DATADOG + etcd: + instances: + - url: http://localhost:2379 + timeout: 5 + ssl_keyfile: /etc/etcd/ssl.key + ssl_certfile: /etc/etcd/ssl.crt + ssl_cert_validation: true + ssl_ca_certs: /etc/etcd/ca-certs.crt + - name: datadog_docker run_list: - recipe[datadog::docker] diff --git a/recipes/etcd.rb b/recipes/etcd.rb new file mode 100644 index 00000000..653f05cd --- /dev/null +++ b/recipes/etcd.rb @@ -0,0 +1,24 @@ +include_recipe 'datadog::dd-agent' + +# Monitor etcd +# +# API endpoint of your etcd instance +# - url: "https://server:port" +# Change the time to wait on an etcd API request +# timeout: 5 +# +# If certificate-based authentication of clients is enabled on your etcd server, +# specify the key file and the certificate file that the check should use. +# ssl_keyfile: /path/to/key/file +# ssl_certfile: /path/to/certificate/file +# +# Set to `false` to disable the validation of the server's SSL certificates (default: true). +# ssl_cert_validation: true +# +# If ssl_cert_validation is enabled, you can provide a custom file +# that lists trusted CA certificates (optional). +# ssl_ca_certs: /path/to/CA/certificate/file + +datadog_monitor 'etcd' do + instances node['datadog']['etcd']['instances'] +end diff --git a/templates/default/etcd.yaml.erb b/templates/default/etcd.yaml.erb new file mode 100644 index 00000000..4b8b56c4 --- /dev/null +++ b/templates/default/etcd.yaml.erb @@ -0,0 +1,12 @@ +instances: +<% @instances.each do |i| -%> + - url: <%= i['url'] %> + <% if i['timeout'] -%>timeout: <%= i['timeout'] %><% end -%> + <% if i['ssl_keyfile'] -%>ssl_keyfile: <%= i['ssl_keyfile'] %><% end -%> + <% if i['ssl_certfile'] -%>ssl_certfile: <%= i['ssl_certfile'] %><% end -%> + <% if i['ssl_cert_validation'] -%>ssl_cert_validation: <%= i['ssl_cert_validation'] %><% end -%> + <% if i['ssl_ca_certs'] -%>ssl_ca_certs: <%= i['ssl_ca_certs'] %><% end -%> +<% end -%> + +# Nothing to configure here +init_config: diff --git a/test/integration/datadog_etcd/serverspec/Gemfile b/test/integration/datadog_etcd/serverspec/Gemfile new file mode 100644 index 00000000..98a51a6c --- /dev/null +++ b/test/integration/datadog_etcd/serverspec/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'json_spec', '~> 1.1' diff --git a/test/integration/datadog_etcd/serverspec/etcd_spec.rb b/test/integration/datadog_etcd/serverspec/etcd_spec.rb new file mode 100644 index 00000000..1e9b95c3 --- /dev/null +++ b/test/integration/datadog_etcd/serverspec/etcd_spec.rb @@ -0,0 +1,37 @@ +# Encoding: utf-8 +require 'json_spec' +require 'serverspec' +require 'yaml' + +set :backend, :exec +set :path, '/sbin:/usr/local/sbin:$PATH' + +AGENT_CONFIG = '/etc/dd-agent/conf.d/etcd.yaml' + +describe service('datadog-agent') do + it { should be_running } +end + +describe file(AGENT_CONFIG) do + it { should be_a_file } + + it 'is valid yaml matching input values' do + generated = YAML.load_file(AGENT_CONFIG) + + expected = { + 'instances' => [ + { + 'url' => 'http://localhost:2379', + 'timeout' => 5, + 'ssl_keyfile' => '/etc/etcd/ssl.key', + 'ssl_certfile' => '/etc/etcd/ssl.crt', + 'ssl_cert_validation' => true, + 'ssl_ca_certs' => '/etc/etcd/ca-certs.crt' + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end