Skip to content

Commit

Permalink
add support for postfix integration
Browse files Browse the repository at this point in the history
  • Loading branch information
phlipper committed Jun 29, 2015
1 parent 448e3a9 commit a695eff
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,25 @@ suites:
- name: test2
host: localhost
port: 5678
- name: datadog_postfix
run_list:
- recipe[sudo]
- recipe[datadog::postfix]
attributes:
datadog:
<<: *DATADOG
postfix:
instances:
- directory: "/var/spool/postfix"
queues:
- incoming
- active
- deferred
tags:
- prod
- postfix_core
- directory: "/var/spool/postfix"
queues:
- bounce
tags:
- test
4 changes: 4 additions & 0 deletions Berksfile
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
3 changes: 3 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
depends 'chef_handler', '~> 1.1.0'
depends 'yum'

suggests 'sudo'

recipe 'datadog::default', 'Default'
recipe 'datadog::dd-agent', 'Installs the Datadog Agent'
recipe 'datadog::dd-handler', 'Installs a Chef handler for Datadog'
Expand All @@ -32,3 +34,4 @@
# integration-specific
recipe 'datadog::cassandra', 'Installs and configures the Cassandra integration'
recipe 'datadog::couchdb', 'Installs and configures the CouchDB integration'
recipe 'datadog::postfix', 'Installs and configures the Postfix integration'
42 changes: 42 additions & 0 deletions recipes/postfix.rb
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
17 changes: 17 additions & 0 deletions templates/default/postfix.yaml.erb
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:
1 change: 1 addition & 0 deletions test/integration/datadog_postfix/serverspec/Gemfile
39 changes: 39 additions & 0 deletions test/integration/datadog_postfix/serverspec/postfix_spec.rb
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

0 comments on commit a695eff

Please sign in to comment.