Skip to content

Commit

Permalink
Add a tokumx recipe, which about three people will use.
Browse files Browse the repository at this point in the history
  • Loading branch information
gswallow committed Oct 17, 2017
1 parent b1f0280 commit 31d467b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions recipes/tokumx.rb
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions spec/integrations/tokumx_spec.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions templates/default/tokumx.yaml.erb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions test/integration/datadog_tokumx/serverspec/tokumx_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 31d467b

Please sign in to comment.