-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
source 'https://supermarket.getchef.com' | ||
|
||
metadata | ||
|
||
group :integration do | ||
cookbook 'sudo' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Cookbook Name:: datadog | ||
# Recipe:: postfix | ||
# | ||
|
||
# Monitor postfix | ||
# | ||
# Assuming you have 2 instances "prod" and "test", you will need to set | ||
# up the following attributes at some point in your Chef run, in either | ||
# a role or another cookbook. | ||
# | ||
# node['datadog']['postfix']['instances'] = [ | ||
# { | ||
# 'directory' => '/var/spool/postfix', | ||
# 'queues' => ['incoming', 'active', 'deferred'], | ||
# 'tags' => ['prod', 'postfix_core'] | ||
# }, | ||
# { | ||
# 'directory' => '/var/spool/postfix', | ||
# 'queues' => ['bounce'], | ||
# 'tags' => ['test'] | ||
# } | ||
# ] | ||
|
||
include_recipe 'datadog::dd-agent' | ||
include_recipe 'sudo' # ~FC007 uses `suggests` | ||
|
||
postfix_instances = Array(node['datadog']['postfix']['instances']) | ||
postfix_commands = postfix_instances.map do |instance| | ||
"/usr/bin/find #{instance['directory']}" | ||
end | ||
|
||
sudo 'dd-agent-find-postfix' do | ||
user 'dd-agent' | ||
nopasswd true | ||
commands postfix_commands.uniq | ||
only_if { postfix_instances.any? } | ||
end | ||
|
||
datadog_monitor 'postfix' do | ||
instances postfix_instances | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Each instance requires a directory and an array of queues. | ||
# Tags are optional. | ||
instances: | ||
<% @instances.each do |instance| -%> | ||
- directory: <%= instance['directory'] %> | ||
queues: | ||
<% Array(instance['queues']).each do |queue| -%> | ||
- <%= queue %> | ||
<% end -%> | ||
tags: | ||
<% Array(instance['tags']).each do |tag| -%> | ||
- <%= tag %> | ||
<% end -%> | ||
<% end -%> | ||
|
||
# Postfix check does not require any init_config | ||
init_config: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../helpers/serverspec/Gemfile |
39 changes: 39 additions & 0 deletions
39
test/integration/datadog_postfix/serverspec/postfix_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Encoding: utf-8 | ||
require 'json_spec' | ||
require 'serverspec' | ||
require 'yaml' | ||
|
||
set :backend, :exec | ||
set :path, '/sbin:/usr/local/sbin:$PATH' | ||
|
||
AGENT_CONFIG = '/etc/dd-agent/conf.d/postfix.yaml' | ||
|
||
describe service('datadog-agent') do | ||
it { should be_running } | ||
end | ||
|
||
describe file(AGENT_CONFIG) do | ||
it { should be_a_file } | ||
|
||
it 'is valid yaml matching input values' do | ||
generated = YAML.load_file(AGENT_CONFIG) | ||
|
||
expected = { | ||
'instances' => [ | ||
{ | ||
'directory' => '/var/spool/postfix', | ||
'queues' => ['incoming', 'active', 'deferred'], | ||
'tags' => ['prod', 'postfix_core'] | ||
}, | ||
{ | ||
'directory' => '/var/spool/postfix', | ||
'queues' => ['bounce'], | ||
'tags' => ['test'] | ||
} | ||
], | ||
'init_config' => nil | ||
} | ||
|
||
expect(generated.to_json).to be_json_eql expected.to_json | ||
end | ||
end |