diff --git a/data/defaults.yaml b/data/defaults.yaml index 1e9cc9d58..06a88cb19 100644 --- a/data/defaults.yaml +++ b/data/defaults.yaml @@ -328,3 +328,12 @@ prometheus::apache_exporter::package_ensure: 'latest' prometheus::apache_exporter::package_name: 'apache_exporter' prometheus::apache_exporter::user: 'apache-exporter' prometheus::apache_exporter::version: '0.7.0' +prometheus::grok_exporter::config_file: '/etc/grok-exporter.yaml' +prometheus::grok_exporter::download_extension: 'zip' +prometheus::grok_exporter::download_url_base: 'https://github.com/fstab/grok_exporter/releases' +prometheus::grok_exporter::extra_groups: [] +prometheus::grok_exporter::group: 'grok-exporter' +prometheus::grok_exporter::package_ensure: 'latest' +prometheus::grok_exporter::package_name: 'grok_exporter' +prometheus::grok_exporter::user: 'grok-exporter' +prometheus::grok_exporter::version: '1.0.0.RC3' diff --git a/manifests/grok_exporter.pp b/manifests/grok_exporter.pp new file mode 100644 index 000000000..18ca716d0 --- /dev/null +++ b/manifests/grok_exporter.pp @@ -0,0 +1,133 @@ +# @summary This module manages prometheus grok_exporter +# @param arch +# Architecture (amd64 or i386) +# @param bin_dir +# Directory where binaries are located +# @param config +# Hash of configuration, see https://github.com/fstab/grok_exporter/blob/master/CONFIG.md +# for available options +# @param config_file +# Path to config file, it will be generated from config param +# @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 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 'grok_exporter') +# @param user +# User which runs the service +# @param version +# The binary release version +class prometheus::grok_exporter ( + Hash $config, + String $config_file, + String[1] $download_extension, + Prometheus::Uri $download_url_base, + Array[String[1]] $extra_groups, + String[1] $group, + String[1] $package_ensure, + String[1] $package_name, + String[1] $user, + String[1] $version, + Boolean $purge_config_dir = true, + Boolean $restart_on_change = true, + Boolean $service_enable = true, + Stdlib::Ensure::Service $service_ensure = 'running', + String[1] $service_name = 'grok_exporter', + Prometheus::Initstyle $init_style = $facts['service_provider'], + String[1] $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, + Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir, + Boolean $export_scrape_job = false, + Stdlib::Port $scrape_port = 9144, + String[1] $scrape_job_name = 'grok', + Optional[Hash] $scrape_job_labels = undef, +) inherits prometheus { + + #Please provide the download_url for versions < 0.9.0 + $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, + } + + $options = "-config ${config_file} ${extra_options}" + + file { $config_file: + ensure => present, + owner => 'root', + group => $group, + mode => $config_mode, + content => inline_template('<%= @config.to_yaml %>'), + notify => $notify_service, + } + + 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_port => $scrape_port, + scrape_job_name => $scrape_job_name, + scrape_job_labels => $scrape_job_labels, + } +} diff --git a/spec/classes/grok_exporter_spec.rb b/spec/classes/grok_exporter_spec.rb new file mode 100644 index 000000000..0eea77cee --- /dev/null +++ b/spec/classes/grok_exporter_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'prometheus::grok_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: '1.0.0.RC3', + arch: 'amd64', + os: 'linux', + bin_dir: '/usr/local/bin', + install_method: 'url', + config: { + 'global' => { + 'config_version' => 3 + }, + 'input' => { + 'type' => 'file', + 'path' => '/var/log/syslog' + }, + 'metrics' => [ + { + 'name' => 'syslog_errors', + 'type' => 'counter', + 'help' => 'number of syslog errors', + 'match' => 'error' + } + ] + } + } + 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/grok_exporter').with('target' => '/opt/grok_exporter-1.0.0.RC3.linux-amd64/grok_exporter') } + it { is_expected.to contain_prometheus__daemon('grok_exporter') } + it { is_expected.to contain_user('grok-exporter') } + it { is_expected.to contain_group('grok-exporter') } + it { is_expected.to contain_service('grok_exporter') } + it { is_expected.to contain_archive('/tmp/grok_exporter-1.0.0.RC3.zip') } + it { is_expected.to contain_file('/opt/grok_exporter-1.0.0.RC3.linux-amd64/grok_exporter') } + it { is_expected.to contain_file('/etc/grok-exporter.yaml').with_content(File.read(fixtures('files', 'grok-exporter.yaml'))) } + end + end + end + end +end diff --git a/spec/fixtures/files/grok-exporter.yaml b/spec/fixtures/files/grok-exporter.yaml new file mode 100644 index 000000000..48b1be49e --- /dev/null +++ b/spec/fixtures/files/grok-exporter.yaml @@ -0,0 +1,11 @@ +--- +global: + config_version: 3 +input: + type: file + path: "/var/log/syslog" +metrics: +- name: syslog_errors + type: counter + help: number of syslog errors + match: error