From 31d467b2c8dbc97044c2b499af23e26df1270fef Mon Sep 17 00:00:00 2001 From: Greg Swallow Date: Tue, 17 Oct 2017 10:14:52 -0400 Subject: [PATCH] Add a tokumx recipe, which about three people will use. --- .kitchen.yml | 11 +++++ recipes/tokumx.rb | 14 ++++++ spec/integrations/tokumx_spec.rb | 43 +++++++++++++++++++ templates/default/tokumx.yaml.erb | 32 ++++++++++++++ .../datadog_tokumx/serverspec/tokumx_spec.rb | 28 ++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 recipes/tokumx.rb create mode 100644 spec/integrations/tokumx_spec.rb create mode 100644 templates/default/tokumx.yaml.erb create mode 100644 test/integration/datadog_tokumx/serverspec/tokumx_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index 12e4cf35..d33c6c9e 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -321,6 +321,17 @@ suites: - host: localhost port: 27017 +- name: datadog_tokumx + run_list: + - recipe[datadog::tokumx] + attributes: + datadog: + <<: *DATADOG + tokumx: + instances: + - host: localhost + port: 27017 + - name: datadog_mysql run_list: - recipe[datadog::mysql] diff --git a/recipes/tokumx.rb b/recipes/tokumx.rb new file mode 100644 index 00000000..84facba9 --- /dev/null +++ b/recipes/tokumx.rb @@ -0,0 +1,14 @@ +include_recipe 'datadog::dd-agent' + +# Monitor tokumx +# +# node.set['datadog']['tokumx']['instances'] = [ +# { +# 'host' => 'localhost', +# 'port' => '27017' +# } +# ] + +datadog_monitor 'tokumx' do + instances node['datadog']['tokumx']['instances'] +end diff --git a/spec/integrations/tokumx_spec.rb b/spec/integrations/tokumx_spec.rb new file mode 100644 index 00000000..4bf83417 --- /dev/null +++ b/spec/integrations/tokumx_spec.rb @@ -0,0 +1,43 @@ +describe 'datadog::tokumx' do + expected_yaml = <<-EOF + init_config: + + instances: + - server: mongodb://localhost:27017 + tags: + - 'env:test' + + EOF + + cached(:chef_run) do + ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node| + node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } } + node.set['datadog'] = { + api_key: 'someapikey', + tokumx: { + instances: [ + { + host: 'localhost', + port: '27017', + tags: ['env:test'] + } + ] + } + } + end.converge(described_recipe) + end + + subject { chef_run } + + it_behaves_like 'datadog-agent' + + it { is_expected.to include_recipe('datadog::dd-agent') } + + it { is_expected.to add_datadog_monitor('tokumx') } + + it 'renders expected YAML config file' do + expect(chef_run).to(render_file('/etc/dd-agent/conf.d/tokumx.yaml').with_content { |content| + expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json) + }) + end +end diff --git a/templates/default/tokumx.yaml.erb b/templates/default/tokumx.yaml.erb new file mode 100644 index 00000000..cf00897e --- /dev/null +++ b/templates/default/tokumx.yaml.erb @@ -0,0 +1,32 @@ +instances: + <% @instances.each do |i| -%> + - server: mongodb://<%= i['host']%>:<%= i['port'] %> + <% if i.key?('tags') -%> + tags: + <% i['tags'].each do |t| -%> + - <%= t %> + <% end -%> + <% end -%> + <% if i.key?('ssl') -%> + ssl: <%= i['ssl'] %> + ssl_ca_certs: <%= i['ssl_ca_certs'] %> + ssl_cert_reqs: <%= i['ssl_cert_reqs'] %> + ssl_certfile: <%= i['ssl_certfile'] %> + ssl_keyfile: <%= i['ssl_keyfile'] %> + <% end %> + <% if i.key?('additional_metrics') -%> + additional_metrics: + <% i['additional_metrics'].each do |t| %> + - <%= t %> + <%end -%> + <% end %> + <% if i.key?('collections') -%> + collections: + <% i['collections'].each do |t| %> + - <%= t %> + <%end -%> + <% end %> + <% end -%> + +init_config: +# No init_config details needed \ No newline at end of file diff --git a/test/integration/datadog_tokumx/serverspec/tokumx_spec.rb b/test/integration/datadog_tokumx/serverspec/tokumx_spec.rb new file mode 100644 index 00000000..b9ff5be6 --- /dev/null +++ b/test/integration/datadog_tokumx/serverspec/tokumx_spec.rb @@ -0,0 +1,28 @@ +# Encoding: utf-8 + +require 'spec_helper' + +AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/tokumx.yaml') + +describe service(@agent_service_name) 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' => [ + { + 'server' => 'mongodb://localhost:27017' + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end