teams-alerter 0.2.2__tar.gz → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Module pour envoyer des alertes Teams via Pub/Sub
5
5
  Author-email: Toki <t.bakotondrabe-ext@paris-turf.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "teams-alerter"
7
- version = "0.2.2"
7
+ version = "0.2.3"
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"
@@ -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, format_email_template_horse
5
+ from .utils import ErrorUtils, DateUtils, format_email_template
6
6
 
7
7
 
8
8
  class TeamsAlerter:
@@ -91,4 +91,25 @@ class TeamsAlerter:
91
91
 
92
92
  def format_email_template(self):
93
93
  self.payload["alert_type"].append("email")
94
- self.payload["email_template_html"] = format_email_template_horse()
94
+
95
+ if self.utils["app_name"] == "health_check_check_horses_stats":
96
+ error_info_list = json.loads(self.payload["detail"]["message"])
97
+ table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
98
+ for error_info in error_info_list:
99
+ table_data.append(
100
+ (
101
+ error_info["idCheval"],
102
+ error_info["champ"],
103
+ error_info["postgres"],
104
+ error_info["mongo"],
105
+ error_info["difference"],
106
+ )
107
+ )
108
+
109
+ email_object = "Contrôle DATASTREAM - Fiche cheval"
110
+ email_message = """
111
+ Bonjour, <br>
112
+ 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.
113
+ """
114
+
115
+ self.payload["email_template_html"] = format_email_template(email_object, email_message, table_data)
@@ -0,0 +1,123 @@
1
+ import datetime
2
+
3
+ from typing import TypedDict
4
+ from google.cloud import logging
5
+
6
+
7
+ class ErrorUtils(TypedDict):
8
+ logger: logging.Logger
9
+ env: str
10
+ app_project_id: str
11
+ topic_project_id: str
12
+ topic_id: str
13
+ app_name: str
14
+ teams_channel: str
15
+
16
+
17
+ class DateUtils:
18
+ @staticmethod
19
+ def get_str_utc_timestamp():
20
+ dt = datetime.datetime.utcnow()
21
+ return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
22
+
23
+ @staticmethod
24
+ def get_str_utc_timestamp_minus_5min():
25
+ dt = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
26
+ return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
27
+
28
+ @staticmethod
29
+ def get_str_utc_timestamp_plus_5min():
30
+ dt = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
31
+ return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
32
+
33
+
34
+ def format_email_template(email_object, email_message, table_data):
35
+ html = f"""
36
+ <html>
37
+ <head lang="fr">
38
+ <meta charset="utf-8">
39
+ <meta name="x-apple-disable-message-reformatting">
40
+ <meta name="viewport" content="width=device-width, initial-scale=1">
41
+ <title>Contrôle datastream</title>
42
+ </head>
43
+ <body style="margin:0; padding:0; background:#f5f7fb;">
44
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f7fb;">
45
+ <tr>
46
+ <td align="center" style="padding:24px;">
47
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="max-width:100%; background:#ffffff; border-radius:8px; border:1px solid #e6e9ef;">
48
+ <tr>
49
+ <td style="text-align: center; padding-top: 12px;">
50
+ <img style="height: 24px;" src="https://upload.wikimedia.org/wikipedia/fr/f/fd/Logo_Paris_Turf.svg" alt="" srcset="">
51
+ </td>
52
+ </tr>
53
+
54
+ <tr>
55
+ <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;">
56
+ Objet : {email_object}
57
+ </td>
58
+ </tr>
59
+
60
+ <tr>
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>
73
+
74
+ <tr>
75
+ <td style="padding:0 16px 24px 16px;">
76
+ {build_html_table(table_data)}
77
+ </td>
78
+ </tr>
79
+
80
+ <tr>
81
+ <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
82
+ Cordialement,
83
+ </td>
84
+ </tr>
85
+
86
+ <tr>
87
+ <td style="padding:0 24px 24px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:12px; line-height:18px; color:#6b7280;">
88
+ <div style="border-top:1px solid #eef2f7; padding-top:12px;text-align: center;">
89
+ Message automatique – ne pas répondre. <br>
90
+ © 2025 Paris-Turf – Tous droits réservés <br>
91
+ <a href="https://www.paris-turf.com">www.paris-turf.com</a>
92
+ </div>
93
+ </td>
94
+ </tr>
95
+ </table>
96
+ </td>
97
+ </tr>
98
+ </table>
99
+ </body>
100
+ </html>
101
+ """
102
+ return html
103
+
104
+
105
+ def build_html_table(table_data: list):
106
+ html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
107
+
108
+ # format header
109
+ html_table += "<tr>"
110
+ for header in table_data[0]:
111
+ html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
112
+ html_table += "</tr>"
113
+
114
+ # format rows
115
+ for row in table_data[1:]:
116
+ html_table += "<tr>"
117
+ for cell in row:
118
+ html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
119
+ html_table += "</tr>"
120
+
121
+ html_table += "</table>"
122
+
123
+ return html_table
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Module pour envoyer des alertes Teams via Pub/Sub
5
5
  Author-email: Toki <t.bakotondrabe-ext@paris-turf.com>
