Skip to content

Commit

Permalink
WIP: postfix exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjfisher committed Nov 26, 2019
1 parent 6ef92f6 commit 78021c1
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
142 changes: 142 additions & 0 deletions manifests/postfix_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Class: prometheus::postfix_exporter
#
# This module manages prometheus postfix_exporter
#
# Parameters:
# [*arch*]
# Architecture (amd64 or i386)
#
# [*bin_dir*]
# Directory where binaries are located
#
# [*config_mode*]
# The permissions of the configuration files
#
# [*download_extension*]
# Extension for the release binary archive
#
# [*download_url*]
# Complete URL corresponding to the where the release binary archive can be downloaded
#
# [*download_url_base*]
# Base URL for the binary archive
#
# [*extra_groups*]
# Extra groups to add the binary user to
#
# [*extra_options*]
# Extra options added to the startup command
#
# [*group*]
# Group under which the binary is running
#
# [*init_style*]
# Service startup scripts style (e.g. rc, upstart or systemd)
#
# [*install_method*]
# Installation method: url or package (only url is supported currently)
#
# [*manage_group*]
# Whether to create a group for or rely on external code for that
#
# [*manage_service*]
# Should puppet manage the service? (default true)
#
# [*manage_user*]
# Whether to create user or rely on external code for that
#
# [*os*]
# Operating system (linux is the only one supported)
#
# [*package_ensure*]
# If package, then use this for package ensure default 'latest'
#
# [*package_name*]
# The binary package name - not available yet
#
# [*purge_config_dir*]
# Purge config files no longer generated by Puppet
#
# [*restart_on_change*]
# Should puppet restart the service on configuration change? (default true)
#
# [*service_enable*]
# Whether to enable the service from puppet (default true)
#
# [*service_ensure*]
# State ensured for the service (default 'running')
#
# [*user*]
# User which runs the service
#
# [*version*]
# The binary release version

class prometheus::postfix_exporter (
String $download_extension = '',
Stdlib::HTTPUrl $download_url_base = 'https://github.com/kumina/postfix_exporter/releases',
String[1] $group = 'postfix-exporter',
Array[String[1]] $extra_groups = [],
String[1] $package_ensure = 'installed',
String[1] $package_name = 'postfix_exporter',
String[1] $user = 'postfix-exporter',
String[1] $version = '0.2.0',
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
String[1] $service_ensure = 'running',
String $service_name = 'postfix_exporter',
String[1] $init_style = $prometheus::init_style,
String[1] $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
String[1] $os = $prometheus::os,
String $extra_options = '',
Hash[String, Scalar] $env_vars = {},
Optional[Stdlib::HTTPUrl] $download_url = undef,
String[1] $config_mode = $prometheus::config_mode,
String[1] $arch = $prometheus::real_arch,
Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir,

Boolean $export_scrape_job = false,
Stdlib::Port $scrape_port = 9154,
String[1] $scrape_job_name = 'postfix',
Optional[Hash] $scrape_job_labels = undef,
) inherits prometheus {

$real_download_url = pick($download_url,"${download_url_base}/download/${version}/${package_name}")
$notify_service = $restart_on_change ? {
true => Service[$service_name],
default => undef,
}

prometheus::daemon { $service_name:
install_method => $install_method,
version => $version,
download_extension => $download_extension,
os => $os,
arch => $arch,
real_download_url => $real_download_url,
bin_dir => $bin_dir,
notify_service => $notify_service,
package_name => $package_name,
package_ensure => $package_ensure,
manage_user => $manage_user,
user => $user,
extra_groups => $extra_groups,
group => $group,
manage_group => $manage_group,
purge => $purge_config_dir,
options => $extra_options,
env_vars => $env_vars,
init_style => $init_style,
service_ensure => $service_ensure,
service_enable => $service_enable,
manage_service => $manage_service,
export_scrape_job => $export_scrape_job,
scrape_port => $scrape_port,
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
}
}
36 changes: 36 additions & 0 deletions spec/acceptance/postfix_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper_acceptance'

describe 'prometheus postfix exporter' do
describe 'install postfix' do
before do
install_module_from_forge('camptocamp/postfix', '>= 1.8.0 < 2.0.0')
end
it do
pp = 'include postfix'
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
end
context 'default version' do
it 'postfix_exporter works idempotently with no errors' do
pp = 'class { "prometheus::postfix_exporter": extra_options => "--systemd.enable --systemd.unit=\"postfix.service\" --postfix.logfile_path=\"\""}'
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('postfix_exporter') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

describe port(9154) do
it { is_expected.to be_listening.with('tcp6') }
end

it 'provides postfix metrics' do
shell('curl -s http://127.0.0.1:9154/metrics') do |r|
expect(r.stdout).to match(%r{postfix_smtpd_connects_total})
end
end
end
end

0 comments on commit 78021c1

Please sign in to comment.