Skip to content

Commit

Permalink
Merge pull request idealista#352 from idealista/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
xtianae7 authored Aug 20, 2024
2 parents 5299de6 + 9107eaa commit df77c3a
Show file tree
Hide file tree
Showing 18 changed files with 1,168 additions and 579 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ os: linux
dist: bionic
language: python

dist: focal

services:
- docker

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ 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)
## [5.0.0](https://github.com/idealista/prom2teams/tree/5.0.0)
### Changed
- *[#351](https://github.com/idealista/prom2teams/pull/351) Support new Microsoft Teams workflows* @FrankBlooBM
### Removed
- *[#351](https://github.com/idealista/prom2teams/pull/351) Support for MessageCard templates*

## [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
- *[#325](https://github.com/idealista/prom2teams/pull/325) add metrics port configuration in Helm* @santi-eidu
## [4.2.1](https://github.com/idealista/prom2teams/tree/4.2.1)
[Full Changelog](https://github.com/idealista/prom2teams/compare/4.2.0...4.2.1)
### Fixed
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 %}
}
}
]
}
5 changes: 5 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ spec:
- name: http
containerPort: 8089
protocol: TCP
- name: http-metrics
containerPort: 9090
protocol: TCP
volumeMounts:
- name: config
mountPath: /opt/prom2teams/helmconfig/
Expand All @@ -48,6 +51,8 @@ spec:
value: {{ .Values.prom2teams.group_alerts_by | quote }}
- name: PROM2TEAMS_LOGLEVEL
value: {{ .Values.prom2teams.loglevel }}
- name: PROMETHEUS_MULTIPROC_PORT
value: {{ .Values.prom2teams.monitoring_port | quote }}
{{- range $key, $value := .Values.prom2teams.extraEnv }}
- name: "{{ $key }}"
value: "{{ $value }}"
Expand Down
4 changes: 4 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ spec:
targetPort: 8089
protocol: TCP
name: http
- port: {{ .Values.service.monitoring_port }}
targetPort: 9090
protocol: TCP
name: http-metrics
selector:
app.kubernetes.io/name: {{ include "prom2teams.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
2 changes: 2 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ resources:
service:
type: ClusterIP
port: 8089
monitoring_port: 9090

prom2teams:
host: 0.0.0.0
port: 8089
monitoring_port: 9090
connector:
connectors: {}
# group_alerts_by can be one of
Expand Down
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 response.status_code != 202 and (response.status_code != 200 or 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
Loading

0 comments on commit df77c3a

Please sign in to comment.