Correctly use url info while needed in other recipes.
MODIFY
attributes/default.rb
attributes/default.rb
@@ -67,8 +67,9 @@ default['datadog']['agent6_config_dir'] =
end
# The site of the Datadog intake to send Agent data to.
+# This configuration option is supported since Agent 6.6
# Defaults to 'datadoghq.com', set to 'datadoghq.eu' to send data to the EU site.
-default['datadog']['site'] = 'datadoghq.com'
+default['datadog']['site'] = nil
# Set a key to true to make the agent6 use the v2 api on that endpoint, false otherwise.
# Leave key value to nil to use agent6 default for that endpoint.

MODIFY
recipes/_agent6_config.rb
recipes/_agent6_config.rb
is_windows = node['platform_family'] == 'windows'
+# use either the site option or the url one, the latter having priority.
+dd_url = 'https://app.datadoghq.com'
+if node['datadog']['site']
+ dd_url = 'https://app.' + node['datadog']['site']
+end
+if node['datadog']['url']
+ dd_url = node['datadog']['url']
+end
+
agent6_config_file = ::File.join(node['datadog']['agent6_config_dir'], 'datadog.yaml')
template agent6_config_file do
def template_vars
@@ -28,7 +37,7 @@ template agent6_config_file do
url = if endpoint['url']
endpoint['url']
else
- node['datadog']['url']
+ dd_url
end
if additional_endpoints.key?(url)
additional_endpoints[url] << endpoint['api_key']

MODIFY
recipes/dd-agent.rb
recipes/dd-agent.rb
@@ -39,6 +39,15 @@ agent_enable = node['datadog']['agent_enable'] ? :enable : :disable
# Set the correct Agent startup action
agent_start = node['datadog']['agent_start'] ? :start : :stop
+# use either the site option or the url one, the latter having priority.
+dd_url = 'https://app.datadoghq.com'
+if node['datadog']['site']
+ dd_url = 'https://app.' + node['datadog']['site']
+end
+if node['datadog']['url']
+ dd_url = node['datadog']['url']
+end
+
#
# Configures a basic agent
# To add integration-specific configurations, add 'datadog::config_name' to
@@ -66,14 +75,14 @@ else
template agent_config_file do
def template_vars
api_keys = [Chef::Datadog.api_key(node)]
- dd_urls = [node['datadog']['url']]
+ dd_urls = [dd_url]
node['datadog']['extra_endpoints'].each do |_, endpoint|
next unless endpoint['enabled']
api_keys << endpoint['api_key']
dd_urls << if endpoint['url']
endpoint['url']
else
- node['datadog']['url']
+ dd_url
end
end
{

MODIFY
recipes/dd-handler.rb
recipes/dd-handler.rb
@@ -26,7 +26,17 @@ if Chef::Config[:why_run]
end
include_recipe 'chef_handler'
-ENV['DATADOG_HOST'] = node['datadog']['url']
+
+# use either the site option or the url one, the latter having priority.
+node.run_state['dd_url'] = 'https://app.datadoghq.com'
+if node['datadog']['site']
+ node.run_state['dd_url'] = 'https://app.' + node['datadog']['site']
+end
+if node['datadog']['url']
+ node.run_state['dd_url'] = node['datadog']['url']
+end
+
+ENV['DATADOG_HOST'] = node.run_state['dd_url']
chef_gem 'chef-handler-datadog' do # ~FC009
action :install
@@ -61,12 +71,13 @@ chef_handler 'Chef::Handler::Datadog' do
def handler_config
extra_config = node['datadog']['handler_extra_config'].reject { |_, v| v.nil? }
+
config = extra_config.merge(
:api_key => Chef::Datadog.api_key(node),
:application_key => Chef::Datadog.application_key(node),
:use_ec2_instance_id => node['datadog']['use_ec2_instance_id'],
:tag_prefix => node['datadog']['tag_prefix'],
- :url => node['datadog']['url'],
+ :url => node.run_state['dd_url'],
:extra_endpoints => extra_endpoints,
:tags_blacklist_regex => node['datadog']['tags_blacklist_regex'],
:send_policy_tags => node['datadog']['send_policy_tags'],

Correctly use url info while needed in other recipes.