6
6
  License: MIT
@@ -1,114 +0,0 @@
1
- import datetime
2
-
3
- from typing import TypedDict
4
- from google.cloud import logging
5
-
6
-
7
- class ErrorUtils(TypedDict):
8
- logger: logging.Logger
9
- env: str
10
- app_project_id: str
11
- topic_project_id: str
12
- topic_id: str
13
- app_name: str
14
- teams_channel: str
15
-
16
-
17
- class DateUtils:
18
- @staticmethod
19
- def get_str_utc_timestamp():
20
- dt = datetime.datetime.utcnow()
21
- return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
22
-
23
- @staticmethod
24
- def get_str_utc_timestamp_minus_5min():
25
- dt = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
26
- return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
27
-
28
- @staticmethod
29
- def get_str_utc_timestamp_plus_5min():
30
- dt = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
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
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f7fb;">
42
- <tr>
43
- <td align="center" style="padding:24px;">
44
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="max-width:100%; background:#ffffff; border-radius:8px; border:1px solid #e6e9ef;">
45
- <tr>
46
- <td style="text-align: center; padding-top: 12px;">
47
- <img style="height: 24px;" src="https://upload.wikimedia.org/wikipedia/fr/f/fd/Logo_Paris_Turf.svg" alt="" srcset="">
48
- </td>
49
- </tr>
50
-
51
- <tr>
52
- <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;">
53
- Objet : {email_object}
54
- </td>
55
- </tr>
56
-
57
- <tr>
58
- <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
59
- {email_message}
60
- </td>
61
- </tr>
62
-
63
- <tr>
64
- <td style="padding:0 16px 24px 16px;">
65
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">
66
- <!-- Header -->
67
- <tr>
68
- <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>
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;">Champ</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;">Postgres</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;">Mongo</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;">Différence</th>
73
- </tr>
74
- <!-- Row 1 -->
75
- <tr>
76
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">12345</td>
77
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">formFigs</td>
78
- <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>
79
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Da (24) 7a 8a 10a ...</td>
80
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Début tronqué (8a 6a manquants)</td>
81
- </tr>
82
- <!-- Row 2 -->
83
- <tr>
84
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">123456</td>
85
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">totalPrize</td>
86
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108220</td>
87
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108222</td>
88
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">-2</td>
89
- </tr>
90
- </table>
91
- </td>
92
- </tr>
93
-
94
- <tr>
95
- <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
96
- Cordialement,
97
- </td>
98
- </tr>
99
-
100
- <tr>
101
- <td style="padding:0 24px 24px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:12px; line-height:18px; color:#6b7280;">
102
- <div style="border-top:1px solid #eef2f7; padding-top:12px;text-align: center;">
103
- Message automatique – ne pas répondre. <br>
104
- © 2025 Paris-Turf – Tous droits réservés <br>
105
- <a href="https://www.paris-turf.com">www.paris-turf.com</a>
106
- </div>
107
- </td>
108
- </tr>
109
- </table>
110
- </td>
111
- </tr>
112
- </table>
113
- """
114
- return html
File without changes
File without changes