teams-alerter 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- teams_alerter/core.py +16 -7
- teams_alerter/utils.py +15 -14
- {teams_alerter-0.2.3.dist-info → teams_alerter-0.2.5.dist-info}/METADATA +1 -1
- teams_alerter-0.2.5.dist-info/RECORD +9 -0
- {teams_alerter-0.2.3.dist-info → teams_alerter-0.2.5.dist-info}/top_level.txt +1 -0
- tests/__init__.py +0 -0
- tests/test_core.py +51 -0
- teams_alerter-0.2.3.dist-info/RECORD +0 -7
- {teams_alerter-0.2.3.dist-info → teams_alerter-0.2.5.dist-info}/WHEEL +0 -0
teams_alerter/core.py
CHANGED
@@ -91,11 +91,12 @@ class TeamsAlerter:
|
|
91
91
|
|
92
92
|
def format_email_template(self):
|
93
93
|
self.payload["alert_type"].append("email")
|
94
|
+
self.payload["email_object"] = "Contrôle DATASTREAM"
|
94
95
|
|
95
96
|
if self.utils["app_name"] == "health_check_check_horses_stats":
|
96
97
|
error_info_list = json.loads(self.payload["detail"]["message"])
|
97
98
|
table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
|
98
|
-
for error_info in error_info_list:
|
99
|
+
for error_info in error_info_list["data"]:
|
99
100
|
table_data.append(
|
100
101
|
(
|
101
102
|
error_info["idCheval"],
|
@@ -107,9 +108,17 @@ class TeamsAlerter:
|
|
107
108
|
)
|
108
109
|
|
109
110
|
email_object = "Contrôle DATASTREAM - Fiche cheval"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
self.payload["email_object"] = email_object
|
112
|
+
email_messages = [
|
113
|
+
"""
|
114
|
+
Bonjour, <br>
|
115
|
+
Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream.
|
116
|
+
""",
|
117
|
+
f"""
|
118
|
+
Env: <strong>{self.utils["env"]}</strong> <br>
|
119
|
+
Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
|
120
|
+
Champs: <strong>formFigs et/ou totalPrize</strong>
|
121
|
+
""",
|
122
|
+
]
|
123
|
+
|
124
|
+
self.payload["email_template_html"] = format_email_template(email_object, email_messages, table_data)
|
teams_alerter/utils.py
CHANGED
@@ -31,7 +31,7 @@ class DateUtils:
|
|
31
31
|
return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
|
32
32
|
|
33
33
|
|
34
|
-
def format_email_template(email_object,
|
34
|
+
def format_email_template(email_object, email_messages, table_data):
|
35
35
|
html = f"""
|
36
36
|
<html>
|
37
37
|
<head lang="fr">
|
@@ -57,19 +57,7 @@ def format_email_template(email_object, email_message, table_data):
|
|
57
57
|
</td>
|
58
58
|
</tr>
|
59
59
|
|
60
|
-
|
61
|
-
<td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
|
62
|
-
{email_message}
|
63
|
-
</td>
|
64
|
-
</tr>
|
65
|
-
|
66
|
-
<tr>
|
67
|
-
<td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
|
68
|
-
Env: <strong>INT</strong> <br>
|
69
|
-
Timestamp: <time datetime="2025-08-25T13:15:00Z">2025-08-25T13:15:00Z</time> <br>
|
70
|
-
Champs: <strong>formFigs et/ou totalPrize</strong>
|
71
|
-
</td>
|
72
|
-
</tr>
|
60
|
+
{build_html_message(email_messages)}
|
73
61
|
|
74
62
|
<tr>
|
75
63
|
<td style="padding:0 16px 24px 16px;">
|
@@ -121,3 +109,16 @@ def build_html_table(table_data: list):
|
|
121
109
|
html_table += "</table>"
|
122
110
|
|
123
111
|
return html_table
|
112
|
+
|
113
|
+
|
114
|
+
def build_html_message(email_messages: list[str]):
|
115
|
+
content = ""
|
116
|
+
for email_message in email_messages:
|
117
|
+
content += f"""
|
118
|
+
<tr>
|
119
|
+
<td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
|
120
|
+
{email_message}
|
121
|
+
</td>
|
122
|
+
</tr>
|
123
|
+
"""
|
124
|
+
return content
|
@@ -0,0 +1,9 @@
|
|
1
|
+
teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
|
2
|
+
teams_alerter/core.py,sha256=lhE8T3AtUBPc0fqO9rCuG-z_TBQMe0L-VhR2ZFyn1Mc,5028
|
3
|
+
teams_alerter/utils.py,sha256=jP3JTnrOmriz60aWbmzc76P_xrETxvJNsUS1TCcz94Y,5342
|
4
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
|
6
|
+
teams_alerter-0.2.5.dist-info/METADATA,sha256=U2aUZ0LH8yZhR5S7tv3t5sNLyq2tgJ8lHqm8rwwkeFA,2194
|
7
|
+
teams_alerter-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
teams_alerter-0.2.5.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
|
9
|
+
teams_alerter-0.2.5.dist-info/RECORD,,
|
tests/__init__.py
ADDED
File without changes
|
tests/test_core.py
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
import pytest
|
2
|
+
import os
|
3
|
+
import json
|
4
|
+
|
5
|
+
from teams_alerter.core import TeamsAlerter
|
6
|
+
|
7
|
+
|
8
|
+
def test_error_handler():
|
9
|
+
env = "dev"
|
10
|
+
ERROR_UTILS = {
|
11
|
+
"env": env,
|
12
|
+
"app_project_id": os.environ.get("ERROR_HANDLER_APP_PROJECT_ID", "betin-horse-datastream-" + env),
|
13
|
+
"topic_project_id": os.environ.get("ERROR_HANDLER_TOPIC_PROJECT_ID", "betin-horse-datastream-" + env),
|
14
|
+
"topic_id": os.environ.get("ERROR_HANDLER_TOPIC_ID", "topic-datastream-errors-" + env),
|
15
|
+
"app_name": "health_check_check_horses_stats",
|
16
|
+
"teams_channel": "datastream-alerts-" + env,
|
17
|
+
}
|
18
|
+
diffs_list = [
|
19
|
+
{
|
20
|
+
"idCheval": 1338148,
|
21
|
+
"champ": "formFigs",
|
22
|
+
"postgres": '<span style="background-color:yellow; color:#000;">5a</span> 8a 8a 3a (24) 13a 12a 9a 10a Da 7a 7m 9a 10a 8m 6a 0a Da 10a 7a 7a (23) 11a 1a 2a 5a 10a 4a Aa 3a 10a Aa 3a 10a 2a 3a 3a 3a Da 4a 7a (22) 7a 3a 3a 1a 12a 6a 1a 1a 2a 7a 1a 4a 4a 1a 6a 1a 4a 10a (21) 14a 4a 5a 4a 1a 3a 2a 4a 7a 3a 5a 4a 6a 2a 2a 7a 7a 7a (20) 1a 1a 2a 4a 6a 1a 3a 5a 1a 1a 4a 1a 3a 4a 2a 2a (19) 4a 5a Da Da 4a 5Da 3a 5a 1a 4a (18) Da Da 5a 2a',
|
23
|
+
"mongo": "8a 8a 3a (24) 13a 12a 9a 10a Da 7a 7m 9a 10a 8m 6a 0a Da 10a 7a 7a (23) 11a 1a 2a 5a 10a 4a Aa 3a 10a Aa 3a 10a 2a 3a 3a 3a Da 4a 7a (22) 7a 3a 3a 1a 12a 6a 1a 1a 2a 7a 1a 4a 4a 1a 6a 1a 4a 10a (21) 14a 4a 5a 4a 1a 3a 2a 4a 7a 3a 5a 4a 6a 2a 2a 7a 7a 7a (20) 1a 1a 2a 4a 6a 1a 3a 5a 1a 1a 4a 1a 3a 4a 2a 2a (19) 4a 5a Da Da 4a 5Da 3a 5a 1a 4a (18) Da Da 5a 2a",
|
24
|
+
"difference": "5a manquants dans Mongo",
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"idCheval": 1338148,
|
28
|
+
"champ": "totalPrize",
|
29
|
+
"postgres": 308670,
|
30
|
+
"mongo": 304920,
|
31
|
+
"difference": "3750 de moins dans Mongo",
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"idCheval": 1343727,
|
35
|
+
"champ": "formFigs",
|
36
|
+
"postgres": '<span style="background-color:yellow; color:#000;">4a</span> <span style="background-color:yellow; color:#000;">4a</span> 4m 9m 7a Da 9a 3m (24) 6a 1a 1a 5a 6a 1a Da 4a 6a 4a 3a 5a 2a 0a (23) 9a 6a Da Aa 1a 0a 3a Da 4m 7a 7a Da 3a 4Dista 5a 9a (22) 13a 11a 6a Aa 4a 8a 3a 2a 3a 4a 4a 3a 6a 8a (21) 1a Da 11a 9a 6a 3a 3a 5a 3a Da 2a 4a 1a 11a Da 6a 2a (20) 1a 11a Da 3a Aa 3a 3a 9a 1a 8a 5a (19) 4a 2a 5a 4a 1a 7a',
|
37
|
+
"mongo": "4m 9m 7a Da 9a 3m (24) 6a 1a 1a 5a 6a 1a Da 4a 6a 4a 3a 5a 2a 0a (23) 9a 6a Da Aa 1a 0a 3a Da 4m 7a 7a Da 3a 4Dista 5a 9a (22) 13a 11a 6a Aa 4a 8a 3a 2a 3a 4a 4a 3a 6a 8a (21) 1a Da 11a 9a 6a 3a 3a 5a 3a Da 2a 4a 1a 11a Da 6a 2a (20) 1a 11a Da 3a Aa 3a 3a 9a 1a 8a 5a (19) 4a 2a 5a 4a 1a 7a",
|
38
|
+
"difference": "4a 4a manquants dans Mongo",
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"idCheval": 1343727,
|
42
|
+
"champ": "totalPrize",
|
43
|
+
"postgres": 163935,
|
44
|
+
"mongo": 159775,
|
45
|
+
"difference": "4160 de moins dans Mongo",
|
46
|
+
},
|
47
|
+
]
|
48
|
+
error = ValueError(
|
49
|
+
ValueError(json.dumps({"data": diffs_list, "message": f"[Vérification horses_stats du 2025-08-29]"}))
|
50
|
+
)
|
51
|
+
TeamsAlerter.handle_error(error, ERROR_UTILS)
|
@@ -1,7 +0,0 @@
|
|
1
|
-
teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
|
2
|
-
teams_alerter/core.py,sha256=hZwY81vf3LR7bhHgUV6XYSh1tany_Coy5aEguv5-sbQ,4656
|
3
|
-
teams_alerter/utils.py,sha256=EzmGSTsWC8UwWyDVgL_U5mw9MY9Ll19aZ_VGPZdSRZI,5772
|
4
|
-
teams_alerter-0.2.3.dist-info/METADATA,sha256=mCkPNerF-wSGyNtk4sCQWYXnjGeftnKUgBo2b25TokU,2194
|
5
|
-
teams_alerter-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
teams_alerter-0.2.3.dist-info/top_level.txt,sha256=Qt8-VgHT7YPTbMzYkAomK9itC-w4YpV7IJ5X6b-TC-4,14
|
7
|
-
teams_alerter-0.2.3.dist-info/RECORD,,
|
File without changes
|