From 4930ff68c7d699611511aaabd2c2ebe585207051 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 11 Mar 2022 20:58:38 +0100 Subject: alerta: improve support for mailer --- roles/monitoring/alerta/tasks/main.yml | 68 +++++++++++++--------------------- 1 file changed, 26 insertions(+), 42 deletions(-) (limited to 'roles/monitoring/alerta/tasks/main.yml') diff --git a/roles/monitoring/alerta/tasks/main.yml b/roles/monitoring/alerta/tasks/main.yml index ffedb143..87a0cb3d 100644 --- a/roles/monitoring/alerta/tasks/main.yml +++ b/roles/monitoring/alerta/tasks/main.yml @@ -19,17 +19,32 @@ copy: content: | FROM alerta/alerta-web:{{ alerta_web_version }} + {% if 'prometheus' in alerta_plugins %} + + RUN set -x \ + && sed 's/USE_AM_EXTERNALURL_FOR_SILENCES/ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES/' -i /venv/lib/python3.8/site-packages/alerta_prometheus.py + {% endif %} + {% if alerta_mailer is defined %} RUN set -x \ - && sed 's/USE_AM_EXTERNALURL_FOR_SILENCES/ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES/' -i /venv/lib/python3.8/site-packages/alerta_prometheus.py \ && /venv/bin/pip install redis=={{ _alerta_pip[alerta_web_version].redis_version }} \ - && /venv/bin/pip install git+https://github.com/alerta/alerta-contrib.git@{{ _alerta_pip[alerta_web_version].contrib_mailer_git_hash }}#subdirectory=integrations/mailer + && /venv/bin/pip install git+https://github.com/alerta/alerta-contrib.git@{{ _alerta_pip[alerta_web_version].contrib_mailer_git_hash }}#subdirectory=integrations/mailer \ + && echo "" >> /app/supervisord.conf.j2 \ + && echo "[program:mailer]" >> /app/supervisord.conf.j2 \ + && echo "command=alerta-mailer" >> /app/supervisord.conf.j2 \ + && echo "redirect_stderr=true" >> /app/supervisord.conf.j2 + + USER root + RUN set -x \ + && sed 's/--scope "write:alerts"/--scope "write:alerts" --scope "write:heartbeats"/' -i /usr/local/bin/docker-entrypoint.sh + USER 1001 + {% endif %} dest: "{{ alerta_base_path }}/build/Dockerfile" register: alerta_custom_image_docker - name: build custom image docker_image: - name: "alerta-web-with-mailer:{{ alerta_web_version }}" + name: "alerta/alerta-web:{{ alerta_web_version }}-custom" state: present force_source: "{{ alerta_custom_image_docker is changed }}" source: build @@ -38,44 +53,13 @@ network: host pull: yes -- name: install alertad config template - copy: - content: | - DEBUG = {{ '{{' }} 'True' if env.DEBUG else 'False' {{ '}}' }} - SECRET = "{{ '{{' }} env.SECRET_KEY {{ '}}' }}" - ALERT_TIMEOUT = 86400 - HEARTBEAT_TIMEOUT = 7200 - PLUGINS = ['reject', 'blackout', 'heartbeat', 'prometheus', 'amqp'] - DEFAULT_ENVIRONMENT = 'unknown' - ALLOWED_ENVIRONMENTS = ['unknown', 'chaos-at-.*'] - HEARTBEAT_EVENTS = ['PrometheusAlertmanagerE2eDeadManSwitch'] - ALERTMANAGER_USERNAME = 'alerta' - ALERTMANAGER_PASSWORD = 'alerta' - ALERTMANAGER_SILENCE_FROM_ACK = True - ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES = True - AMQP_URL = 'redis://localhost:6379/' - dest: "{{ alerta_base_path }}/config/alertad.conf.j2" - - ## TODO: add key handling... -- name: install alerta-mailer config file - copy: - content: | - [alerta-mailer] - debug = True - key = aNqBsEyG0ynIKcc3e7acaBVBk5B793o_z7tvlsht - endpoint = http://localhost:8080/api - amqp_url = redis://localhost:6379 - severities = critical, warning - smtp_host = 192.168.28.250 - smtp_port = 25 - smtp_starttls = False - skip_mta = False - mail_to = equinox@chaos-at-home.org - mail_from = noreply@chaos-at-home.org - email_type = text - mail_template = /app/email.tmpl - dashboard_url = http://192.168.32.1:8080 - dest: "{{ alerta_base_path }}/config/alerta-mailer.conf" +- name: install config templates + loop: + - alertad + - alerta + template: + src: "{{ item }}.conf.j2.j2" + dest: "{{ alerta_base_path }}/config/{{ item }}.conf.j2" mode: 0640 - name: install e-mail template @@ -93,7 +77,7 @@ - path: "{{ alerta_base_path }}/config/alertad.conf.j2" properties: - checksum - - path: "{{ alerta_base_path }}/config/alerta-mailer.conf" + - path: "{{ alerta_base_path }}/config/alerta.conf.j2" properties: - checksum - path: "{{ alerta_base_path }}/config/email.tmpl" -- cgit v1.2.3