From 3927ac61d185ebb65bbd7327a992b7778557da42 Mon Sep 17 00:00:00 2001 From: "Montague, Brent" Date: Wed, 6 Sep 2023 23:08:54 -0400 Subject: [PATCH] Add datadog_monitor option to set the config file name 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. --- resources/monitor.rb | 5 +++-- test/cookbooks/test/recipes/monitor_add.rb | 5 +++++ test/cookbooks/test/recipes/monitor_remove.rb | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/monitor.rb b/resources/monitor.rb index 2c930126..55a7e4b2 100644 --- a/resources/monitor.rb +++ b/resources/monitor.rb @@ -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}") @@ -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 @@ -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 diff --git a/test/cookbooks/test/recipes/monitor_add.rb b/test/cookbooks/test/recipes/monitor_add.rb index 7f6e3d15..2073ff01 100644 --- a/test/cookbooks/test/recipes/monitor_add.rb +++ b/test/cookbooks/test/recipes/monitor_add.rb @@ -15,3 +15,8 @@ datadog_monitor 'potato' do action :add end + +datadog_monitor 'potato' do + action :add + config_name 'potato-one' +end \ No newline at end of file diff --git a/test/cookbooks/test/recipes/monitor_remove.rb b/test/cookbooks/test/recipes/monitor_remove.rb index 8ad5b8d7..ff81253d 100644 --- a/test/cookbooks/test/recipes/monitor_remove.rb +++ b/test/cookbooks/test/recipes/monitor_remove.rb @@ -15,3 +15,8 @@ datadog_monitor 'potato' do action :remove end + +datadog_monitor 'potato' do + action :remove + config_name 'potato-one' +end \ No newline at end of file