<% # OPTIONS REMOVED IN AGENT 6: # - check_freq # - use_mount # - developer_mode # - dogstreams # - autorestart # - custom_emitters # - graphite # - dogstatsd_target # - dogstatsd_interval # - dogstatsd_normalize # - legacy_integrations # - listen_port (`agent_port` attribute) # TODO: options not supported yet: # - agent_checks_interval # - Autodiscovery (aka Service Discovery) related options def string_list_to_array(string_list) # return an array from a comma-separated list in a string string_list.split(',').map{ |elem| elem.strip } end ## Normalize complex config values for agent6 format ## if node['datadog']['tags'].respond_to?(:each_pair) tags = node['datadog']['tags'].reject{ |_k,v| v.empty? }.map{ |k,v| "#{k.strip}:#{v.strip}" } elsif node['datadog']['tags'].respond_to?(:each) tags = node['datadog']['tags'] else tags = string_list_to_array(node['datadog']['tags']) end # TODO: support the more complete proxy settings that the agent6 supports http_proxy = nil no_proxy = nil if node['datadog']['web_proxy']['host'] host = node['datadog']['web_proxy']['host'] port = node['datadog']['web_proxy']['port'] user = node['datadog']['web_proxy']['user'] password = node['datadog']['web_proxy']['password'] scheme = "" no_proxy = node['datadog']['web_proxy']['no_proxy'] unless host.start_with?('http://') or host.start_with?('https://') scheme = 'http://' end http_proxy = host if port http_proxy += ":#{port}" end if user if password http_proxy = "#{user}:#{password}@#{http_proxy}" else http_proxy = "#{user}@#{http_proxy}" end end http_proxy = scheme + http_proxy end # In the default case we will start and run with only container collection. process_agent_enabled = 'false' if node['datadog']['enable_process_agent'].is_a?(TrueClass) # Collect processes if enabled. process_agent_enabled = 'true' elsif node['datadog']['enable_process_agent'].is_a?(FalseClass) # Disable the Agent altogether if false. process_agent_enabled = 'disabled' end ## Populate agent_config ## agent_config = @extra_config.merge({ api_key: @api_key, site: node['datadog']['site'], dd_url: node['datadog']['url'], hostname: node['datadog']['hostname'], bind_host: node['datadog']['bind_host'], additional_endpoints: @additional_endpoints, skip_ssl_validation: node['datadog']['web_proxy']['skip_ssl_validation'], tags: tags, env: node['datadog']['env'], create_dd_check_tags: node['datadog']['create_dd_check_tags'], collect_ec2_tags: node['datadog']['collect_ec2_tags'], dogstatsd_non_local_traffic: node['datadog']['non_local_traffic'], histogram_aggregates: string_list_to_array(node['datadog']['histogram_aggregates']), histogram_percentiles: string_list_to_array(node['datadog']['histogram_percentiles']), use_dogstatsd: node['datadog']['dogstatsd'], statsd_metric_namespace: node['datadog']['statsd_metric_namespace'], log_level: node['datadog']['log_level'], cmd_port: node['datadog']['cmd_port'], GUI_port: node['datadog']['gui_port'], # log agent options logs_enabled: node['datadog']['enable_logs_agent'], }) if node['datadog']['statsd_forward_host'] # TODO: in next major, make `nil` the default value of `statsd_forward_port` to normalize handling agent_config['statsd_forward_host'] = node['datadog']['statsd_forward_host'] agent_config['statsd_forward_port'] = node['datadog']['statsd_forward_port'] end if node['datadog']['logs_agent_config'] agent_config['logs_config'] = node['datadog']['logs_agent_config'] end if node['datadog']['log_file_directory'] agent_config['log_file'] = ::File.join(node['datadog']['log_file_directory'], "agent.log") end if !node['datadog']['use_v2_api'].nil? && !node['datadog']['use_v2_api'].empty? agent_config['use_v2_api'] = node['datadog']['use_v2_api'] end if node['datadog']['syslog']['active'] agent_config['log_to_syslog'] = true # TODO: double check the udp settings work with agent6 if node['datadog']['syslog']['udp'] agent_config['syslog_uri'] = "#{node['datadog']['syslog']['host']}:#{node['datadog']['syslog']['port']}" end end if !node['datadog']['log_to_console'].nil? agent_config['log_to_console'] = node['datadog']['log_to_console'] end # Set proxy options if !http_proxy.nil? agent_config['proxy'] = { http: http_proxy, https: http_proxy } agent_config['proxy']['no_proxy'] = no_proxy if !no_proxy.nil? end ## Process agent options ## process_config = { enabled: process_agent_enabled, log_file: node['datadog']['process_agent']['log_file'], intervals: { container: node['datadog']['process_agent']['container_interval'], container_realtime: node['datadog']['process_agent']['rtcontainer_interval'], process: node['datadog']['process_agent']['process_interval'], process_realtime: node['datadog']['process_agent']['rtprocess_interval'], }, blacklist_patterns: node['datadog']['process_agent']['blacklist'], scrub_args: node['datadog']['process_agent']['scrub_args'], custom_sensitive_words: node['datadog']['process_agent']['custom_sensitive_words'], process_dd_url: node['datadog']['process_agent']['url'] } # Take into account options defined under ['extra_config']['process_config'] process_config = @extra_config['process_config'].merge(process_config) unless @extra_config['process_config'].nil? agent_config[:process_config] = process_config # Remove nil values agent_config[:process_config][:intervals].reject!{ |k,v| v.nil? } agent_config[:process_config].reject!{ |k,v| v.nil? } ## Trace agent options ## apm_config = { enabled: node['datadog']['enable_trace_agent'], env: node['datadog']['trace_env'], extra_sample_rate: node['datadog']['extra_sample_rate'], max_traces_per_second: node['datadog']['max_traces_per_second'], receiver_port: node['datadog']['receiver_port'], apm_non_local_traffic: node['datadog']['non_local_traffic'] } apm_config.reject!{ |k,v| v.nil? } # Take into account options defined under ['extra_config']['apm_config'] apm_config = @extra_config['apm_config'].merge(apm_config) unless @extra_config['apm_config'].nil? agent_config[:apm_config] = apm_config # Remove nil values agent_config.reject!{ |k,v| v.nil? } -%> # Generated by Chef, local modifications will be overwritten <%= JSON.parse(agent_config.to_json).to_yaml %>