diff --git a/roles/alertmanager/defaults/main.yml b/roles/alertmanager/defaults/main.yml index 22683c284..a26d334f7 100644 --- a/roles/alertmanager/defaults/main.yml +++ b/roles/alertmanager/defaults/main.yml @@ -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: diff --git a/roles/alertmanager/meta/argument_specs.yml b/roles/alertmanager/meta/argument_specs.yml index c9e7d10e0..cb2095c64 100644 --- a/roles/alertmanager/meta/argument_specs.yml +++ b/roles/alertmanager/meta/argument_specs.yml @@ -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" diff --git a/roles/alertmanager/molecule/default/molecule.yml b/roles/alertmanager/molecule/default/molecule.yml index 217e1f322..eeb81d063 100644 --- a/roles/alertmanager/molecule/default/molecule.yml +++ b/roles/alertmanager/molecule/default/molecule.yml @@ -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" diff --git a/roles/alertmanager/tasks/preflight.yml b/roles/alertmanager/tasks/preflight.yml index fc7322a45..c68b1293d 100644 --- a/roles/alertmanager/tasks/preflight.yml +++ b/roles/alertmanager/tasks/preflight.yml @@ -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 diff --git a/roles/alertmanager/templates/alertmanager.yml.j2 b/roles/alertmanager/templates/alertmanager.yml.j2 index 7c04df37b..5189ad8cf 100644 --- a/roles/alertmanager/templates/alertmanager.yml.j2 +++ b/roles/alertmanager/templates/alertmanager.yml.j2 @@ -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) }}