Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Alertmanager config #277

Merged
merged 13 commits into from
May 30, 2019
35 changes: 27 additions & 8 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,33 @@
recurse => $purge_config_dir,
}

file { $config_file:
ensure => present,
owner => $user,
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
require => File[$config_dir],
if ( versioncmp($version, '0.10.0') >= 0 ) {
# If version >= 0.10.0 then install amtool - Alertmanager validation tool
file {"${bin_dir}/amtool":
ensure => link,
target => "/opt/${package_name}-${version}.${os}-${arch}/amtool",
}

file { $config_file:
ensure => present,
owner => $user,
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
require => File["${bin_dir}/amtool", $config_dir],
validate_cmd => "${bin_dir}/amtool check-config --alertmanager.url='' %",
}
} else {
file { $config_file:
ensure => present,
owner => $user,
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
require => File[$config_dir],
}
}

if $facts['prometheus_alert_manager_running'] == 'running' {
Expand Down
19 changes: 19 additions & 0 deletions spec/acceptance/alertmanager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper_acceptance'

describe 'prometheus alertmanager' do
it 'alertmanager works idempotently with no errors' do
pp = "class { 'prometheus::alertmanager': }"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous style was correct, you can undo the last commit.

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('alertmanager') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end
# the class installs an the alertmanager that listens on port 9093
describe port(9093) do
it { is_expected.to be_listening.with('tcp6') }
end
end