Skip to content

Commit

Permalink
Validate Alertmanager config (#277)
Browse files Browse the repository at this point in the history
* Validate Alertmanager config

Install the amtool and validate alertmanager config file prior changes.

* Fixed lint and require parameter

Fixed lint and require parameter

* Removed trailing whitespace

* Uses bind_dir

Uses bin_dir instead of prometheus::server::bin_dir

* Update alertmanager.pp

Check Alertmanager version.

* Identation corrected

* Corrected notify service

* Acceptance test for Alertmanager

Acceptance test for Alertmanager

* Alertmanager acceptance test via class

Alertmanager acceptance test via class

* Using my tested config for Alertmanager

* Minimal configuration for Alertmanager

* Fixed syntax, added missing closing braces

* Removed IPv4 configuration to allow IPv6 test
  • Loading branch information
allangood authored and bastelfreak committed May 30, 2019
1 parent aaffe9f commit 8925168
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
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
37 changes: 37 additions & 0 deletions spec/acceptance/alertmanager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper_acceptance'

describe 'prometheus alertmanager' do
it 'alertmanager works idempotently with no errors' do
pp = <<-EOS
class { 'prometheus::alertmanager':
version => '0.17.0',
extra_options => '--web.listen-address=":9093"',
route => { 'receiver' => 'default' },
receivers => [
{
name => 'default',
email_configs => [
send_resolved => true,
to => 'test@localhost.localdomain',
from => 'prometheus@localhost.localdomain',
smarthost => '127.0.0.1:25',
require_tls => false
]
}
]
}
EOS
# 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

0 comments on commit 8925168

Please sign in to comment.