Skip to content

Commit

Permalink
Merge pull request #563 from treydock/mute_time_intervals
Browse files Browse the repository at this point in the history
Support mute_time_intervals for Alertmanager
  • Loading branch information
bastelfreak authored Jun 25, 2021
2 parents a0d1c2e + b83474f commit cf0d3f2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ prometheus::alertmanager::route:
'group_interval': '5m'
'repeat_interval': '3h'
'receiver': 'Admin'
prometheus::alertmanager::mute_time_intervals: []
prometheus::alertmanager::storage_path: '/var/lib/alertmanager'
prometheus::alertmanager::templates: [ "%{lookup('prometheus::alertmanager::config_dir')}/*.tmpl" ]
prometheus::alertmanager::user: 'alertmanager'
Expand Down
7 changes: 7 additions & 0 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
# Should puppet manage the service? (default true)
# @param manage_user
# Whether to create user or rely on external code for that
# @param mute_time_intervals
# Array of mute time intervals
# Example:
# prometheus::alertmanager::mute_time_intervals:
# - name: weekend
# weekdays: ['saturday','sunday']
# @param os
# Operating system (linux is the only one supported)
# @param package_ensure
Expand Down Expand Up @@ -103,6 +109,7 @@
String[1] $package_name,
Array $receivers,
Hash $route,
Array[Hash] $mute_time_intervals,
Stdlib::Absolutepath $storage_path,
Array $templates,
String[1] $user,
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
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'])
}
it {
is_expected.not_to contain_file('/etc/alertmanager/alertmanager.yaml').with_content(%r{mute_time_intervals})
}
end
describe 'service reload' do
it {
Expand All @@ -47,6 +50,29 @@
end
end

context 'with latest version specified and mute_time_intervals' do
let(:params) do
{
version: '0.22.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url',
mute_time_intervals: [{ 'name' => 'weekend', 'weekdays' => ['saturday','sunday'] }],
}
end

it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
'mute_time_intervals:',
'- name: weekend',
' weekdays:',
' - saturday',
' - sunday',
])
}
end

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

Expand Down
5 changes: 5 additions & 0 deletions templates/alertmanager.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<% receivers = scope.lookupvar('::prometheus::alertmanager::receivers') -%>
<% inhibit_rules = scope.lookupvar('::prometheus::alertmanager::inhibit_rules') -%>
<% full_config = { 'global'=>global, 'templates'=>templates, 'route'=>route, 'receivers'=>receivers, 'inhibit_rules'=>inhibit_rules } -%>
<%
if scope.function_versioncmp([scope.lookupvar('::prometheus::alertmanager::version'), '0.22.0']) >= 0
full_config['mute_time_intervals'] = scope.lookupvar('::prometheus::alertmanager::mute_time_intervals')
end
-%>
<%= full_config.to_yaml -%>

0 comments on commit cf0d3f2

Please sign in to comment.