Skip to content

Commit

Permalink
enhancement: Add time_intervals to AlertManager (#251)
Browse files Browse the repository at this point in the history
* enhancement: Add time_intervals to AlertManager

---------

Signed-off-by: Shaun Megaw <[email protected]>
  • Loading branch information
rezizter authored Dec 12, 2023
1 parent e6c9dec commit 6223e3b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion roles/alertmanager/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ alertmanager_receivers: []
# slack_configs:
# - send_resolved: true
# channel: '#alerts'

alertmanager_time_intervals: []
# alertmanager_time_intervals:
# - name: offhours
# time_intervals:
# - times:
# - start_time: "21:00"
# end_time: "24:00"
# location: "Africa/Johannesburg"
alertmanager_inhibit_rules: []
# alertmanager_inhibit_rules:
# - target_match:
Expand Down
3 changes: 3 additions & 0 deletions roles/alertmanager/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ argument_specs:
alertmanager_receivers:
description: "A list of notification receivers. Configuration same as in L(official docs,https://prometheus.io/docs/alerting/configuration/#receiver)"
type: "list"
alertmanager_time_intervals:
description: "A list of time intervals. Configuration same as in L(official docs,https://prometheus.io/docs/alerting/latest/configuration/#time_interval)"
type: "list"
alertmanager_inhibit_rules:
description: "List of inhibition rules. Same as in L(official docs,https://prometheus.io/docs/alerting/configuration/#inhibit_rule)"
type: "list"
Expand Down
7 changes: 7 additions & 0 deletions roles/alertmanager/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ provisioner:
group_interval: 5m
repeat_interval: 3h
receiver: slack
alertmanager_time_intervals:
- name: offhours
time_intervals:
- times:
- start_time: "21:00"
end_time: "24:00"
location: "Africa/Johannesburg"
8 changes: 8 additions & 0 deletions roles/alertmanager/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,11 @@
msg: "Please move content of `alertmanager_child_routes` to `alertmanager_route.routes` as the former variable is deprecated
and will be removed in future versions."
when: alertmanager_child_routes is defined

- name: "`alertmanager_time_intervals` is only supported on version 0.22.0. Please upgrade to this version."
ansible.builtin.fail:
msg: "To use `alertmanager_time_intervals`,
Please upgrade to AlertManager 0.22.0 or newer."
when:
- alertmanager_version is version_compare('0.22.0', '<')
- alertmanager_time_intervals is defined
4 changes: 4 additions & 0 deletions roles/alertmanager/templates/alertmanager.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ receivers:
inhibit_rules:
{{ alertmanager_inhibit_rules | to_nice_yaml(indent=2) }}
{% endif %}
{% if alertmanager_time_intervals | length %}
time_intervals:
{{ alertmanager_time_intervals | to_nice_yaml(indent=2) }}
{% endif %}
route:
{{ alertmanager_route | to_nice_yaml(indent=2) | indent(2, False) }}

0 comments on commit 6223e3b

Please sign in to comment.