Migrate to Chef 12.5+ based resource
DELETE
providers/monitor.rb
-# Creates the proper yaml file in /etc/dd-agent/conf.d/
-
-# Defined since Chef 11
-use_inline_resources if defined?(use_inline_resources)
-
-def whyrun_supported?
- true
-end
-
-action :add do
- Chef::Log.debug "Adding monitoring for #{new_resource.name}"
- config_dir = node['datadog']['agent6'] ? node['datadog']['agent6_config_dir'] : node['datadog']['config_dir']
- template ::File.join(config_dir, 'conf.d', "#{new_resource.name}.yaml") do
- if node['platform_family'] == 'windows'
- owner 'Administrators'
- rights :full_control, 'Administrators'
- inherits false
- else
- owner 'dd-agent'
- mode '600'
- end
-
- source 'integration.yaml.erb' if new_resource.use_integration_template
-
- variables(
- init_config: new_resource.init_config,
- instances: new_resource.instances,
- version: new_resource.version
- )
- cookbook new_resource.cookbook
- sensitive true if Chef::Resource.instance_methods(false).include?(:sensitive)
- notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
- end
-
- service 'datadog-agent' do
- service_name node['datadog']['agent_name']
- # HACK: the restart can fail when we hit systemd's restart limits (by default, 5 starts every 10 seconds)
- # To workaround this, retry once after 5 seconds, and a second time after 10 seconds
- retries 2
- retry_delay 5
- end
-end
-
-action :remove do
- config_dir = node['datadog']['agent6'] ? node['datadog']['agent6_config_dir'] : node['datadog']['config_dir']
- confd_dir = ::File.join(config_dir, 'conf.d')
- Chef::Log.debug "Removing #{new_resource.name} from #{confd_dir}"
- file ::File.join(confd_dir, "#{new_resource.name}.yaml") do
- action :delete
- sensitive true if Chef::Resource.instance_methods(false).include?(:sensitive)
- notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
- end
-
- service 'datadog-agent' do
- service_name node['datadog']['agent_name']
- end
-end

MODIFY
resources/monitor.rb
resources/monitor.rb
# Configure a service via its yaml file
-actions :add, :remove
-default_action :add if defined?(default_action)
+default_action :add
-attribute :name, :kind_of => String, :name_attribute => true
-attribute :cookbook, :kind_of => String, :default => 'datadog'
+property :name, String, name_attribute: true
+property :cookbook, String, default: 'datadog'
# checks have 2 sections: init_config and instances
# we mimic these here, no validation is performed until the template
# is evaluated.
-attribute :init_config, :kind_of => Hash, :required => false, :default => {}
-attribute :instances, :kind_of => Array, :required => false, :default => []
-attribute :version, :kind_of => Integer, :required => false, :default => nil
-attribute :use_integration_template, :kind_of => [TrueClass, FalseClass], :required => false, :default => false
+property :init_config, Hash, required: false, default: {}
+property :instances, Array, required: false, default: []
+property :version, Integer, required: false, default: nil
+property :use_integration_template, [TrueClass, FalseClass], required: false, default: false
+
+action :add do
+ log "Adding monitoring for #{new_resource.name}" do
+ level :debug
+ end
+
+ template ::File.join(node['datadog']['config_dir'], 'conf.d', "#{new_resource.name}.yaml") do
+ if node['platform_family'] == 'windows'
+ owner 'Administrators'
+ rights :full_control, 'Administrators'
+ inherits false
+ else
+ owner 'dd-agent'
+ mode '600'
+ end
+
+ source 'integration.yaml.erb' if new_resource.use_integration_template
+
+ variables(
+ init_config: new_resource.init_config,
+ instances: new_resource.instances,
+ version: new_resource.version
+ )
+ cookbook new_resource.cookbook
+ sensitive true
+ notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
+ end
+
+ service 'datadog-agent' do
+ service_name node['datadog']['agent_name']
+ end
+end
+
+action :remove do
+ confd_dir = ::File.join(node['datadog']['config_dir'], 'conf.d')
+
+ log "Removing #{new_resource.name} from #{confd_dir}" do
+ level :debug
+ end
+
+ file ::File.join(confd_dir, "#{new_resource.name}.yaml") do
+ action :delete
+ sensitive true
+ notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
+ end
+
+ service 'datadog-agent' do
+ service_name node['datadog']['agent_name']
+ end
+end

Migrate to Chef 12.5+ based resource