Skip to content

Commit

Permalink
Add datadog_monitor option to set the config file name
Browse files Browse the repository at this point in the history
This allows people to use the integration multiple times and place
different config files in the same integration directory.  The use case
would be many different cookbooks adding a single check they care about
without doing messy attribute overrides.
  • Loading branch information
brentm5 committed Sep 7, 2023
1 parent 252230c commit 3927ac6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions resources/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
property :use_integration_template, [TrueClass, FalseClass], required: false, default: false
property :is_jmx, [TrueClass, FalseClass], required: false, default: false
property :logs, [Array, nil], required: false, default: []
property :config_name, [String, nil], required: false, default: 'conf'

action :add do
Chef::Log.debug("Adding monitoring for #{new_resource.name}")
Expand All @@ -49,7 +50,7 @@
mode '755'
end
end
yaml_file = ::File.join(yaml_dir, "#{new_resource.name}.d", 'conf.yaml')
yaml_file = ::File.join(yaml_dir, "#{new_resource.name}.d", "#{config_name}.yaml")
else
yaml_file = ::File.join(yaml_dir, "#{new_resource.name}.yaml")
end
Expand Down Expand Up @@ -101,7 +102,7 @@

action :remove do
yaml_file = if Chef::Datadog.agent_major_version(node) != 5
::File.join(yaml_dir, "#{new_resource.name}.d", 'conf.yaml')
::File.join(yaml_dir, "#{new_resource.name}.d", "#{config_name}.yaml")
else
::File.join(yaml_dir, "#{new_resource.name}.yaml")
end
Expand Down
5 changes: 5 additions & 0 deletions test/cookbooks/test/recipes/monitor_add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@
datadog_monitor 'potato' do
action :add
end

datadog_monitor 'potato' do
action :add
config_name 'potato-one'
end
5 changes: 5 additions & 0 deletions test/cookbooks/test/recipes/monitor_remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@
datadog_monitor 'potato' do
action :remove
end

datadog_monitor 'potato' do
action :remove
config_name 'potato-one'
end

0 comments on commit 3927ac6

Please sign in to comment.