summaryrefslogtreecommitdiff
path: root/roles/monitoring/alerta/tasks/main.yml
blob: 43c2e8920d2f8f7a9480413c2ea0c1a44b7c1ece (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
- name: prepare storage volume for alerta
  when: alerta_storage is defined
  vars:
    storage_volume: "{{ alerta_storage | combine({'dest': alerta_base_path}) }}"
  include_role:
    name: "storage/{{ alerta_storage.type }}/volume"

- name: create alerta subdirectories
  loop:
  - config
  - postgres
  - build
  file:
    path: "{{ alerta_base_path }}/{{ item }}"
    state: directory

- name: generate Dockerfile for custom image
  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 \
          && /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 \
          && 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 %}
      {% if alerta_hearbeat_force_severity is defined %}

      RUN set -x \
          && sed 's/want_severity = .*/want_severity = severity/' -i /venv/lib/python3.8/site-packages/alertaclient/commands/cmd_heartbeats.py

      ENV HEARTBEAT_SEVERITY={{ alerta_hearbeat_force_severity }}
      {% endif %}
    dest: "{{ alerta_base_path }}/build/Dockerfile"
  register: alerta_custom_image_docker

- name: build custom image
  docker_image:
    name: "alerta/alerta-web:{{ alerta_web_version }}-custom"
    state: present
    force_source: "{{ alerta_custom_image_docker is changed }}"
    source: build
    build:
      path: "{{ alerta_base_path }}/build"
      network: host
      pull: yes

- 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
  copy:
    src: email.tmpl
    dest: "{{ alerta_base_path }}/config/email.tmpl"

- name: install pod manifest
  vars:
    kubernetes_standalone_pod:
      name: "alerta"
      spec: "{{ lookup('template', 'pod-spec.yml.j2') }}"
      mode: "0600"
      config_hash_items:
      - path: "{{ alerta_base_path }}/config/alertad.conf.j2"
        properties:
        - checksum
      - path: "{{ alerta_base_path }}/config/alerta.conf.j2"
        properties:
        - checksum
      - path: "{{ alerta_base_path }}/config/email.tmpl"
        properties:
        - checksum
      - path: "{{ alerta_base_path }}/build/Dockerfile"
        properties:
        - checksum
  include_role:
    name: kubernetes/standalone/pod