Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datadog_monitor option to override the config file name #903

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,21 @@ datadog_monitor 'name' do
instances Array # default value: []
logs Array # default value: []
use_integration_template true, false # default value: false
config_name String # default value: 'conf'
action Symbol # defaults to :add
end
```
#### Properties
| Property | Description |
|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `'name'` | The name of the Agent integration to configure and enable. |
| `instances` | The fields used to fill values under the `instances` section in the integration configuration file. |
| `init_config` | The fields used to fill values under the the `init_config` section in the integration configuration file. |
| `logs` | The fields used to fill values under the the `logs` section in the integration configuration file. |
| Property | Description |
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `'name'` | The name of the Agent integration to configure and enable. |
| `instances` | The fields used to fill values under the `instances` section in the integration configuration file. |
| `init_config` | The fields used to fill values under the the `init_config` section in the integration configuration file. |
| `logs` | The fields used to fill values under the the `logs` section in the integration configuration file. |
| `use_integration_template` | Set to `true` (recommended) to use the default template, which writes the values of `instances`, `init_config`, and `logs` in the YAML under their respective keys. This defaults to `false` for backward compatibility, but may default to `true` in a future major version of the cookbook. |
| `config_name` | The filename used when creating an integrations configuration file. Overriding this property allows the creation of multiple configuration files for a single integration. This defaults to `conf`, which creates a configuration file named `conf.yaml`. |
#### Example
Expand Down
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", "#{new_resource.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", "#{new_resource.config_name}.yaml")
else
::File.join(yaml_dir, "#{new_resource.name}.yaml")
end
Expand Down
2 changes: 2 additions & 0 deletions spec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ def set_env_var(name, value)
end
it 'creates the config file at A7\'s path' do
expect(chef_run).to render_file('/etc/datadog-agent/conf.d/potato.d/conf.yaml')
expect(chef_run).to render_file('/etc/datadog-agent/conf.d/potato.d/potato-one.yaml')
end
end
end
Expand Down Expand Up @@ -1541,6 +1542,7 @@ def set_env_var(name, value)
end
it 'creates the config file at A7\'s path' do
expect(chef_run).to delete_file('/etc/datadog-agent/conf.d/potato.d/conf.yaml')
expect(chef_run).to delete_file('/etc/datadog-agent/conf.d/potato.d/potato-one.yaml')
end
end
end
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
Loading