Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrate to Teams Workflow #351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog).

## [Unreleased](https://github.com/idealista/prom2teams/tree/develop)
### Changed
- *[#351](https://github.com/idealista/prom2teams/pull/351) Support new Microsoft Teams workflows* @FrankBlooBM

## [4.2.2](https://github.com/idealista/prom2teams/tree/4.2.2)
[Full Changelog](https://github.com/idealista/prom2teams/compare/4.2.1...4.2.2)
### Added
Expand Down
113 changes: 70 additions & 43 deletions helm/files/teams.j2
Original file line number Diff line number Diff line change
@@ -1,44 +1,71 @@
{%- 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": "Prometheus alert {% if status=='resolved' %}(Resolved) {% elif status=='unknown' %} (status unknown) {% endif %}",
"sections": [{
"activityTitle": "{{ msg_text.summary }}",
"facts": [{% if msg_text.name %}{
"name": "Alert",
"value": "{{ msg_text.name }}"
},{% endif %}{% if msg_text.instance %}{
"name": "In host",
"value": "{{ msg_text.instance }}"
},{% endif %}{% if msg_text.severity %}{
"name": "Severity",
"value": "{{ msg_text.severity }}"
},{% endif %}{% if msg_text.description %}{
"name": "Description",
"value": "{{ msg_text.description }}"
},{% endif %}{
"name": "Status",
"value": "{{ msg_text.status }}"
}{% 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
}]
}
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"style": "{% if status=='resolved' %}good{% else %}attention{% endif %}",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Prometheus alert {{ msg_text.name }} {% if status=='resolved' %}(Resolved){% elif status=='unknown' %}(status unknown){% else %}triggered{% endif %}",
"weight": "Bolder",
"size": "Large"
},
{
"type": "TextBlock",
"text": "{% if status=='resolved' %}(Resolved) {% endif %}{{ msg_text.summary }}",
"wrap": true
}
]
}
]
},
{
"type": "FactSet",
"facts": [
{% if msg_text.name %} { "title": "Alert", "value": "{{ msg_text.name }}" }, {% endif %}
{% if msg_text.instance %} { "title": "In host", "value": "{{ msg_text.instance }}" }, {% endif %}
{% if msg_text.severity %} { "title": "Severity", "value": "{{ msg_text.severity }}" }, {% endif %}
{% if msg_text.description %} { "title": "Description", "value": "{{ msg_text.description }}" }, {% endif %}
{ "title": "Status", "value": "{{ msg_text.status }}" }
{% if msg_text.extra_labels %}
{% for key in msg_text.extra_labels %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_labels[key] }}" }
{% endfor %}
{% endif %}
{% if msg_text.extra_annotations %}
{% for key in msg_text.extra_annotations %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_annotations[key] }}" }
{% endfor %}
{% endif %}
]
}
]
{% if msg_text.runbook_url %}
,
"actions": [
{
"type": "Action.OpenUrl",
"title": "View details",
"url": "{{ msg_text.runbook_url }}"
}
]
{% endif %}
}
}
]
}
2 changes: 1 addition & 1 deletion prom2teams/app/teams_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def simple_post(teams_webhook_url, message):

