Skip to content
Open
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

This file is used to list changes made in each version of the aws_cloudwatch cookbook.

## 1.0.2 (2019-04.07)
## 1.0.3 (2019-10-07)
- Allow variables to be passed to amazon-cloudwatch-agent.json template

## 1.0.2 (2019-04-07)
- Ubuntu-18.04 support

## 1.0.1 (2019-01-14)
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ Amazon CloudWatch Agent configuration file which defines which metrics/logs are
Place the `amazon-cloudwatch-agent.json.erb` file to `templates` directory. This is an agent configuration for metrics and logs collection.
See AWS documentation for more information: [Manually Create or Edit the CloudWatch Agent Configuration File](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Complete-Example)

### json_variables

A hash of variables can be passed into the template file. This is similar to the way variables are used in the [template resource](https://docs.chef.io/resources/template/).
As an example, define your resource with variables:

```
aws_cloudwatch_agent 'default' do
action [:install, :configure, :restart]
json_config 'amazon-cloudwatch-agent.json.erb'
json_variables ({
:disks => '/'
})
end
```

Then define your `amazon-cloudwatch-agent.json.erb` template:

```
{
"metrics": {
"metrics_collected": {
"disk": {
"measurement": [
"used_percent"
],
"resources": [
<%= @disks %>
]
}
}
}
}
```

### config

Expand Down Expand Up @@ -105,13 +138,17 @@ The `aws_cloudwatch_agent` resource installs AWS Cloudwatch Agent.
* `config` - A template name for a custom `test-config.toml` file
* `config_params` - A hash with `test-config.toml` parameters
* `json_config` - A template name for an `amazon-cloudwatch-agent.json` file
* `json_variables` - A hash with variables available to the `amazon-cloudwatch-agent.json` template

#### Example

```
aws_cloudwatch_agent 'default' do
action [:install, :configure, :restart]
json_config 'amazon-cloudwatch-agent.json.erb'
json_variables ({
:disks => '/'
})
config_params :shared_credential_profile => 'test_profile',
:shared_credential_file => '/etc/test_credential_file',
:http_proxy => 'http://192.168.0.1',
Expand Down
6 changes: 5 additions & 1 deletion libraries/agent_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AgentInstaller < Chef::Resource

property :config, String
property :json_config, String
property :json_variables, Hash
property :config_params, Hash, default: {'param' => 'value'}

default_action :install
Expand Down Expand Up @@ -111,6 +112,9 @@ class AgentInstaller < Chef::Resource
template json_path do
action :create
source new_resource.json_config
if new_resource.json_variables
variables new_resource.json_variables
end
end
script 'amazon-cloudwatch-agent-config-translator' do
action :run
Expand Down Expand Up @@ -196,4 +200,4 @@ class AgentInstaller < Chef::Resource
end
end
end
end
end
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
maintainer 'Gennady Potapov'
license 'Apache-2.0'
description 'Provides aws_cloudwatch_agent resource'
version '1.0.2'
version '1.0.3'
chef_version '>= 12.14' if respond_to?(:chef_version)

supports 'ubuntu', '= 14.04'
Expand Down