Skip to content

Commit

Permalink
Merge pull request voxpupuli#424 from treydock/reload
Browse files Browse the repository at this point in the history
Support reloading alertmanager rather than restarting
  • Loading branch information
bastelfreak committed Feb 12, 2020
2 parents a13475f + 5330f67 commit 49acd70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
24 changes: 22 additions & 2 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
Stdlib::Ensure::Service $service_ensure = 'running',
String[1] $service_name = 'alertmanager',
Boolean $restart_on_change = true,
Boolean $reload_on_change = false,
Boolean $purge_config_dir = true,
Boolean $manage_config = true,
Prometheus::Initstyle $init_style = $facts['service_provider'],
Expand Down Expand Up @@ -138,6 +139,25 @@
default => undef,
}

$alertmanager_reload = $prometheus::init_style ? {
'systemd' => "systemctl reload-or-restart ${service_name}",
/^(upstart|none)$/ => "service ${service_name} reload",
/^(sysv|redhat|sles|debian)$/ => "/etc/init.d/${service_name} reload",
'launchd' => "launchctl stop ${service_name} && launchctl start ${service_name}",
}

exec { 'alertmanager-reload':
command => $alertmanager_reload,
path => [ '/usr/bin', '/bin', '/usr/sbin', '/sbin' ],
refreshonly => true,
}

if $reload_on_change {
$_notify_service = Exec['alertmanager-reload']
} else {
$_notify_service = $notify_service
}

file { $config_dir:
ensure => 'directory',
owner => 'root',
Expand All @@ -160,7 +180,7 @@
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
notify => $_notify_service,
require => File["${bin_dir}/amtool", $config_dir],
validate_cmd => "${bin_dir}/amtool check-config --alertmanager.url='' %",
}
Expand All @@ -174,7 +194,7 @@
group => $group,
mode => $config_mode,
content => template('prometheus/alertmanager.yaml.erb'),
notify => $notify_service,
notify => $_notify_service,
require => File[$config_dir],
}
}
Expand Down
19 changes: 18 additions & 1 deletion spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@
end
describe 'config file contents' do
it {
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml')
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Service[alertmanager]')
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
}
end
describe 'service reload' do
it {
is_expected.to contain_exec('alertmanager-reload').with(
# 'command' => 'systemctl reload alertmanager',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
'refreshonly' => true
)
}
end
end

context 'when reload_on_change => true' do
let(:params) { { reload_on_change: true } }

it {
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Exec[alertmanager-reload]')
}
end

context 'with manage_config => false' do
Expand Down

0 comments on commit 49acd70

Please sign in to comment.