add general custom receivers and template

This commit is contained in:
Anton Iakimov 2024-03-26 18:27:03 +01:00
parent 4e43dd54e2
commit 7a6687469d
No known key found for this signature in database
GPG Key ID: DEA1FE58DD8BF7FA
5 changed files with 44 additions and 13 deletions

View File

@ -29,11 +29,14 @@ alertmanager_probe_interval: '5s'
#alertmanager_smtp_from: ~
#alertmanager_smtp_user: ~
#alertmanager_smtp_pass: ~
alertmanager_smtp_receivers_extra: []
alertmanager_receivers_extra: []
# - name: 'devops'
# email_configs:
# - to: 'devops@example.org'
# send_resolved: true
# routes:
# continue: true
# receivers:
# email_configs:
# - to: 'devops@example.org'
# send_resolved: true
# OAuth
alertmanager_oauth_compose_file: '{{ alertmanager_service_path }}/docker-compose.oauth.yml'

15
files/custom.tmpl Normal file
View File

@ -0,0 +1,15 @@
{{ define "discord.custom.title" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }}{{ end }}
{{ define "__text_alert_description_list" }}{{ range . }}- [{{ .Annotations.description }}]({{ .GeneratorURL }})
{{ end }}{{ end }}
{{ define "discord.custom.message" }}
{{ if gt (len .Alerts.Firing) 0 }}
Alerts Firing:
{{ template "__text_alert_description_list" .Alerts.Firing }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
Alerts Resolved:
{{ template "__text_alert_description_list" .Alerts.Resolved }}
{{ end }}
{{ end }}

View File

@ -9,7 +9,7 @@
mode: 0750
with_items:
- 'data'
- 'conf'
- 'conf/templates'
- name: Create config files
template:
@ -22,3 +22,11 @@
with_items:
- 'alertmanager.yml'
- 'amtool.yml'
- name: Create template file
copy:
src: 'custom.tmpl'
dest: '{{ alertmanager_service_path }}/conf/templates/custom.tmpl'
owner: 'dockremap'
group: 'docker'
mode: 0640

View File

@ -23,14 +23,15 @@ route:
repeat_interval: '{{ alertmanager_repeat_interval | mandatory }}'
routes:
{% for extra_receiver in alertmanager_receivers_extra %}
{% filter indent(width=6) %}
- {{ {'receiver': extra_receiver.name} | combine(extra_receiver.routes) | to_nice_yaml(sort_keys=false) }}
{% endfilter %}
{% endfor %}
{% if alertmanager_victorops_enabled %}
- receiver: 'victorops-alerts'
continue: true
{% endif %}
{% for extra_receiver in alertmanager_smtp_receivers_extra %}
- receiver: '{{ extra_receiver.name }}'
continue: true
{% endfor %}
receivers:
- name: 'admin-email'
@ -47,9 +48,12 @@ receivers:
entity_display_name: '{{ alertmanager_victorops_display_name | mandatory | trim }}'
state_message: '{{ alertmanager_victorops_state_message | mandatory | trim }}'
{% endif %}
{% if alertmanager_smtp_receivers_extra|length > 0 %}
{% filter indent(width=2) %}
{{ alertmanager_smtp_receivers_extra | to_nice_yaml(indent=2) | trim }}
{% for extra_receiver in alertmanager_receivers_extra %}
{% filter indent(width=4) %}
- {{ {'name': extra_receiver.name} | combine(extra_receiver.receivers) | to_nice_yaml(sort_keys=false, indent=1) }}
{% endfilter %}
{% endif %}
{% endfor %}
templates:
- '/etc/alertmanager/templates/custom.tmpl'

View File

@ -13,6 +13,7 @@ services:
volumes:
- '{{ alertmanager_service_path }}/conf/alertmanager.yml:/etc/alertmanager.yml:ro'
- '{{ alertmanager_service_path }}/conf/amtool.yml:/etc/amtool/config.yml:ro'
- '{{ alertmanager_service_path }}/conf/templates:/etc/alertmanager/templates:ro'
- '{{ alertmanager_service_path }}/data:/data'
- '/certs:/certs'
command: