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

Directory check integration #277

Closed
wants to merge 6 commits into from
Closed
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
16 changes: 16 additions & 0 deletions recipes/directory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_recipe 'datadog::dd-agent'

# Monitor files in a directory
#
# node['datadog']['directory']['instances'] = [
# {
# 'directory' => "/path/to/directory",
# 'name' => 'tag_name',
# 'pattern' => '*.log",
# 'recursive' => true
# }
# ]

datadog_monitor 'directory' do
instances node['datadog']['directory']['instances']
end
50 changes: 50 additions & 0 deletions spec/integrations/directory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
describe 'datadog::directory' do
expected_yaml = <<-EOF
init_config:
instances:
- directory: "/path/to/directory"
name: "tag_value"
dirtagname: "tag_dirname"
filetagname: "tag_filename"
filegauges: False
pattern: "*.log"
recursive: True
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',
directory: {
instances: [
{
directory: '/path/to/directory',
name: 'tag_value',
dirtagname: 'tag_dirname',
filetagname: 'tag_filename',
filegauges: false,
pattern: '*.log',
recursive: true
}
]
}
}
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('directory') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/directory.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
13 changes: 13 additions & 0 deletions templates/default/directory.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
instances:
<% @instances.each do |i| -%>
- directory: "<%= i['directory'] %>"
<% if i['name'] -%>name: "<%= i['name'] %>"<% end -%>
<% if i['dirtagname'] -%>dirtagname: "<%= i['dirtagname'] %>"<% end -%>
<% if i['filetagname'] -%>filetagname: "<%= i['filetagname'] %>"<% end -%>
<% if i.key?('filegauges') -%>filegauges: <%= i['filegauges'] %><% end -%>
<% if i['pattern'] -%>pattern: "<%= i['pattern'] %>"<% end -%>
<% if i.key?('recursive') -%>recursive: <%= i['recursive'] %><% end -%>
<% end -%>

# Nothing to configure here
init_config: