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

Fixed #429 - Add Recipe for disk integration #430

Merged
merged 3 commits into from
May 3, 2017
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
35 changes: 35 additions & 0 deletions recipes/disk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Cookbook Name: datadog
# Recipe: disk
#
# This recipe exists to apply (optional) configuration to the disk integration
# This recipe does not need to be included to use the disk integration,
# but it allows you to override some defaults that the disk integration
# provides.
# For more information on the integration itself, see:
# https://docs.datadoghq.com/integrations/disk/

include_recipe 'datadog::dd-agent'

# example configuration:
# node['datadog']['disk']['instances'] = [
# {
# 'use_mount' => true,
# 'excluded_filesystems' => [
# 'tmpfs'
# ],
# 'excluded_disks' => [
# '/dev/sda1',
# '/dev/sda2'
# ],
# 'excluded_disk_re' => '/dev/sde.*',
# 'tag_by_filesystem' => false,
# 'excluded_mountpoint_re' => '/mnt/somebody-elses-problem.*',
# 'all_partitions' => false
# }
# ]

datadog_monitor 'disk' do
instances node['datadog']['disk']['instances']
init_config nil
end
55 changes: 55 additions & 0 deletions spec/integrations/disk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
describe 'datadog::disk' do
expected_yaml = <<-EOF
init_config: {}

instances:
- use_mount: true
excluded_filesystems:
- tmpfs
excluded_disks:
- /dev/sda1
- /dev/sda2
excluded_disk_re: '/dev/sde.*'
tag_by_filesystem: false
excluded_mountpoint_re: '/mnt/somebody-elses-problem.*'
all_partitions: false
EOF

cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } }
node.set['datadog'] = {
api_key: 'someapikey',
disk: {
instances: [
{
use_mount: true,
excluded_filesystems: ['tmpfs'],
excluded_disks: ['/dev/sda1', '/dev/sda2'],
excluded_disk_re: '/dev/sde.*',
tag_by_filesystem: false,
excluded_mountpoint_re: '/mnt/somebody-elses-problem.*',
all_partitions: false
}
]
}
}
end.converge(described_recipe)
end

subject { chef_run }

it_behaves_like 'datadog-agent'

it { is_expected.to include_recipe('datadog::dd-agent') }

it { is_expected.to add_datadog_monitor('disk') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/disk.yaml').with_content { |content|
expect(YAML.safe_load(content).to_json).to be_json_eql(
YAML.safe_load(expected_yaml).to_json
)
}
end
end
3 changes: 3 additions & 0 deletions templates/default/disk.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by Chef, local modifications will be overwritten

<%= JSON.parse(({ 'instances' => @instances, 'init_config' => @init_config }).to_json).to_yaml %>