From c0d77b86175a5894aae68097f03571a2c81a683a Mon Sep 17 00:00:00 2001 From: Zac Shenker Date: Fri, 25 Sep 2015 15:18:32 -0700 Subject: [PATCH 1/3] Adding recipe and template for etcd integration. --- recipes/etcd.rb | 24 ++++++++++++++++++++++++ templates/default/etcd.yaml.erb | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 recipes/etcd.rb create mode 100644 templates/default/etcd.yaml.erb 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..ebc70578 --- /dev/null +++ b/templates/default/etcd.yaml.erb @@ -0,0 +1,12 @@ +instances: +<% @instances.each do |i| -%> + - url: <%= i['url'] %> + <% if i['timeout'] -%>timout: <%= 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: From 7eaf1b4d7b0bd4509571c15238fca4a625384e41 Mon Sep 17 00:00:00 2001 From: Darron Froese Date: Tue, 29 Sep 2015 17:36:01 -0600 Subject: [PATCH 2/3] Fix typo in template. --- templates/default/etcd.yaml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/default/etcd.yaml.erb b/templates/default/etcd.yaml.erb index ebc70578..4b8b56c4 100644 --- a/templates/default/etcd.yaml.erb +++ b/templates/default/etcd.yaml.erb @@ -1,7 +1,7 @@ instances: <% @instances.each do |i| -%> - url: <%= i['url'] %> - <% if i['timeout'] -%>timout: <%= i['timeout'] %><% end -%> + <% 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 -%> From a09f721331288122597b73036a57158aa984469e Mon Sep 17 00:00:00 2001 From: Darron Froese Date: Tue, 29 Sep 2015 17:36:18 -0600 Subject: [PATCH 3/3] Add TestKitchen test. --- .kitchen.yml | 15 ++++++++ .../datadog_etcd/serverspec/Gemfile | 3 ++ .../datadog_etcd/serverspec/etcd_spec.rb | 37 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/integration/datadog_etcd/serverspec/Gemfile create mode 100644 test/integration/datadog_etcd/serverspec/etcd_spec.rb 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/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