diff --git a/.fixtures.yml b/.fixtures.yml index 02affa0d..a5693ee2 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,6 +3,7 @@ fixtures: stdlib: repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git" ref: "4.12.0" + concat: "git://github.com/puppetlabs/puppetlabs-concat.git" ruby: "git://github.com/puppetlabs/puppetlabs-ruby.git" remote_file: "git://github.com/lwf/puppet-remote_file.git" symlinks: diff --git a/manifests/init.pp b/manifests/init.pp index b74f69db..11324ad6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -183,6 +183,8 @@ $collect_ec2_tags = false, $collect_instance_metadata = true, $tags = [], + $integrations = {}, + $hiera_integrations = false, $hiera_tags = false, $facts_to_tags = [], $puppet_run_reports = false, @@ -239,6 +241,7 @@ $sd_jmx_enable = false, $consul_token = '', $conf_dir = $datadog_agent::params::conf_dir, + $conf_dir_purge = $datadog_agent::params::conf_dir_purge, $service_name = $datadog_agent::params::service_name, $package_name = $datadog_agent::params::package_name, $dd_user = $datadog_agent::params::dd_user, @@ -249,6 +252,7 @@ # Allow ports to be passed as integers or strings. # lint:ignore:only_variable_string + $_dogstatsd_port = "${dogstatsd_port}" $_statsd_forward_port = "${statsd_forward_port}" $_proxy_port = "${proxy_port}" $_graphite_listen_port = "${graphite_listen_port}" @@ -271,7 +275,7 @@ validate_bool($log_to_syslog) validate_bool($manage_repo) validate_string($log_level) - validate_integer($dogstatsd_port) + validate_re($_dogstatsd_port, '^\d*$') validate_string($statsd_histogram_percentiles) validate_re($_statsd_forward_port, '^\d*$') validate_string($proxy_host) @@ -324,6 +328,17 @@ $local_tags = $tags } + if $hiera_integrations { + $local_integrations = hiera_hash('datadog_agent::integrations') + } else { + $local_integrations = $integrations + } + + datadog_agent::tag{$local_tags: } + datadog_agent::tag{$facts_to_tags: + lookup_fact => true, + } + include datadog_agent::params case upcase($log_level) { 'CRITICAL': { $_loglevel = 'CRITICAL' } @@ -354,19 +369,17 @@ require => Package['datadog-agent'], } - # main agent config file - # content - if ($extra_template != '') { - $agent_conf_content = template( - 'datadog_agent/datadog.conf.erb', - $extra_template - ) - } else { - $agent_conf_content = template('datadog_agent/datadog.conf.erb') + file { $conf_dir: + ensure => directory, + purge => $conf_dir_purge, + recurse => true, + force => $conf_dir_purge, + owner => $dd_user, + group => $dd_group, + notify => Service['datadog-agent'] } - file { '/etc/dd-agent/datadog.conf': - ensure => file, - content => $agent_conf_content, + + concat {'/etc/dd-agent/datadog.conf': owner => $datadog_agent::params::dd_user, group => $datadog_agent::params::dd_group, mode => '0640', @@ -374,6 +387,31 @@ require => File['/etc/dd-agent'], } + concat::fragment{ 'datadog header': + target => '/etc/dd-agent/datadog.conf', + content => template('datadog_agent/datadog_header.conf.erb'), + order => '01', + } + + concat::fragment{ 'datadog tags': + target => '/etc/dd-agent/datadog.conf', + content => 'tags: ', + order => '02', + } + + concat::fragment{ 'datadog footer': + target => '/etc/dd-agent/datadog.conf', + content => template('datadog_agent/datadog_footer.conf.erb'), + order => '05', + } + + concat::fragment{ 'datadog apm footer': + target => '/etc/dd-agent/datadog.conf', + content => template('datadog_agent/datadog_apm_footer.conf.erb'), + order => '06', + } + + if $puppet_run_reports { class { 'datadog_agent::reports': api_key => $api_key, @@ -383,4 +421,6 @@ hostname_extraction_regex => $hostname_extraction_regex, } } + + create_resources('datadog_agent::integration', $local_integrations) } diff --git a/manifests/params.pp b/manifests/params.pp index 56f7ca7f..a2bc2329 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -21,6 +21,7 @@ $package_name = 'datadog-agent' $service_name = 'datadog-agent' $dogapi_version = 'installed' + $conf_dir_purge = false case $::operatingsystem { 'Ubuntu','Debian' : { diff --git a/manifests/tag.pp b/manifests/tag.pp new file mode 100644 index 00000000..ede29b6a --- /dev/null +++ b/manifests/tag.pp @@ -0,0 +1,30 @@ +# Allow custom tags via a define +define datadog_agent::tag( + $tag = $name, + $lookup_fact = false, +){ + + if $lookup_fact{ + $value = getvar($tag) + + if is_array($value){ + $tags = prefix($value, "${tag}:") + datadog_agent::tag{$tags: } + } else { + if $value { + concat::fragment{ "datadog tag ${tag}:${value}": + target => '/etc/dd-agent/datadog.conf', + content => "${tag}:${value}, ", + order => '03', + } + } + } + } else { + concat::fragment{ "datadog tag ${tag}": + target => '/etc/dd-agent/datadog.conf', + content => "${tag}, ", + order => '03', + } + } + +} diff --git a/spec/classes/datadog_agent_spec.rb b/spec/classes/datadog_agent_spec.rb index c856a69f..3e569672 100644 --- a/spec/classes/datadog_agent_spec.rb +++ b/spec/classes/datadog_agent_spec.rb @@ -39,173 +39,174 @@ end it { should contain_file('/etc/dd-agent') } - it { should contain_file('/etc/dd-agent/datadog.conf') } + it { should contain_concat('/etc/dd-agent/datadog.conf') } + it { should contain_file('/etc/dd-agent/conf.d').with_ensure('directory') } it { should contain_class('datadog_agent::reports') } describe 'parameter check' do context 'with defaults' do context 'for proxy' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^dd_url: https:\/\/app.datadoghq.com\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# proxy_host:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# proxy_port:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# proxy_user:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# proxy_password:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# skip_ssl_validation: no\n/, )} end context 'for general' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^api_key: your_API_key\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^# hostname:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^non_local_traffic: false\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^collect_ec2_tags: false\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^collect_instance_metadata: true\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /# recent_point_threshold: 30\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# listen_port: 17123\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# graphite_listen_port: 17124\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# additional_checksd: \/etc\/dd-agent\/checks.d\/\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_curl_http_client: false\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# device_blacklist_re: .*\\\/dev\\\/mapper\\\/lxc-box.*\n/, )} end context 'for pup' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_pup: no\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# pup_port: 17125\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# pup_interface: localhost\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# pup_url: http:\/\/localhost:17125\n/, )} end context 'for dogstatsd' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# bind_host: localhost\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_dogstatsd: yes\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_port: 8125\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# dogstatsd_target: http:\/\/localhost:17123\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# dogstatsd_interval: 10\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_normalize: yes\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# statsd_forward_host: address_of_own_statsd_server\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# statsd_forward_port: 8125\n/, )} end context 'for ganglia' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# ganglia_host: localhost\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# ganglia_port: 8651\n/, )} end context 'for logging' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^log_level: INFO\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^log_to_syslog: yes\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# collector_log_file: \/var\/log\/datadog\/collector.log\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# forwarder_log_file: \/var\/log\/datadog\/forwarder.log\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# dogstatsd_log_file: \/var\/log\/datadog\/dogstatsd.log\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( #'content' => /^# pup_log_file: \/var\/log\/datadog\/pup.log\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# syslog_host:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^# syslog_port:\n/, )} end context 'for service_discovery' do - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^service_discovery_backend:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^sd_config_backend:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^sd_backend_host:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^sd_backend_port:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^sd_template_dir:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').without( + it { should contain_concat__fragment('datadog footer').without( 'content' => /^consul_token:\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( - 'content' => /^# sd_jmx_enable: no\n/, + it { should contain_concat__fragment('datadog footer').without( + 'content' => /^# sd_jmx_enable:\n/, )} end context 'for APM' do - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^apm_enabled: false\n/, )} end @@ -214,330 +215,342 @@ context 'with user provided paramaters' do context 'with a custom dd_url' do let(:params) {{:dd_url => 'https://notaurl.datadoghq.com'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^dd_url: https:\/\/notaurl.datadoghq.com\n/, )} end context 'with a custom proxy_host' do let(:params) {{:proxy_host => 'localhost'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^proxy_host: localhost\n/, )} end context 'with a custom proxy_port' do let(:params) {{:proxy_port => '1234'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^proxy_port: 1234\n/, )} end context 'with a custom proxy_port, specified as an integer' do let(:params) {{:proxy_port => 1234}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^proxy_port: 1234\n/, )} end context 'with a custom proxy_user' do let(:params) {{:proxy_user => 'notauser'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^proxy_user: notauser\n/, )} end context 'with a custom api_key' do let(:params) {{:api_key => 'notakey'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^api_key: notakey\n/, )} end context 'with a custom hostname' do let(:params) {{:host => 'notahost'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^hostname: notahost\n/, )} end context 'with non_local_traffic set to true' do let(:params) {{:non_local_traffic => true}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^non_local_traffic: true\n/, )} end #Should expand testing to cover changes to the case upcase context 'with log level set to critical' do let(:params) {{:log_level => 'critical'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^log_level: CRITICAL\n/, )} end context 'with a custom hostname' do let(:params) {{:host => 'notahost'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^hostname: notahost\n/, )} end context 'with log_to_syslog set to false' do let(:params) {{:log_to_syslog => false}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^log_to_syslog: no\n/, )} end context 'with skip_ssl_validation set to true' do let(:params) {{:skip_ssl_validation => true }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog header').with( 'content' => /^skip_ssl_validation: true\n/, )} end context 'with collect_ec2_tags set to yes' do let(:params) {{:collect_ec2_tags => true }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^collect_ec2_tags: true\n/, )} end context 'with collect_instance_metadata set to no' do let(:params) {{:collect_instance_metadata => false }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^collect_instance_metadata: false\n/, )} end context 'with recent_point_threshold set to 60' do let(:params) {{:recent_point_threshold => '60' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^recent_point_threshold: 60\n/, )} end context 'with a custom port set to 17125' do let(:params) {{:listen_port => '17125' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^listen_port: 17125\n/, )} end context 'with a custom port set to 17125, specified as an integer' do let(:params) {{:listen_port => 17125 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^listen_port: 17125\n/, )} end context 'listening for graphite data on port 17124' do let(:params) {{:graphite_listen_port => '17124' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^graphite_listen_port: 17124\n/, )} end context 'listening for graphite data on port 17124, port specified as an integer' do let(:params) {{:graphite_listen_port => 17124 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^graphite_listen_port: 17124\n/, )} end context 'with configuration for a custom checks.d' do let(:params) {{:additional_checksd => '/etc/dd-agent/checks_custom.d' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^additional_checksd: \/etc\/dd-agent\/checks_custom.d\n/, )} end context 'with configuration for a custom checks.d' do let(:params) {{:additional_checksd => '/etc/dd-agent/checks_custom.d' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^additional_checksd: \/etc\/dd-agent\/checks_custom.d\n/, )} end context 'with configuration for a custom checks.d' do let(:params) {{:additional_checksd => '/etc/dd-agent/checks_custom.d' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^additional_checksd: \/etc\/dd-agent\/checks_custom.d\n/, )} end context 'with using the Tornado HTTP client' do let(:params) {{:use_curl_http_client => true }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_curl_http_client: true\n/, )} end context 'with a custom bind_host' do let(:params) {{:bind_host => 'test' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^bind_host: test\n/, )} end context 'with pup enabled' do let(:params) {{:use_pup => true }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_pup: yes\n/, )} end context 'with a custom pup_port' do let(:params) {{:pup_port => '17126' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^pup_port: 17126\n/, )} end context 'with a custom pup_port, specified as an integer' do let(:params) {{:pup_port => 17126 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^pup_port: 17126\n/, )} end context 'with a custom pup_interface' do let(:params) {{:pup_interface => 'notalocalhost' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^pup_interface: notalocalhost\n/, )} end context 'with a custom pup_url' do let(:params) {{:pup_url => 'http://localhost:17126' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^pup_url: http:\/\/localhost:17126\n/, )} end context 'with use_dogstatsd set to no' do let(:params) {{:use_dogstatsd => false}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^use_dogstatsd: no\n/, )} end + context 'with use_dogstatsd set to yes' do + let(:params) {{:use_dogstatsd => true}} + it { should contain_concat__fragment('datadog footer').with( + 'content' => /^use_dogstatsd: yes\n/, + )} + end context 'with dogstatsd_port set to 8126 - must be specified as an integer!' do let(:params) {{:dogstatsd_port => 8126 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( + 'content' => /^dogstatsd_port: 8126\n/, + )} + end + context 'with dogstatsd_port set to 8126' do + let(:params) {{:dogstatsd_port => 8126}} + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_port: 8126\n/, )} end context 'with dogstatsd_target set to localhost:17124' do let(:params) {{:dogstatsd_target => 'http://localhost:17124'}} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_target: http:\/\/localhost:17124\n/, )} end context 'with dogstatsd_interval set to 5' do let(:params) {{:dogstatsd_interval => '5' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_interval: 5\n/, )} end context 'with dogstatsd_interval set to 5' do let(:params) {{:dogstatsd_interval => '5' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_interval: 5\n/, )} end context 'with dogstatsd_normalize set to false' do let(:params) {{:dogstatsd_normalize => false }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_normalize: no\n/, )} end context 'with statsd_forward_host set to localhost:3958' do let(:params) {{:statsd_forward_host => 'localhost:3958' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^statsd_forward_host: localhost:3958\n/, )} end context 'with statsd_forward_port set to 8126' do let(:params) {{:statsd_forward_port => '8126' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^statsd_forward_port: 8126\n/, )} end context 'with statsd_forward_port set to 8126, specified as an integer' do let(:params) {{:statsd_forward_port => 8126 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^statsd_forward_port: 8126\n/, )} end context 'with device_blacklist_re set to test' do let(:params) {{:device_blacklist_re => 'test' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^device_blacklist_re: test\n/, )} end context 'with device_blacklist_re set to test' do let(:params) {{:device_blacklist_re => 'test' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^device_blacklist_re: test\n/, )} end context 'with ganglia_host set to localhost and ganglia_port set to 12345' do let(:params) {{:ganglia_host => 'testhost', :ganglia_port => '12345' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^ganglia_port: 12345\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^ganglia_host: testhost\n/, )} end context 'with ganglia_host set to localhost and ganglia_port set to 12345, port specified as an integer' do let(:params) {{:ganglia_host => 'testhost', :ganglia_port => 12345 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^ganglia_port: 12345\n/, )} end context 'with dogstreams set to /path/to/log1:/path/to/parser' do let(:params) {{:dogstreams => ['/path/to/log1:/path/to/parser'] }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstreams: \/path\/to\/log1:\/path\/to\/parser\n/, )} end context 'with custom_emitters set to /test/emitter' do let(:params) {{:custom_emitters => '/test/emitter/' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^custom_emitters: \/test\/emitter\/\n/, )} end context 'with custom_emitters set to /test/emitter' do let(:params) {{:custom_emitters => '/test/emitter/' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^custom_emitters: \/test\/emitter\/\n/, )} end context 'with collector_log_file set to /test/log' do let(:params) {{:collector_log_file => '/test/log' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^collector_log_file: \/test\/log\n/, )} end context 'with forwarder_log_file set to /test/log' do let(:params) {{:forwarder_log_file => '/test/log' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^forwarder_log_file: \/test\/log\n/, )} end context 'with forwarder_log_file set to /test/log' do let(:params) {{:forwarder_log_file => '/test/log' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^forwarder_log_file: \/test\/log\n/, )} end context 'with dogstatsd_log_file set to /test/log' do let(:params) {{:dogstatsd_log_file => '/test/log' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^dogstatsd_log_file: \/test\/log\n/, )} end context 'with pup_log_file set to /test/log' do let(:params) {{:pup_log_file => '/test/log' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^pup_log_file: \/test\/log\n/, )} end context 'with syslog location set to localhost' do let(:params) {{:syslog_host => 'localhost' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^syslog_host: localhost\n/, )} end context 'with syslog port set to 8080' do let(:params) {{:syslog_port => '8080' }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^syslog_port: 8080\n/, )} end context 'with syslog port set to 8080, specified as an integer' do let(:params) {{:syslog_port => 8080 }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^syslog_port: 8080\n/, )} end context 'with apm_enabled set to true' do let(:params) {{:apm_enabled => true }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^apm_enabled: true\n/, )} end @@ -546,13 +559,13 @@ {:apm_enabled => true, :apm_env => 'foo', }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^apm_enabled: true\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog apm footer').with( 'content' => /^\[trace.agent\]\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog apm footer').with( 'content' => /^env: foo\n/, )} end @@ -564,19 +577,19 @@ :sd_backend_port => '8080', :sd_jmx_enable => true, }} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^service_discovery_backend: docker\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^sd_config_backend: etcd\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^sd_backend_host: localhost\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^sd_backend_port: 8080\n/, )} - it { should contain_file('/etc/dd-agent/datadog.conf').with( + it { should contain_concat__fragment('datadog footer').with( 'content' => /^sd_jmx_enable: true\n/, )} end @@ -591,4 +604,20 @@ end end end + + context "with facts to tags set" do + describe "ensure facts_array outputs a list of tags" do + let(:params) { { puppet_run_reports: true, puppet_gem_provider: 'gem', facts_to_tags: ['osfamily', 'facts_array']} } + let(:facts) do + { + operatingsystem: 'CentOS', + osfamily: 'redhat', + facts_array: ['one', 'two', 'three'] + } + + it { should contain_concat('/etc/dd-agent/datadog.conf') } + it { should contain_concat__fragment('datadog tags').with(/tags: osfamily:redhat, facts_array:one, facts_array:two, facts_array:three/) } + end + end + end end diff --git a/templates/datadog_apm_footer.conf.erb b/templates/datadog_apm_footer.conf.erb new file mode 100644 index 00000000..0958ff30 --- /dev/null +++ b/templates/datadog_apm_footer.conf.erb @@ -0,0 +1,4 @@ +<% if not @apm_env.empty? -%> +[trace.agent] +env: <%= @apm_env %> +<% end -%> diff --git a/templates/datadog.conf.erb b/templates/datadog_footer.conf.erb similarity index 88% rename from templates/datadog.conf.erb rename to templates/datadog_footer.conf.erb index eb9bcd12..f418c0c3 100644 --- a/templates/datadog.conf.erb +++ b/templates/datadog_footer.conf.erb @@ -1,67 +1,3 @@ -# -# MANAGED BY PUPPET -# -[Main] - -# The host of the Datadog intake server to send agent data to -dd_url: <%= @dd_url %> - -# If you need a proxy to connect to the Internet, provide the settings here -<% if @proxy_host.empty? -%> -# proxy_host: -<% else -%> -proxy_host: <%= @proxy_host %> -<% end -%> -<% if @_proxy_port.empty? -%> -# proxy_port: -<% else -%> -proxy_port: <%= @_proxy_port %> -<% end -%> -<% if @proxy_user.empty? -%> -# proxy_user: -<% else -%> -proxy_user: <%= @proxy_user %> -<% end -%> -<% if @proxy_password.empty? -%> -# proxy_password: -<% else -%> -proxy_password: <%= @proxy_password %> -<% end -%> - -# If you run the agent behind haproxy, you might want to set this to yes -<% if @skip_ssl_validation -%> -skip_ssl_validation: <%= @skip_ssl_validation %> -<% else -%> -# skip_ssl_validation: no -<% end -%> - -# The Datadog api key to associate your Agent's data with your organization. -# Can be found here: -# https://app.datadoghq.com/account/settings -api_key: <%= @api_key %> - -# Force the hostname to whatever you want. -<% if @host.empty? -%> -# hostname: -<% else -%> -hostname: <%= @host %> -<% end -%> - -# Set the host's tags -#tags: mytag0, mytag1 -<% -tag_list = @local_tags -@facts_to_tags.each do |f| - value = scope.lookupvar(f) - if not value.nil? - tag = "#{f}:#{value}" - tag_list << tag - end -end -if not tag_list.empty? --%> -tags: <%= tag_list.join(', ') %> -<% end -%> # Collect AWS EC2 custom tags as agent tags collect_ec2_tags: <%= @collect_ec2_tags %> @@ -124,6 +60,7 @@ use_curl_http_client: <%= @use_curl_http_client %> bind_host: <%= @bind_host %> <% end -%> + # ========================================================================== # # Pup configuration # ========================================================================== # @@ -163,10 +100,10 @@ use_dogstatsd: <%= @use_dogstatsd ? "yes" : "no" %> # usage information, check out http://api.datadoghq.com # Make sure your client is sending to the same port. -<% if @dogstatsd_port.nil? -%> +<% if @_dogstatsd_port.empty? -%> # dogstatsd_port: 8125 <% else -%> -dogstatsd_port: <%= @dogstatsd_port %> +dogstatsd_port: <%= @_dogstatsd_port %> <% end -%> # By default dogstatsd will post aggregate metrics to the Agent (which handles @@ -390,8 +327,6 @@ sd_template_dir: <%= @sd_template_dir %> # Enable JMX checks for service discovery <% if @sd_jmx_enable -%> sd_jmx_enable: <%= @sd_jmx_enable %> -<% else -%> -# sd_jmx_enable: no <% end -%> # If you Consul store requires token authentication for service discovery, you can define that token here. @@ -405,17 +340,13 @@ consul_token: <%= @consul_token %> # Trace # # ========================================================================== # +# Enable the trace agent. apm_enabled: <%= @apm_enabled %> -<% if not @extra_template.empty? -%> +<% if not @extra_template.empty? -%> # ========================================================================== # # Custom Templates from Puppet # # ========================================================================== # <% end -%> - -<% if not @apm_env.empty? -%> -[trace.agent] -env: <%= @apm_env %> -<% end -%> diff --git a/templates/datadog_header.conf.erb b/templates/datadog_header.conf.erb new file mode 100644 index 00000000..3f40fd44 --- /dev/null +++ b/templates/datadog_header.conf.erb @@ -0,0 +1,48 @@ +# +# MANAGED BY PUPPET +# +[Main] + +# The host of the Datadog intake server to send agent data to +dd_url: <%= @dd_url %> + +# If you need a proxy to connect to the Internet, provide the settings here +<% if @proxy_host.empty? -%> +# proxy_host: +<% else -%> +proxy_host: <%= @proxy_host %> +<% end -%> +<% if @_proxy_port.empty? -%> +# proxy_port: +<% else -%> +proxy_port: <%= @_proxy_port %> +<% end -%> +<% if @proxy_user.empty? -%> +# proxy_user: +<% else -%> +proxy_user: <%= @proxy_user %> +<% end -%> +<% if @proxy_password.empty? -%> +# proxy_password: +<% else -%> +proxy_password: <%= @proxy_password %> +<% end -%> + +# If you run the agent behind haproxy, you might want to set this to yes +<% if @skip_ssl_validation -%> +skip_ssl_validation: <%= @skip_ssl_validation %> +<% else -%> +# skip_ssl_validation: no +<% end -%> + +# The Datadog api key to associate your Agent's data with your organization. +# Can be found here: +# https://app.datadoghq.com/account/settings +api_key: <%= @api_key %> + +# Force the hostname to whatever you want. +<% if @host.empty? -%> +# hostname: +<% else -%> +hostname: <%= @host %> +<% end -%> diff --git a/templates/datadog_tags.conf.erb b/templates/datadog_tags.conf.erb new file mode 100644 index 00000000..e69de29b