diff --git a/manifests/prometheus_client.pp b/manifests/prometheus_client.pp new file mode 100644 index 0000000..9e0ceba --- /dev/null +++ b/manifests/prometheus_client.pp @@ -0,0 +1,52 @@ +# == Class: watcher::prometheus_client +# +# Configure the prometheus_client options +# +# === Parameters +# +# [*host*] +# (Required) The hostname of IP address for the prometheus server. +# +# [*port*] +# (Optional) The port number used by the prometheus server. +# Defaults to $facts['os_service_default'] +# +# [*fqdn_label*] +# (Optional) The label that Prometheus uses to store the fqdn of exporters. +# Defaults to $facts['os_service_default'] +# +# [*instance_uuid_label*] +# (Optional) The label that Prometheus uses to store the uuid of OpenStack +# instances. +# Defaults to $facts['os_service_default'] +# +# [*username*] +# (Optional) The basic_auth username to use to authenticate with +# the Prometheus server. +# Defaults to $facts['os_service_default']. +# +# [*password*] +# (Optional) The basic_auth password to use to authenticate with +# the Prometheus server. +# Defaults to $facts['os_service_default']. +# +class watcher::prometheus_client ( + $host, + $port = $facts['os_service_default'], + $fqdn_label = $facts['os_service_default'], + $instance_uuid_label = $facts['os_service_default'], + $username = $facts['os_service_default'], + $password = $facts['os_service_default'], +) { + + include watcher::deps + + watcher_config { + 'prometheus_client/host': value => $host; + 'prometheus_client/port': value => $port; + 'prometheus_client/fqdn_label': value => $fqdn_label; + 'prometheus_client/instance_uuid_label': value => $instance_uuid_label; + 'prometheus_client/username': value => $username; + 'prometheus_client/password': value => $password, secret => true; + } +} diff --git a/releasenotes/notes/prometheus_client-8263eb5873bf0708.yaml b/releasenotes/notes/prometheus_client-8263eb5873bf0708.yaml new file mode 100644 index 0000000..3b6725b --- /dev/null +++ b/releasenotes/notes/prometheus_client-8263eb5873bf0708.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + The new ``watcher::prometheus_client`` class has been added. diff --git a/spec/classes/watcher_prometheus_client_spec.rb b/spec/classes/watcher_prometheus_client_spec.rb new file mode 100644 index 0000000..daa6871 --- /dev/null +++ b/spec/classes/watcher_prometheus_client_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe 'watcher::prometheus_client' do + + shared_examples 'watcher::prometheus_client' do + let :params do + { + :host => '127.0.0.1' + } + end + + context 'with defaults' do + it 'should set the defaults' do + should contain_watcher_config('prometheus_client/host').with_value('127.0.0.1') + should contain_watcher_config('prometheus_client/port').with_value('') + should contain_watcher_config('prometheus_client/fqdn_label').with_value('') + should contain_watcher_config('prometheus_client/instance_uuid_label').with_value('') + should contain_watcher_config('prometheus_client/username').with_value('') + should contain_watcher_config('prometheus_client/password').with_value('').with_secret(true) + end + end + + context 'with parameters overridden' do + before :each do + params.merge!({ + :port => 9090, + :fqdn_label => 'fqdn', + :instance_uuid_label => 'resource', + :username => 'promuser', + :password => 'prompass' + }) + end + + it 'should set the overridden values' do + should contain_watcher_config('prometheus_client/host').with_value('127.0.0.1') + should contain_watcher_config('prometheus_client/port').with_value(9090) + should contain_watcher_config('prometheus_client/fqdn_label').with_value('fqdn') + should contain_watcher_config('prometheus_client/instance_uuid_label').with_value('resource') + should contain_watcher_config('prometheus_client/username').with_value('promuser') + should contain_watcher_config('prometheus_client/password').with_value('prompass').with_secret(true) + end + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + it_behaves_like 'watcher::prometheus_client' + end + end + +end