Skip to content

Commit

Permalink
Support SSL exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Jun 25, 2021
1 parent cf0d3f2 commit f8c8a20
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
138 changes: 138 additions & 0 deletions manifests/ssl_exporter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# @summary This module manages prometheus ssl_exporter (https://github.com/ribbybibby/ssl_exporter)
# @param arch
# Architecture (amd64 or i386)
# @param bin_dir
# Directory where binaries are located
# @param config_file
# Path to SSL exporter configuration file
# @param config_mode
# The permissions of the configuration files
# @param download_extension
# Extension for the release binary archive
# @param download_url
# Complete URL corresponding to the where the release binary archive can be downloaded
# @param download_url_base
# Base URL for the binary archive
# @param extra_groups
# Extra groups to add the binary user to
# @param extra_options
# Extra options added to the startup command
# @param group
# Group under which the binary is running
# @param init_style
# Service startup scripts style (e.g. rc, upstart or systemd)
# @param install_method
# Installation method: url or package (only url is supported currently)
# @param manage_group
# Whether to create a group for or rely on external code for that
# @param manage_service
# Should puppet manage the service? (default true)
# @param manage_user
# Whether to create user or rely on external code for that
# @param modules
# Hash of SSL exporter modules
# @param os
# Operating system (linux is the only one supported)
# @param package_ensure
# If package, then use this for package ensure default 'latest'
# @param package_name
# The binary package name - not available yet
# @param purge_config_dir
# Purge config files no longer generated by Puppet
# @param restart_on_change
# Should puppet restart the service on configuration change? (default true)
# @param service_enable
# Whether to enable the service from puppet (default true)
# @param service_ensure
# State ensured for the service (default 'running')
# @param service_name
# Name of the node exporter service (default 'ssk_exporter')
# @param user
# User which runs the service
# @param version
# The binary release version
class prometheus::ssl_exporter (
Stdlib::Absolutepath $config_file = '/etc/ssl_exporter.yaml',
String[1] $package_name = 'ssl_exporter',
String $download_extension = 'tar.gz',
String[1] $version = '2.2.1',
String[1] $package_ensure = 'latest',
String[1] $user = 'ssl-exporter',
String[1] $group = 'ssl-exporter',
Prometheus::Uri $download_url_base = 'https://github.com/ribbybibby/ssl_exporter/releases',
Array[String] $extra_groups = [],
Prometheus::Initstyle $init_style = $facts['service_provider'],
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
Stdlib::Ensure::Service $service_ensure = 'running',
String[1] $service_name = 'ssl_exporter',
Prometheus::Install $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
String[1] $os = downcase($facts['kernel']),
String $extra_options = '',
Optional[Prometheus::Uri] $download_url = undef,
String[1] $config_mode = $prometheus::config_mode,
String[1] $arch = $prometheus::real_arch,
String[1] $bin_dir = $prometheus::bin_dir,
Optional[Stdlib::Host] $scrape_host = undef,
Boolean $export_scrape_job = false,
Stdlib::Port $scrape_port = 9219,
String[1] $scrape_job_name = 'ssl',
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $bin_name = undef,
Hash $modules = {},
) inherits prometheus {
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")

$notify_service = $restart_on_change ? {
true => Service[$service_name],
default => undef,
}

file { $config_file:
ensure => file,
owner => $user,
group => $group,
mode => $config_mode,
content => epp('prometheus/ssl_exporter.yaml.epp', { 'modules' => $modules }),
notify => $notify_service,
}

$options = join([
"--config.file=${config_file}",
$extra_options,
], ' ')

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 => $options,
init_style => $init_style,
service_ensure => $service_ensure,
service_enable => $service_enable,
manage_service => $manage_service,
export_scrape_job => $export_scrape_job,
scrape_host => $scrape_host,
scrape_port => $scrape_port,
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
bin_name => $bin_name,
}
}
17 changes: 17 additions & 0 deletions spec/acceptance/ssl_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper_acceptance'

describe 'prometheus ssl exporter' do
it 'ssl_exporter works idempotently with no errors' do
pp = 'include prometheus::ssl_exporter'
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('ssl_exporter') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
describe port(9219) do
it { is_expected.to be_listening.with('tcp6') }
end
end
45 changes: 45 additions & 0 deletions spec/classes/ssl_exporter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

describe 'prometheus::ssl_exporter' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(os_specific_facts(facts))
end

context 'with version specified' do
let(:params) do
{
version: '2.2.1',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url',
modules: {
'https' => {
'prober' => 'https',
'timeout' => '5s',
},
}
}
end

describe 'with all defaults' do
it { is_expected.to contain_class('prometheus') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/usr/local/bin/ssl_exporter').with('target' => '/opt/ssl_exporter-2.2.1.linux-amd64/ssl_exporter') }
it { is_expected.to contain_prometheus__daemon('ssl_exporter') }
it { is_expected.to contain_user('ssl-exporter') }
it { is_expected.to contain_group('ssl-exporter') }
it { is_expected.to contain_service('ssl_exporter') }
it { is_expected.to contain_archive('/tmp/ssl_exporter-2.2.1.tar.gz') }
it { is_expected.to contain_file('/opt/ssl_exporter-2.2.1.linux-amd64/ssl_exporter') }
it {
is_expected.to contain_file('/etc/ssl_exporter.yaml')
verify_contents(catalogue, '/etc/ssl_exporter.yaml', ['---', 'modules:', ' https:', ' prober: https', ' timeout: 5s'])
}
end
end
end
end
end
3 changes: 3 additions & 0 deletions templates/ssl_exporter.yaml.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- | Hash $modules | -%>
<%- $config = { 'modules' => $modules } -%>
<%= to_yaml($config) -%>

0 comments on commit f8c8a20

Please sign in to comment.