teams-alerter 0.2.6__tar.gz → 0.2.8__tar.gz
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-0.2.6 → teams_alerter-0.2.8}/PKG-INFO +1 -1
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/pyproject.toml +1 -1
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter/core.py +53 -3
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter/utils.py +50 -10
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter.egg-info/PKG-INFO +1 -1
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/README.md +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/setup.cfg +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter/__init__.py +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter.egg-info/SOURCES.txt +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter.egg-info/dependency_links.txt +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter.egg-info/requires.txt +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/teams_alerter.egg-info/top_level.txt +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/tests/__init__.py +0 -0
- {teams_alerter-0.2.6 → teams_alerter-0.2.8}/tests/test_core.py +0 -0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "teams-alerter"
|
7
|
-
version = "0.2.
|
7
|
+
version = "0.2.8"
|
8
8
|
description = "Module pour envoyer des alertes Teams via Pub/Sub"
|
9
9
|
authors = [{ name = "Toki", email = "t.bakotondrabe-ext@paris-turf.com" }]
|
10
10
|
readme = "README.md"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
import traceback
|
3
|
+
import datetime
|
3
4
|
|
4
5
|
from google.cloud import pubsub_v1
|
5
6
|
from .utils import ErrorUtils, DateUtils, format_email_template, is_json
|
@@ -54,11 +55,11 @@ class TeamsAlerter:
|
|
54
55
|
"health_check_check_pg_wal_slot",
|
55
56
|
"health_check_check_meetings_ids",
|
56
57
|
"health_check_check_races_ids",
|
57
|
-
"health_check_check_partants_data",
|
58
58
|
"health_check_check_runners_ids",
|
59
59
|
"health_check_check_processing_queue_ids",
|
60
60
|
],
|
61
61
|
"email": [
|
62
|
+
"health_check_check_partants_data",
|
62
63
|
"health_check_check_horses_stats",
|
63
64
|
],
|
64
65
|
}
|
@@ -124,6 +125,55 @@ class TeamsAlerter:
|
|
124
125
|
""",
|
125
126
|
]
|
126
127
|
|
127
|
-
self.payload["email_template_html"] = format_email_template(
|
128
|
+
self.payload["email_template_html"] = format_email_template(
|
129
|
+
email_object, email_messages, table_data, self.utils["app_name"]
|
130
|
+
)
|
131
|
+
else:
|
132
|
+
print(
|
133
|
+
"⚠ ERREUR INTERNE : error_message health_check_check_horses_stats n'est pas un JSON valide :",
|
134
|
+
self.payload["detail"]["message"],
|
135
|
+
)
|
136
|
+
|
137
|
+
elif self.utils["app_name"] == "health_check_check_partants_data":
|
138
|
+
if is_json(self.payload["detail"]["message"]):
|
139
|
+
error_info_list = json.loads(self.payload["detail"]["message"])
|
140
|
+
|
141
|
+
table_data = []
|
142
|
+
for error_info in error_info_list["data"]:
|
143
|
+
table_data.append(
|
144
|
+
(
|
145
|
+
error_info["idCourse"],
|
146
|
+
error_info["dateCourse"],
|
147
|
+
error_info["nbInitialRunners_postgres"],
|
148
|
+
error_info["nbInitialRunners_mongo"],
|
149
|
+
error_info["nbNonRunners_postgres"],
|
150
|
+
error_info["nbNonRunners_mongo"],
|
151
|
+
error_info["nonRunners_postgres"],
|
152
|
+
error_info["nonRunners_mongo"],
|
153
|
+
error_info["nbRunners_postgres"],
|
154
|
+
error_info["nbRunners_mongo"],
|
155
|
+
)
|
156
|
+
)
|
157
|
+
email_object = "Contrôle DATASTREAM - Partants (COURSES)"
|
158
|
+
self.payload["email_object"] = email_object
|
159
|
+
|
160
|
+
email_messages = [
|
161
|
+
f"""
|
162
|
+
Bonjour, <br>
|
163
|
+
Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur les partants des courses du {datetime.date.today().strftime("%d/%m/%Y")} dans Datastream.
|
164
|
+
""",
|
165
|
+
f"""
|
166
|
+
Env: <strong>{self.utils["env"]}</strong> <br>
|
167
|
+
Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
|
168
|
+
Table name: <strong>tb_course</strong>
|
169
|
+
""",
|
170
|
+
]
|
171
|
+
|
172
|
+
self.payload["email_template_html"] = format_email_template(
|
173
|
+
email_object, email_messages, table_data, self.utils["app_name"]
|
174
|
+
)
|
128
175
|
else:
|
129
|
-
print(
|
176
|
+
print(
|
177
|
+
"⚠ ERREUR INTERNE : error_message health_check_check_partants_data n'est pas un JSON valide :",
|
178
|
+
self.payload["detail"]["message"],
|
179
|
+
)
|
@@ -32,7 +32,7 @@ class DateUtils:
|
|
32
32
|
return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
|
33
33
|
|
34
34
|
|
35
|
-
def format_email_template(email_object, email_messages, table_data):
|
35
|
+
def format_email_template(email_object, email_messages, table_data, app_name):
|
36
36
|
html = f"""
|
37
37
|
<html>
|
38
38
|
<head lang="fr">
|
@@ -62,7 +62,7 @@ def format_email_template(email_object, email_messages, table_data):
|
|
62
62
|
|
63
63
|
<tr>
|
64
64
|
<td style="padding:0 16px 24px 16px;">
|
65
|
-
{build_html_table(table_data)}
|
65
|
+
{build_html_table(table_data, app_name)}
|
66
66
|
</td>
|
67
67
|
</tr>
|
68
68
|
|
@@ -91,20 +91,60 @@ def format_email_template(email_object, email_messages, table_data):
|
|
91
91
|
return html
|
92
92
|
|
93
93
|
|
94
|
-
def build_html_table(table_data: list):
|
94
|
+
def build_html_table(table_data: list, app_name: str):
|
95
|
+
if app_name == "health_check_check_horses_stats":
|
96
|
+
html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
|
97
|
+
|
98
|
+
# format header
|
99
|
+
html_table += "<tr>"
|
100
|
+
for header in table_data[0]:
|
101
|
+
html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
|
102
|
+
html_table += "</tr>"
|
103
|
+
|
104
|
+
# format rows
|
105
|
+
for row in table_data[1:]:
|
106
|
+
html_table += "<tr>"
|
107
|
+
for cell in row:
|
108
|
+
html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
|
109
|
+
html_table += "</tr>"
|
110
|
+
|
111
|
+
html_table += "</table>"
|
112
|
+
|
113
|
+
return html_table
|
114
|
+
|
115
|
+
elif app_name == "health_check_check_partants_data":
|
116
|
+
return build_html_table_partants_course(table_data)
|
117
|
+
|
118
|
+
|
119
|
+
def build_html_table_partants_course(table_data: list):
|
95
120
|
html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
|
96
121
|
|
97
122
|
# format header
|
98
|
-
html_table += "
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
123
|
+
html_table += """
|
124
|
+
<tr>
|
125
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" rowspan="2">ID Course</th>
|
126
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" rowspan="2">Date Course</th>
|
127
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB initial runners</th>
|
128
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB non runners</th>
|
129
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">Non runners</th>
|
130
|
+
<th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB runners</th>
|
131
|
+
</tr>
|
132
|
+
<tr>
|
133
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
|
134
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
|
135
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
|
136
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
|
137
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
|
138
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
|
139
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
|
140
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
|
141
|
+
</tr>
|
142
|
+
"""
|
103
143
|
# format rows
|
104
|
-
for row in table_data
|
144
|
+
for row in table_data:
|
105
145
|
html_table += "<tr>"
|
106
146
|
for cell in row:
|
107
|
-
html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border
|
147
|
+
html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border:1px solid #bbbbbb;">{cell}</td>'
|
108
148
|
html_table += "</tr>"
|
109
149
|
|
110
150
|
html_table += "</table>"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|