diff --git a/README.md b/README.md index ec4c0c42..71b624aa 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,9 @@ Here are some of the other variables that be set in the datadog_agent class to c | process_enabled | boolean to enable the process agent; defaults to true | | scrub_args | boolean to enable the process cmdline scrubbing; defaults to true | | custom_sensitive_words| an array to add more words beyond the default ones used by the scrubbing feature; defaults to [] | -| agent6_extra_options | hash to provide additional configuration options to agent6. | +| logs_enabled | boolean to enable the logs agent; defaults to false | +| container_collect_all | boolean to enable logs collection for all containers | +| agent6_extra_options | hash to provide additional configuration options to agent6 | _NOTE: `agent6_extra_options` may be used to provide a fine grain control of additional agent6 config options. A deep merge is performed that may override options provided in the `datadog_agent` class parameters_ diff --git a/manifests/init.pp b/manifests/init.pp index f2440dd9..c403fea3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -174,6 +174,12 @@ # $custom_sensitive_words # Array to add more words to be used on the process cdmline scrubbing by the process-agent # Array. Default: [] +# $logs_enabled +# Boolean to enable or disable the logs agent +# Boolean. Default: false +# $container_collect_all +# Boolean to enable logs collection for all containers +# Boolean. Default: false # # Actions: # @@ -273,6 +279,8 @@ $process_enabled = $datadog_agent::params::process_default_enabled, $scrub_args = $datadog_agent::params::process_default_scrub_args, $custom_sensitive_words = $datadog_agent::params::process_default_custom_words, + $logs_enabled = $datadog_agent::params::logs_enabled, + $container_collect_all = $datadog_agent::params::container_collect_all, Hash[String[1], Data] $agent6_extra_options = {}, $agent5_repo_uri = $datadog_agent::params::agent5_default_repo, $agent6_repo_uri = $datadog_agent::params::agent6_default_repo, @@ -355,6 +363,8 @@ validate_legacy(Boolean, 'validate_bool', $process_enabled) validate_legacy(Boolean, 'validate_bool', $scrub_args) validate_legacy(Array, 'validate_array', $custom_sensitive_words) + validate_legacy(Boolean, 'validate_bool', $logs_enabled) + validate_legacy(Boolean, 'validate_bool', $container_collect_all) validate_legacy(String, 'validate_string', $agent5_repo_uri) validate_legacy(String, 'validate_string', $agent6_repo_uri) validate_legacy(String, 'validate_string', $apt_release) @@ -528,6 +538,10 @@ 'scrub_args' => $scrub_args, 'custom_sensitive_words' => $custom_sensitive_words, }, + 'logs_enabled' => $logs_enabled, + 'logs_config' => { + 'container_collect_all' => $container_collect_all, + }, } $extra_config = deep_merge($base_extra_config, $agent6_extra_options) diff --git a/manifests/integrations/logs.pp b/manifests/integrations/logs.pp new file mode 100644 index 00000000..712c59ac --- /dev/null +++ b/manifests/integrations/logs.pp @@ -0,0 +1,56 @@ +# Class: datadog_agent::integrations::logs +# +# This class will install the necessary configuration for the logs integration. +# +# Parameters: +# $logs: +# array of log sources. +# +# Log Source: +# $type +# Type of log input source (tcp / udp / file / docker / journald / windows_event). +# $service +# Optional name of the service owning the log. +# $source +# Optional attribute that defines which integration is sending the logs. +# $tags +# Optional tags that are added to each log collected. +# $log_processing_rules +# Optional array of processing rules. +# +# Sample Usage: +# +# class { 'datadog_agent::integrations::logs' : +# logs => [ +# { +# 'type' => 'file', +# 'path' => '/var/log/afile.log', +# }, +# { +# 'type' => 'docker', +# }, +# ], +# } +# +# Documentation: +# https://docs.datadoghq.com/logs/log_collection +# + +class datadog_agent::integrations::logs( + Array $logs = [], +) inherits datadog_agent::params { + unless $::datadog_agent::agent5_enable { + include datadog_agent + validate_legacy('Array', 'validate_array', $logs) + + file { "${datadog_agent::conf6_dir}/logs.yaml": + ensure => file, + owner => $datadog_agent::params::dd_user, + group => $datadog_agent::params::dd_group, + mode => '0600', + content => template('datadog_agent/agent-conf.d/logs.yaml.erb'), + require => Package[$datadog_agent::params::package_name], + notify => Service[$datadog_agent::params::service_name] + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 659513b4..fcca7840 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -30,6 +30,8 @@ $process_default_enabled = false $process_default_scrub_args = true $process_default_custom_words = [] + $logs_enabled = false + $container_collect_all = false case $::operatingsystem { 'Ubuntu','Debian' : { diff --git a/spec/classes/datadog_agent_integrations_logs_spec.rb b/spec/classes/datadog_agent_integrations_logs_spec.rb new file mode 100644 index 00000000..a7974a9a --- /dev/null +++ b/spec/classes/datadog_agent_integrations_logs_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::logs' do + context 'supported agents - v6' do + let(:pre_condition) { "class {'::datadog_agent': agent5_enable => false}" } + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/datadog-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/logs.yaml" } + + context 'with default parameters' do + it { should compile } + end + + context 'with parameters set' do + let(:params) {{ + logs: [ + { + 'type' => 'file', + 'path' => 'apath.log', + }, + { + 'type' => 'docker', + }, + ], + }} + it { should contain_file(conf_file).with_content(%r{logs:}) } + it { should contain_file(conf_file).with_content(%r{- type: file}) } + it { should contain_file(conf_file).with_content(%r{path: apath.log}) } + it { should contain_file(conf_file).with_content(%r{- type: docker}) } + end + end +end diff --git a/spec/classes/datadog_agent_spec.rb b/spec/classes/datadog_agent_spec.rb index 9e05877a..9f95ad99 100644 --- a/spec/classes/datadog_agent_spec.rb +++ b/spec/classes/datadog_agent_spec.rb @@ -897,6 +897,10 @@ it { should contain_file('/etc/datadog-agent/datadog.yaml').with( 'content' => /^\ \ custom_sensitive_words: \[\]\n/, )} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^logs_enabled: false\n/, + 'content' => /^\ \ container_collect_all: false\n/, + )} end end @@ -1038,8 +1042,19 @@ it { should contain_file('/etc/datadog-agent/datadog.yaml').with( 'content' => /^\ \ -\ dd_key\n/, )} + end + context 'with logs enabled' do + let(:params) {{ + :logs_enabled => true, + :container_collect_all => true + }} + it { should contain_file('/etc/datadog-agent/datadog.yaml').with( + 'content' => /^logs_enabled: true\n/, + 'content' => /^\ \ container_collect_all: true\n/, + )} end + end end end diff --git a/templates/agent-conf.d/logs.yaml.erb b/templates/agent-conf.d/logs.yaml.erb new file mode 100644 index 00000000..7e93638c --- /dev/null +++ b/templates/agent-conf.d/logs.yaml.erb @@ -0,0 +1,5 @@ +<% +require 'yaml' +%> + +<%= {'logs'=>@logs}.to_yaml %>