idealista / prom2teams

prom2teams is an HTTP server built with Python that receives alert notifications from a previously configured Prometheus Alertmanager instance and forwards it to Microsoft Teams using defined connectors
Apache License 2.0
268 stars 84 forks source link

Added possibility to define your own j2 template string for Helm Chart #334

Closed lordgreg closed 1 year ago

lordgreg commented 1 year ago

Requirements

Description of the Change

This pull request adds the possibility to define your own j2 template (as string) when installing using HELM chart.

Benefits

you can define/create your own content for MS Teams Body instead of using the default teams.j2.

Possible Drawbacks

Layer-8. If user doesn't add the correct content to the variable, YAML syntax error can appear.

Working example:

...
prom2teams:
  j2_template: |
    {%- set
      theme_colors = {
        'resolved' : '2DC72D',
        'critical' : '8C1A1A',
        'severe' : '8C1A1A',
        'warning' : 'FF9A0B',
        'unknown' : 'CCCCCC'
      }
    -%}

    {
        "@type": "MessageCard",
        "@context": "http://schema.org/extensions",
        "themeColor": "{% if status=='resolved' %} {{ theme_colors.resolved }} {% else %} {{ theme_colors[msg_text.severity] }} {% endif %}",
        "summary": "{% if status=='resolved' %}(Resolved) {% endif %}{{ msg_text.summary }}",
        "title": "{% if status=='resolved' %}(Resolved) {% elif status=='unknown' %} (status unknown) {% endif %}{{ msg_text.name }}",
        "sections": [{
            "activityTitle": "{{ msg_text.summary }}",
            "facts": [{% if msg_text.extra_labels %}{% for key in msg_text.extra_labels %},{
                "name": "{{ key }}",
                "value": "{{ msg_text.extra_labels[key] }}"
            }{% endfor %}{% endif %}
            {% if msg_text.extra_annotations %}{% for key in msg_text.extra_annotations %},{
                "name": "{{ key }}",
                "value": "{{ msg_text.extra_annotations[key] }}"
            }{% endfor %}{% endif %}],
              "markdown": true
        }]
    }

...
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.