teams-alerter 0.1.9__py3-none-any.whl → 0.2.0__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 +52 -20
- teams_alerter/utils.py +85 -0
- {teams_alerter-0.1.9.dist-info → teams_alerter-0.2.0.dist-info}/METADATA +1 -1
- teams_alerter-0.2.0.dist-info/RECORD +7 -0
- teams_alerter-0.1.9.dist-info/RECORD +0 -7
- {teams_alerter-0.1.9.dist-info → teams_alerter-0.2.0.dist-info}/WHEEL +0 -0
- {teams_alerter-0.1.9.dist-info → teams_alerter-0.2.0.dist-info}/top_level.txt +0 -0
teams_alerter/core.py
CHANGED
@@ -2,7 +2,7 @@ import json
|
|
2
2
|
import traceback
|
3
3
|
|
4
4
|
from google.cloud import pubsub_v1
|
5
|
-
from .utils import ErrorUtils, DateUtils
|
5
|
+
from .utils import ErrorUtils, DateUtils, format_email_template_horse
|
6
6
|
|
7
7
|
|
8
8
|
class TeamsAlerter:
|
@@ -10,8 +10,10 @@ class TeamsAlerter:
|
|
10
10
|
def __init__(
|
11
11
|
self,
|
12
12
|
utils: ErrorUtils,
|
13
|
+
payload: None,
|
13
14
|
):
|
14
15
|
self.utils = utils
|
16
|
+
self.payload = payload
|
15
17
|
|
16
18
|
@staticmethod
|
17
19
|
def handle_error(error: Exception, utils: ErrorUtils) -> None:
|
@@ -27,31 +29,16 @@ class TeamsAlerter:
|
|
27
29
|
level = "ERROR"
|
28
30
|
|
29
31
|
teams_alerter = TeamsAlerter(utils)
|
32
|
+
teams_alerter.format_payload(detail, level, url_log, utc_timestamp)
|
33
|
+
teams_alerter.publish_alert()
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
def publish_alert(self, detail, level, url_log, teams_template, utc_timestamp):
|
34
|
-
|
35
|
-
# Formatage du payload
|
36
|
-
payload = json.dumps(
|
37
|
-
{
|
38
|
-
"app_name": self.utils["app_name"],
|
39
|
-
"teams_channel": self.utils["teams_channel"],
|
40
|
-
"detail": detail,
|
41
|
-
"level": level,
|
42
|
-
"environment": self.utils["env"],
|
43
|
-
"url_log": url_log,
|
44
|
-
"timestamp": utc_timestamp,
|
45
|
-
"teams_template": teams_template,
|
46
|
-
}
|
47
|
-
)
|
48
|
-
|
35
|
+
def publish_alert(self):
|
49
36
|
# Création d'un éditeur
|
50
37
|
publisher = pubsub_v1.PublisherClient()
|
51
38
|
topic_path = publisher.topic_path(self.utils["topic_project_id"], self.utils["topic_id"])
|
52
39
|
|
53
40
|
# Message à publier
|
54
|
-
data = payload.encode("utf-8")
|
41
|
+
data = json.dumps(self.payload).encode("utf-8")
|
55
42
|
|
56
43
|
# Publier le message
|
57
44
|
try:
|
@@ -60,3 +47,48 @@ class TeamsAlerter:
|
|
60
47
|
|
61
48
|
except Exception as e:
|
62
49
|
self.utils["logger"](f"🟥Une erreur s'est produite lors de la publication du message : {e}")
|
50
|
+
|
51
|
+
def format_payload(self, detail, level, url_log, utc_timestamp):
|
52
|
+
app_list = {
|
53
|
+
"teams": [
|
54
|
+
"health_check_check_pg_wal_slot",
|
55
|
+
"health_check_check_meetings_ids",
|
56
|
+
"health_check_check_races_ids",
|
57
|
+
"health_check_check_partants_data",
|
58
|
+
"health_check_check_runners_ids",
|
59
|
+
],
|
60
|
+
"email": [
|
61
|
+
"health_check_check_horses_stats",
|
62
|
+
],
|
63
|
+
}
|
64
|
+
|
65
|
+
# base payload
|
66
|
+
self.payload = {
|
67
|
+
# base info
|
68
|
+
"app_name": self.utils["app_name"],
|
69
|
+
"detail": detail,
|
70
|
+
"level": level,
|
71
|
+
"environment": self.utils["env"],
|
72
|
+
"url_log": url_log,
|
73
|
+
"timestamp": utc_timestamp,
|
74
|
+
# alerting info
|
75
|
+
"alert_type": [], # teams, email
|
76
|
+
# "teams_channel": "",
|
77
|
+
# "teams_template": "",
|
78
|
+
# "email_template_html": "",
|
79
|
+
}
|
80
|
+
|
81
|
+
if self.utils["app_name"] in app_list["teams"]:
|
82
|
+
self.format_teams_template()
|
83
|
+
|
84
|
+
if self.utils["app_name"] in app_list["email"]:
|
85
|
+
self.format_email_template()
|
86
|
+
|
87
|
+
def format_teams_template(self):
|
88
|
+
self.payload["alert_type"].append("teams")
|
89
|
+
self.payload["teams_channel"] = self.utils["teams_channel"]
|
90
|
+
self.payload["teams_template"] = "card"
|
91
|
+
|
92
|
+
def format_email_template(self):
|
93
|
+
self.payload["alert_type"].append("email")
|
94
|
+
self.payload["email_template_html"] = format_email_template_horse()
|
teams_alerter/utils.py
CHANGED
@@ -29,3 +29,88 @@ class DateUtils:
|
|
29
29
|
def get_str_utc_timestamp_plus_5min():
|
30
30
|
dt = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
|
31
31
|
return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
|
32
|
+
|
33
|
+
|
34
|
+
def format_email_template_horse():
|
35
|
+
email_object = "Contrôle DATASTREAM - Fiche cheval"
|
36
|
+
email_message = """
|
37
|
+
Bonjour, <br>
|
38
|
+
Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream (champs formFigs et totalPrize) le 25/08/2025 à 13:15:00 UTC.
|
39
|
+
"""
|
40
|
+
html = f"""
|
41
|
+
<body style="margin:0; padding:0; background:#f5f7fb;">
|
42
|
+
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f7fb;">
|
43
|
+
<tr>
|
44
|
+
<td align="center" style="padding:24px;">
|
45
|
+
<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="max-width:100%; background:#ffffff; border-radius:8px; border:1px solid #e6e9ef;">
|
46
|
+
<tr>
|
47
|
+
<td style="text-align: center; padding-top: 12px;">
|
48
|
+
<img style="height: 24px;" src="https://upload.wikimedia.org/wikipedia/fr/f/fd/Logo_Paris_Turf.svg" alt="" srcset="">
|
49
|
+
</td>
|
50
|
+
</tr>
|
51
|
+
|
52
|
+
<tr>
|
53
|
+
<td style="padding:24px 24px 12px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:20px; line-height:26px; color:#111827; font-weight:700;">
|
54
|
+
Objet : {email_object}
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
|
58
|
+
<tr>
|
59
|
+
<td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
|
60
|
+
{email_message}
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
|
64
|
+
<tr>
|
65
|
+
<td style="padding:0 16px 24px 16px;">
|
66
|
+
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">
|
67
|
+
<!-- Header -->
|
68
|
+
<tr>
|
69
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">ID cheval</th>
|
70
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Champ</th>
|
71
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
|
72
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
|
73
|
+
<th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Différence</th>
|
74
|
+
</tr>
|
75
|
+
<!-- Row 1 -->
|
76
|
+
<tr>
|
77
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">12345</td>
|
78
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">formFigs</td>
|
79
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">8a 6a Da (24) 7a 8a 10a ...</td>
|
80
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Da (24) 7a 8a 10a ...</td>
|
81
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Début tronqué (8a 6a manquants)</td>
|
82
|
+
</tr>
|
83
|
+
<!-- Row 2 -->
|
84
|
+
<tr>
|
85
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">123456</td>
|
86
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">totalPrize</td>
|
87
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108220</td>
|
88
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108222</td>
|
89
|
+
<td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">-2</td>
|
90
|
+
</tr>
|
91
|
+
</table>
|
92
|
+
</td>
|
93
|
+
</tr>
|
94
|
+
|
95
|
+
<tr>
|
96
|
+
<td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
|
97
|
+
Cordialement,
|
98
|
+
</td>
|
99
|
+
</tr>
|
100
|
+
|
101
|
+
<tr>
|
102
|
+
<td style="padding:0 24px 24px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:12px; line-height:18px; color:#6b7280;">
|
103
|
+
<div style="border-top:1px solid #eef2f7; padding-top:12px;text-align: center;">
|
104
|
+
Message automatique – ne pas répondre. <br>
|
105
|
+
© 2025 Paris-Turf – Tous droits réservés <br>
|
106
|
+
<a href="https://www.paris-turf.com">www.paris-turf.com</a>
|
107
|
+
</div>
|
108
|
+
</td>
|
109
|
+
</tr>
|
110
|
+
</table>
|
111
|
+
</td>
|
112
|
+
</tr>
|
113
|
+
</table>
|
114
|
+
</body>
|
115
|
+
"""
|
116
|
+
return html
|
@@ -0,0 +1,7 @@
|
|
1
|
+
teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
|
2
|
+
teams_alerter/core.py,sha256=UnqP1LT0eSt13IA5qnge6MaSBmWgS9VVibNlqHskLjk,3578
|
3
|
+
teams_alerter/utils.py,sha256=4Yhrhld9NpcJpb4y9XSnGEbsAoIzUhKBhev8YFSfqA0,6769
|
4
|
+
teams_alerter-0.2.0.dist-info/METADATA,sha256=w9HDzU31rEXgZMPt72q3WwE0bIa_w-4pclfBY24SnSQ,2194
|
5
|
+
teams_alerter-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
teams_alerter-0.2.0.dist-info/top_level.txt,sha256=Qt8-VgHT7YPTbMzYkAomK9itC-w4YpV7IJ5X6b-TC-4,14
|
7
|
+
teams_alerter-0.2.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
|
2
|
-
teams_alerter/core.py,sha256=MlRSHQaLVheV9QrH871hdsZ7aqCqvwRx-1I9ZcdTVOg,2394
|
3
|
-
teams_alerter/utils.py,sha256=FIv5LaU7Ff4mB9PRvYILCq3DJJKDImbgDx_pCTGbp9k,861
|
4
|
-
teams_alerter-0.1.9.dist-info/METADATA,sha256=pO2I6IKitRSf6qafM9K2SDu2saGsxiVdDhuUPTPf3IQ,2194
|
5
|
-
teams_alerter-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
teams_alerter-0.1.9.dist-info/top_level.txt,sha256=Qt8-VgHT7YPTbMzYkAomK9itC-w4YpV7IJ5X6b-TC-4,14
|
7
|
-
teams_alerter-0.1.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|