def _do_post(self, teams_webhook_url, message):
response = self.session.post(teams_webhook_url, data=message, timeout=self.timeout)
if not response.ok or response.text != '1':
if not response.status_code == 202 and not (response.status_code == 200 and response.text == '1'):
exception_msg = 'Error performing request to: {}.\n' \
' Returned status code: {}.\n' \
' Returned data: {}\n' \
Expand Down
124 changes: 69 additions & 55 deletions prom2teams/resources/templates/teams.j2
Original file line number Diff line number Diff line change
@@ -1,57 +1,71 @@
{%- 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": "Prometheus alert {% if status=='resolved' %}(Resolved) {% elif status=='unknown' %} (status unknown) {% endif %}",
"sections": [{
"activityTitle": "{{ msg_text.summary }}",
"facts": [{% if msg_text.name %}{
"name": "Alert",
"value": "{{ msg_text.name }}"
},{% endif %}{% if msg_text.instance %}{
"name": "In host",
"value": "{{ msg_text.instance }}"
},{% endif %}{% if msg_text.severity %}{
"name": "Severity",
"value": "{{ msg_text.severity }}"
},{% endif %}{% if msg_text.description %}{
"name": "Description",
"value": "{{ msg_text.description }}"
},{% endif %}{
"name": "Status",
"value": "{{ msg_text.status }}"
}{% 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
}]
{% if msg_text.runbook_url %}
,
"potentialAction": [
{
"@context": "http://schema.org",
"@type": "ViewAction",
"name": "Runbook",
"target": [
"{{ msg_text.runbook_url }}"
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"style": "{% if status=='resolved' %}good{% else %}attention{% endif %}",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Prometheus alert {{ msg_text.name }} {% if status=='resolved' %}(Resolved){% elif status=='unknown' %}(status unknown){% else %}triggered{% endif %}",
"weight": "Bolder",
"size": "Large"
},
{
"type": "TextBlock",
"text": "{% if status=='resolved' %}(Resolved) {% endif %}{{ msg_text.summary }}",
"wrap": true
}
]
}
]
}
]
{% endif %}
}
},
{
"type": "FactSet",
"facts": [
{% if msg_text.name %} { "title": "Alert", "value": "{{ msg_text.name }}" }, {% endif %}
{% if msg_text.instance %} { "title": "In host", "value": "{{ msg_text.instance }}" }, {% endif %}
{% if msg_text.severity %} { "title": "Severity", "value": "{{ msg_text.severity }}" }, {% endif %}
{% if msg_text.description %} { "title": "Description", "value": "{{ msg_text.description }}" }, {% endif %}
{ "title": "Status", "value": "{{ msg_text.status }}" }
{% if msg_text.extra_labels %}
{% for key in msg_text.extra_labels %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_labels[key] }}" }
{% endfor %}
{% endif %}
{% if msg_text.extra_annotations %}
{% for key in msg_text.extra_annotations %}
, { "title": "{{ key }}", "value": "{{ msg_text.extra_annotations[key] }}" }
{% endfor %}
{% endif %}
]
}
]
{% if msg_text.runbook_url %}
,
"actions": [
{
"type": "Action.OpenUrl",
"title": "View details",
"url": "{{ msg_text.runbook_url }}"
}
]
{% endif %}
}
}
]
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ flask-restplus==0.12.1
marshmallow==3.0.0rc6
jinja2==2.11.3
Flask==1.0.2
pyyaml==5.4
pyyaml==6.0.1
uwsgi==2.0.20
prometheus_flask_exporter==0.9.0
werkzeug==0.16.1
Expand Down
77 changes: 52 additions & 25 deletions tests/data/json_files/teams_alert_all_ok.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": " 2DC72D ",
"summary": "(Resolved) Disk usage alert on CS30.evilcorp",
"title": "Prometheus alert (Resolved) ",
"sections": [{
"activityTitle": "Disk usage alert on CS30.evilcorp",
"facts": [{
"name": "Alert",
"value": "DiskSpace"
},{
"name": "In host",
"value": "cs30.evilcorp"
},{
"name": "Severity",
"value": "severe"
},{
"name": "Description",
"value": "disk usage 93% on rootfs device"
},{
"name": "Status",
"value": "resolved"
}],
"markdown": true
}]
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"style": "good",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Prometheus alert DiskSpace (Resolved)",
"weight": "Bolder",
"size": "Large"
},
{
"type": "TextBlock",
"text": "(Resolved) Disk usage alert on CS30.evilcorp",
"wrap": true
}
]
}
]
},
{
"type": "FactSet",
"facts": [
{ "title": "Alert", "value": "DiskSpace" },
{ "title": "In host", "value": "cs30.evilcorp" },
{ "title": "Severity", "value": "severe" },
{
"title": "Description",
"value": "disk usage 93% on rootfs device"
},
{ "title": "Status", "value": "resolved" }
]
}
]
}
}
]
}
Loading
Loading