diff --git a/REFERENCE.md b/REFERENCE.md
index 2bda4b24b..ffdf082f9 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -6350,6 +6350,8 @@ The following parameters are available in the `prometheus::node_exporter` class:
* [`service_name`](#service_name)
* [`user`](#user)
* [`version`](#version)
+* [`env_vars`](#env_vars)
+* [`env_file_path`](#env_file_path)
* [`scrape_host`](#scrape_host)
* [`export_scrape_job`](#export_scrape_job)
* [`scrape_port`](#scrape_port)
@@ -6446,7 +6448,7 @@ Data type: `Prometheus::Initstyle`
Service startup scripts style (e.g. rc, upstart or systemd)
-Default value: `$facts['service_provider']`
+Default value: `$prometheus::init_style`
##### `install_method`
@@ -6552,6 +6554,22 @@ Data type: `String[1]`
The binary release version
+##### `env_vars`
+
+Data type: `Hash[String[1], Scalar]`
+
+hash with custom environment variables thats passed to the exporter via init script / unit file
+
+Default value: `{}`
+
+##### `env_file_path`
+
+Data type: `Stdlib::Absolutepath`
+
+The path to the file with the environmetn variable that is read from the init script/systemd unit
+
+Default value: `$prometheus::env_file_path`
+
##### `scrape_host`
Data type: `Optional[Stdlib::Host]`
diff --git a/data/Archlinux.yaml b/data/Archlinux.yaml
index 2298b1e76..75d4ac9ad 100644
--- a/data/Archlinux.yaml
+++ b/data/Archlinux.yaml
@@ -4,7 +4,7 @@ prometheus::server::init_style: 'none'
prometheus::version: '2.10.0'
prometheus::install_method: 'package'
prometheus::bin_dir: '/usr/bin'
-prometheus::env_file_path: '/etc/default'
+prometheus::env_file_path: '/etc/conf.d'
prometheus::node_exporter::package_name: 'prometheus-node-exporter'
prometheus::node_exporter::install_method: 'package'
prometheus::node_exporter::bin_name: 'prometheus-node-exporter'
@@ -12,6 +12,8 @@ prometheus::node_exporter::user: 'node_exporter'
prometheus::node_exporter::group: 'node_exporter'
prometheus::node_exporter::manage_user: false
prometheus::node_exporter::manage_group: false
+prometheus::node_exporter::service_name: 'prometheus-node-exporter'
+prometheus::node_exporter::init_style: 'none'
prometheus::bird_exporter::install_method: 'package'
prometheus::bird_exporter::bin_name: 'prometheus-bird-exporter'
prometheus::bird_exporter::package_name: 'prometheus-bird-exporter'
@@ -19,4 +21,3 @@ prometheus::bird_exporter::manage_user: false
prometheus::bird_exporter::manage_group: false
prometheus::bird_exporter::init_style: 'none'
prometheus::bird_exporter::service_name: 'prometheus-bird-exporter'
-prometheus::bird_exporter::env_file_path: '/etc/conf.d'
diff --git a/manifests/node_exporter.pp b/manifests/node_exporter.pp
index c50cc543a..aaf23a24b 100644
--- a/manifests/node_exporter.pp
+++ b/manifests/node_exporter.pp
@@ -54,6 +54,10 @@
# User which runs the service
# @param version
# The binary release version
+# @param env_vars
+# hash with custom environment variables thats passed to the exporter via init script / unit file
+# @param env_file_path
+# The path to the file with the environmetn variable that is read from the init script/systemd unit
class prometheus::node_exporter (
String $download_extension,
Prometheus::Uri $download_url_base,
@@ -68,7 +72,7 @@
Boolean $service_enable = true,
Stdlib::Ensure::Service $service_ensure = 'running',
String[1] $service_name = 'node_exporter',
- Prometheus::Initstyle $init_style = $facts['service_provider'],
+ Prometheus::Initstyle $init_style = $prometheus::init_style,
Prometheus::Install $install_method = $prometheus::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
@@ -87,6 +91,8 @@
String[1] $scrape_job_name = 'node',
Optional[Hash] $scrape_job_labels = undef,
Optional[String[1]] $bin_name = undef,
+ Hash[String[1], Scalar] $env_vars = {},
+ Stdlib::Absolutepath $env_file_path = $prometheus::env_file_path,
) inherits prometheus {
# Prometheus added a 'v' on the realease name at 0.13.0
if versioncmp ($version, '0.13.0') >= 0 {
@@ -145,5 +151,7 @@
scrape_job_name => $scrape_job_name,
scrape_job_labels => $scrape_job_labels,
bin_name => $bin_name,
+ env_vars => $env_vars,
+ env_file_path => $env_file_path,
}
}
diff --git a/spec/classes/node_exporter_spec.rb b/spec/classes/node_exporter_spec.rb
index d6dc25625..d7f82991a 100644
--- a/spec/classes/node_exporter_spec.rb
+++ b/spec/classes/node_exporter_spec.rb
@@ -10,8 +10,6 @@
context 'without parameters' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('prometheus') }
- it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: ' ') }
- it { is_expected.to contain_service('node_exporter') }
if facts[:os]['name'] == 'Archlinux'
it { is_expected.not_to contain_user('node-exporter') }
@@ -19,21 +17,25 @@
it { is_expected.not_to contain_file('/opt/node_exporter-1.0.1.linux-amd64/node_exporter') }
it { is_expected.not_to contain_file('/usr/local/bin/node_exporter') }
it { is_expected.to contain_package('prometheus-node-exporter') }
- it { is_expected.to contain_systemd__unit_file('node_exporter.service') }
+ it { is_expected.not_to contain_systemd__unit_file('node_exporter.service') }
+ it { is_expected.to contain_service('prometheus-node-exporter') }
+ it { is_expected.to contain_prometheus__daemon('prometheus-node-exporter').with(options: ' ') }
else
it { is_expected.to contain_user('node-exporter') }
it { is_expected.to contain_group('node-exporter') }
it { is_expected.to contain_file('/opt/node_exporter-1.0.1.linux-amd64/node_exporter') }
it { is_expected.to contain_file('/usr/local/bin/node_exporter') }
+ it { is_expected.to contain_service('node_exporter') }
+ it { is_expected.to contain_prometheus__daemon('node_exporter').with(options: ' ') }
+ it { is_expected.to contain_systemd__unit_file('node_exporter.service') }
end
-
- # rubocop:disable Style/IdenticalConditionalBranches
# rubocop:disable RSpec/RepeatedExample
if facts[:os]['family'] == 'RedHat'
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
elsif facts[:os]['name'] == 'Archlinux'
- it { is_expected.to contain_file('/etc/default/node_exporter') }
+ it { is_expected.to contain_file('/etc/conf.d/prometheus-node-exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
+ it { is_expected.not_to contain_file('/etc/default/node_exporter') }
else
it { is_expected.not_to contain_file('/etc/default/node_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/node_exporter') }
@@ -47,6 +49,8 @@
{
collectors_enable: %w[foo bar],
collectors_disable: %w[baz qux],
+ init_style: 'systemd',
+ service_name: 'node_exporter',
install_method: 'url'
}
end
@@ -68,7 +72,9 @@
{
collectors_enable: %w[foo bar],
collectors_disable: %w[baz qux],
- extra_options: '--path.procfs /host/proc --path.sysfs /host/sys'
+ extra_options: '--path.procfs /host/proc --path.sysfs /host/sys',
+ service_name: 'node_exporter',
+ install_method: 'url'
}
end
@@ -83,6 +89,7 @@
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
+ service_name: 'node_exporter',
install_method: 'url'
}
end
@@ -98,7 +105,9 @@
context 'with no download_extension' do
let(:params) do
{
+ install_method: 'url',
download_extension: '',
+ service_name: 'node_exporter'
}
end
diff --git a/spec/classes/unbound_exporter_spec.rb b/spec/classes/unbound_exporter_spec.rb
index 94faa7f20..6e27e8a67 100644
--- a/spec/classes/unbound_exporter_spec.rb
+++ b/spec/classes/unbound_exporter_spec.rb
@@ -16,13 +16,21 @@
it { is_expected.to contain_user('unbound-exporter') }
it { is_expected.to contain_systemd__unit_file('unbound_exporter.service') }
+ # rubocop:disable RSpec/RepeatedExample
if facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_file('/etc/sysconfig/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/default/unbound_exporter') }
+ it { is_expected.not_to contain_file('/etc/conf.d/unbound_exporter') }
+ elsif facts[:os]['name'] == 'Archlinux'
+ it { is_expected.to contain_file('/etc/conf.d/unbound_exporter') }
+ it { is_expected.not_to contain_file('/etc/sysconfig/unbound_exporter') }
+ it { is_expected.not_to contain_file('/etc/default/unbound_exporter') }
else
it { is_expected.to contain_file('/etc/default/unbound_exporter') }
it { is_expected.not_to contain_file('/etc/sysconfig/unbound_exporter') }
+ it { is_expected.not_to contain_file('/etc/conf.d/unbound_exporter') }
end
+ # rubocop:enable RSpec/RepeatedExample
end
end
end