-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from DataDog/jaime/generic-integration
Make a generic define for creating modules
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'yaml' | ||
|
||
module Puppet::Parser::Functions | ||
newfunction(:to_instances_yaml, :type => :rvalue) do |args| | ||
init_config = args[0] | ||
instances = args[1] | ||
default_values = { | ||
'init_config' => init_config.is_a?(String) ? nil: init_config, | ||
'instances' => instances | ||
} | ||
YAML::dump(default_values) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
define datadog_agent::integration ( | ||
$instances, | ||
$init_config = undef, | ||
$integration = $title, | ||
){ | ||
|
||
include datadog_agent | ||
|
||
validate_array($instances) | ||
if $init_config != undef { | ||
validate_hash($init_config) | ||
} | ||
validate_string($integration) | ||
|
||
file { "${datadog_agent::conf_dir}/${integration}.yaml": | ||
ensure => file, | ||
owner => $datadog_agent::dd_user, | ||
group => $datadog_agent::dd_group, | ||
mode => '0600', | ||
content => to_instances_yaml($init_config, $instances), | ||
notify => Service[$datadog_agent::service_name] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe "datadog_agent::integration" do | ||
let (:title) { "test" } | ||
let(:facts) do | ||
{ | ||
operatingsystem: 'CentOS', | ||
osfamily: 'redhat' | ||
} | ||
end | ||
let (:params) {{ | ||
:instances => [ | ||
{ 'one' => "two" } | ||
] | ||
}} | ||
it { should compile } | ||
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/init_config: /) } | ||
gem_spec = Gem.loaded_specs['puppet'] | ||
if gem_spec.version >= Gem::Version.new('4.0.0') | ||
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/---\ninit_config: \ninstances:\n- one: two\n/) } | ||
else | ||
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').with_content(/--- \n init_config: \n instances: \n - one: two/) } | ||
end | ||
it { should contain_file('/etc/dd-agent/conf.d/test.yaml').that_notifies("Service[datadog-agent]") } | ||
end |