Skip to content

Commit b996898

Browse files
authored
Merge pull request #212 from jacobbednarz/add-dns-check
Create DNS check integration manifest
2 parents df495f9 + b297cab commit b996898

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Class: datadog_agent::integrations::dns_check
2+
#
3+
# This class will install the necessary configuration for the DNS check
4+
# integration.
5+
#
6+
# Parameters:
7+
# $hostname:
8+
# Domain or IP you wish to check the availability of.
9+
# $nameserver
10+
# The nameserver you wish to use to check the hostname
11+
# availability.
12+
# $timeout
13+
# Time in seconds to wait before terminating the request.
14+
#
15+
# Sample Usage:
16+
#
17+
# class { 'datadog_agent::integrations::dns_check':
18+
# checks => [
19+
# {
20+
# 'hostname' => 'example.com',
21+
# 'nameserver' => '8.8.8.8',
22+
# 'timeout' => 5,
23+
# }
24+
# ]
25+
# }
26+
#
27+
class datadog_agent::integrations::dns_check (
28+
$checks = [
29+
{
30+
'hostname' => 'google.com',
31+
'nameserver' => '8.8.8.8',
32+
'timeout' => 5,
33+
}
34+
]
35+
) inherits datadog_agent::params {
36+
include datadog_agent
37+
38+
validate_array($checks)
39+
40+
file { "${datadog_agent::params::conf_dir}/dns_check.yaml":
41+
ensure => file,
42+
owner => $datadog_agent::params::dd_user,
43+
group => $datadog_agent::params::dd_group,
44+
mode => '0600',
45+
content => template('datadog_agent/agent-conf.d/dns_check.yaml.erb'),
46+
require => Package[$datadog_agent::params::package_name],
47+
notify => Service[$datadog_agent::params::service_name],
48+
}
49+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'spec_helper'
2+
3+
describe 'datadog_agent::integrations::dns_check' do
4+
let(:facts) {{
5+
operatingsystem: 'Ubuntu',
6+
}}
7+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8+
let(:dd_user) { 'dd-agent' }
9+
let(:dd_group) { 'root' }
10+
let(:dd_package) { 'datadog-agent' }
11+
let(:dd_service) { 'datadog-agent' }
12+
let(:conf_file) { "#{conf_dir}/dns_check.yaml" }
13+
14+
it { should compile.with_all_deps }
15+
it { should contain_file(conf_file).with(
16+
owner: dd_user,
17+
group: dd_group,
18+
mode: '0600',
19+
)}
20+
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
21+
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
22+
23+
context 'with default parameters' do
24+
it { should contain_file(conf_file).with_content(%r{hostname: google.com}) }
25+
it { should contain_file(conf_file).with_content(%r{nameserver: 8.8.8.8}) }
26+
it { should contain_file(conf_file).with_content(%r{timeout: 5}) }
27+
end
28+
29+
context 'with parameters set' do
30+
let(:params) {{
31+
checks: [
32+
{
33+
'hostname' => 'example.com',
34+
'nameserver' => '1.2.3.4',
35+
'timeout' => 5,
36+
},
37+
{
38+
'hostname' => 'localdomain.com',
39+
'nameserver' => '4.3.2.1',
40+
'timeout' => 3,
41+
}
42+
]
43+
}}
44+
45+
it { should contain_file(conf_file).with_content(%r{hostname: example.com}) }
46+
it { should contain_file(conf_file).with_content(%r{nameserver: 1.2.3.4}) }
47+
it { should contain_file(conf_file).with_content(%r{timeout: 5}) }
48+
it { should contain_file(conf_file).with_content(%r{hostname: localdomain.com}) }
49+
it { should contain_file(conf_file).with_content(%r{nameserver: 4.3.2.1}) }
50+
it { should contain_file(conf_file).with_content(%r{timeout: 3}) }
51+
end
52+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# MANAGED BY PUPPET
3+
#
4+
5+
init_config:
6+
default_timeout: 4
7+
8+
instances:
9+
<% @checks.each do |check| -%>
10+
- hostname: <%= check['hostname'] %>
11+
nameserver: <%= check['nameserver'] %>
12+
timeout: <%= check['timeout'] %>
13+
<% end -%>

0 commit comments

Comments
 (0)