Skip to content

Commit 7326b14

Browse files
authored
Merge pull request #233 from DataDog/jaime/generic-integration
Make a generic define for creating modules
2 parents 8218721 + 9d77765 commit 7326b14

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'yaml'
2+
3+
module Puppet::Parser::Functions
4+
newfunction(:to_instances_yaml, :type => :rvalue) do |args|
5+
init_config = args[0]
6+
instances = args[1]
7+
default_values = {
8+
'init_config' => init_config.is_a?(String) ? nil: init_config,
9+
'instances' => instances
10+
}
11+
YAML::dump(default_values)
12+
end
13+
end

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@
229229
$pup_log_file = '',
230230
$syslog_host = '',
231231
$syslog_port = '',
232+
$conf_dir = $datadog_agent::params::conf_dir,
233+
$service_name = $datadog_agent::params::service_name,
234+
$package_name = $datadog_agent::params::package_name,
235+
$dd_user = $datadog_agent::params::dd_user,
236+
$dd_group = $datadog_agent::params::dd_group,
232237
) inherits datadog_agent::params {
233238

234239
validate_string($dd_url)

manifests/integration.pp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
define datadog_agent::integration (
2+
$instances,
3+
$init_config = undef,
4+
$integration = $title,
5+
){
6+
7+
include datadog_agent
8+
9+
validate_array($instances)
10+
if $init_config != undef {
11+
validate_hash($init_config)
12+
}
13+
validate_string($integration)
14+
15+
file { "${datadog_agent::conf_dir}/${integration}.yaml":
16+
ensure => file,
17+
owner => $datadog_agent::dd_user,
18+
group => $datadog_agent::dd_group,
19+
mode => '0600',
20+
content => to_instances_yaml($init_config, $instances),
21+
notify => Service[$datadog_agent::service_name]
22+
}
23+
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
describe "datadog_agent::integration" do
4+
let (:title) { "test" }
5+
let(:facts) do
6+
{
7+
operatingsystem: 'CentOS',
8+
osfamily: 'redhat'
9+
}
10+
end
11+
let (:params) {{
12+
:instances => [
13+
{ 'one' => "two" }
14+
]
15+
}}
16+
it { should compile }
17+
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/init_config: /) }
18+
gem_spec = Gem.loaded_specs['puppet']
19+
if gem_spec.version >= Gem::Version.new('4.0.0')
20+
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/---\ninit_config: \ninstances:\n- one: two\n/) }
21+
else
22+
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/--- \n init_config: \n instances: \n - one: two/) }
23+
end
24+
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').that_notifies("Service[datadog-agent]") }
25+
end

0 commit comments

Comments
 (0)