Skip to content

Commit

Permalink
Added dns_check support
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmarden committed May 2, 2016
1 parent ae48cdf commit 5c2c69c
Showing 3 changed files with 102 additions and 0 deletions.
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

0 comments on commit 5c2c69c

Please sign in to comment.