File tree Expand file tree Collapse file tree
lib/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ( /---\n init_config: \n instances:\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
You can’t perform that action at this time.
0 commit comments