Skip to content

Commit

Permalink
Fixed #429 - Add Recipe for disk integration
Browse files Browse the repository at this point in the history
  • Loading branch information
iancward committed Apr 28, 2017
1 parent a49ebbe commit cc45c15
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
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' => 'yes',
# 'excluded_filesystems' => [
# 'tmpfs'
# ],
# 'excluded_disks' => [
# '/dev/sda1',
# '/dev/sda2'
# ],
# 'excluded_disk_re' => '/dev/sde.*',
# 'tag_by_filesystem' => 'no',
# 'excluded_mountpoint_re' => '/mnt/somebody-elses-problem.*',
# 'all_partitions' => 'no'
# }
# ]

datadog_monitor 'disk' do
instances node['datadog']['disk']['instances']
init_config nil
end
56 changes: 56 additions & 0 deletions spec/integrations/disk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
describe 'datadog::disk' do
expected_yaml = <<-EOF
init_config: {}
instances:
- use_mount: 'yes'
excluded_filesystems:
- tmpfs
excluded_disks:
- /dev/sda1
- /dev/sda2
excluded_disk_re: '/dev/sde.*'
tag_by_filesystem: 'no'
excluded_mountpoint_re: '/mnt/somebody-elses-problem.*'
all_partitions: 'no'
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: 'yes',
excluded_filesystems: ['tmpfs'],
excluded_disks: ['/dev/sda1', '/dev/sda2'],
excluded_disk_re: '/dev/sde.*',
tag_by_filesystem: 'no',
excluded_mountpoint_re: '/mnt/somebody-elses-problem.*',
all_partitions: 'no'
}
]
}
}
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 %>

0 comments on commit cc45c15

Please sign in to comment.