Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dns_check support #294

Merged
merged 1 commit into from
May 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added dns_check support
nickmarden committed May 2, 2016
commit 5c2c69cd81a99b6c5dbf88e22a336a9fc7f49d2f
33 changes: 33 additions & 0 deletions recipes/dns_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include_recipe 'datadog::dd-agent'

# Monitor dns
#
# Create one attribute entry for each combination of hostname that
# you want to monitor + DNS server that you want to monitor it on.
#
# node['datadog']['dns_check']['instances'] = [
# {
# 'hostname' => 'foo.example.com',
# 'nameserver' => 'prod-ns.example.com',
# 'timeout' => 1
# },
# {
# 'hostname' => 'baz.example.com',
# 'nameserver' => 'prod-ns.example.com',
# 'timeout' => 1
# },
# {
# 'hostname' => 'foo.example.com',
# 'nameserver' => 'test-ns.example.com',
# 'timeout' => 3
# },
# {
# 'hostname' => 'quux.example.com',
# 'nameserver' => 'test-ns.example.com',
# 'timeout' => 3
# },
# ]

datadog_monitor 'dns_check' do
instances node['datadog']['dns_check']['instances']
end
58 changes: 58 additions & 0 deletions spec/integrations/dns_check_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
describe 'datadog::dns_check' do
expected_yaml = <<-EOF
init_config:
default_timeout: 4

instances:
- hostname: foo.example.com
nameserver: prod-ns.example.com
timeout: 1
- hostname: bar.example.com
nameserver: prod-ns.example.com
- hostname: staging.example.com
nameserver: test-ns.example.com
timeout: 2
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',
'dns_check' => {
'instances' => [
{
'hostname' => 'foo.example.com',
'nameserver' => 'prod-ns.example.com',
'timeout' => 1
},
{
'hostname' => 'bar.example.com',
'nameserver' => 'prod-ns.example.com'
},
{
'hostname' => 'staging.example.com',
'nameserver' => 'test-ns.example.com',
'timeout' => 2
}
]
}
}
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('dns_check') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/dns_check.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
11 changes: 11 additions & 0 deletions templates/default/dns_check.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
instances:
<% @instances.each do |i| -%>
- hostname: <%= i["hostname"] %>
nameserver: <%= i["nameserver"] || '127.0.0.1' %>
<% unless i["timeout"].nil? %>
timeout: <%= i["timeout"] %>
<% end %>
<% end %>

init_config:
default_timeout: 4