diff --git a/.kitchen.yml b/.kitchen.yml index a4efa261..0552d9ca 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -98,6 +98,20 @@ suites: - dskDevice - ifName +- name: datadog_consul + run_list: + - recipe[datadog::consul] + attributes: + datadog: + <<: *DATADOG + consul: + instances: + - url: http://localhost:8500 + new_leader_checks: false + catalog_checks: false + service_whitelist: consul + tags: ['_default'] + - name: datadog_cassandra run_list: - recipe[datadog::cassandra] diff --git a/recipes/consul.rb b/recipes/consul.rb new file mode 100644 index 00000000..e73453f2 --- /dev/null +++ b/recipes/consul.rb @@ -0,0 +1,33 @@ +include_recipe 'datadog::dd-agent' + +# Monitor consul +# +# Assuming you have a consul instance on a given server, you will need to set +# up the following attributes at some point in your Chef run, in either +# a role or another cookbook. +# +# Note that the Agent only supports monitoring one Consul instance +# +# A few explanatory words: +# - `catalog_checks`: Whether to perform checks against the Consul service Catalog +# - `new_leader_checks`: Whether to enable new leader checks from this agent +# Note: if this is set on multiple agents in the same cluster +# you will receive one event per leader change per agent +# - `service_whitelist`: Services to restrict catalog querying to +# The default settings query up to 50 services. So if you have more than +# this many in your Consul service catalog, you will want to fill in the +# whitelist +# +# node['datadog']['consul']['instances'] = [ +# { +# 'url' => 'http://localhost:8500', +# 'new_leader_checks' => false, +# 'catalog_checks' => false, +# 'service_whitelist' => [], +# 'tags' => [node.chef_environment] +# } +# ] + +datadog_monitor 'consul' do + instances node['datadog']['consul']['instances'] +end diff --git a/templates/default/consul.yaml.erb b/templates/default/consul.yaml.erb new file mode 100644 index 00000000..3bfb784e --- /dev/null +++ b/templates/default/consul.yaml.erb @@ -0,0 +1,22 @@ +instances: +<% @instances.each do |i| -%> + - url: <%= i['url'] %> + <% unless i['new_leader_checks'].nil? %> + new_leader_checks: <%= i['new_leader_checks'] %> + <% end %> + <% unless i['catalog_checks'].nil? %> + catalog_checks: <%= i['catalog_checks'] %> + <% end %> + <% unless i['service_whitelist'].nil? %> + service_whitelist: <%= i['service_whitelist'] %> + <% end %> + <% if i.key?('tags') -%> + tags: + <% i['tags'].each do |t| -%> + - <%= t %> + <% end -%> + <% end -%> +<% end -%> + +# Nothing to configure here +init_config: diff --git a/test/integration/datadog_consul/serverspec/Gemfile b/test/integration/datadog_consul/serverspec/Gemfile new file mode 120000 index 00000000..74f9789f --- /dev/null +++ b/test/integration/datadog_consul/serverspec/Gemfile @@ -0,0 +1 @@ +../../helpers/serverspec/Gemfile \ No newline at end of file diff --git a/test/integration/datadog_consul/serverspec/consul_spec.rb b/test/integration/datadog_consul/serverspec/consul_spec.rb new file mode 100644 index 00000000..dc4bb9a4 --- /dev/null +++ b/test/integration/datadog_consul/serverspec/consul_spec.rb @@ -0,0 +1,36 @@ +# 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/consul.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:8500', + 'new_leader_checks' => false, + 'catalog_checks' => false, + 'service_whitelist' => 'consul', + 'tags' => ['_default'] + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end