teams-alerter 0.2.5__py3-none-any.whl → 0.2.7__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 CHANGED
@@ -1,8 +1,9 @@
1
1
  import json
2
2
  import traceback
3
+ import datetime
3
4
 
4
5
  from google.cloud import pubsub_v1
5
- from .utils import ErrorUtils, DateUtils, format_email_template
6
+ from .utils import ErrorUtils, DateUtils, format_email_template, is_json
6
7
 
7
8
 
8
9
  class TeamsAlerter:
@@ -54,10 +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
+ "health_check_check_processing_queue_ids",
59
60
  ],
60
61
  "email": [
62
+ "health_check_check_partants_data",
61
63
  "health_check_check_horses_stats",
62
64
  ],
63
65
  }
@@ -94,31 +96,83 @@ class TeamsAlerter:
94
96
  self.payload["email_object"] = "Contrôle DATASTREAM"
95
97
 
96
98
  if self.utils["app_name"] == "health_check_check_horses_stats":
97
- error_info_list = json.loads(self.payload["detail"]["message"])
98
- table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
99
- for error_info in error_info_list["data"]:
100
- table_data.append(
101
- (
102
- error_info["idCheval"],
103
- error_info["champ"],
104
- error_info["postgres"],
105
- error_info["mongo"],
106
- error_info["difference"],
99
+ if is_json(self.payload["detail"]["message"]):
100
+ # cette ligne plante si message n'est pas json
101
+ error_info_list = json.loads(self.payload["detail"]["message"])
102
+ table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
103
+ for error_info in error_info_list["data"]:
104
+ table_data.append(
105
+ (
106
+ error_info["idCheval"],
107
+ error_info["champ"],
108
+ error_info["postgres"],
109
+ error_info["mongo"],
110
+ error_info["difference"],
111
+ )
107
112
  )
113
+
114
+ email_object = "Contrôle DATASTREAM - Fiche cheval"
115
+ self.payload["email_object"] = email_object
116
+ email_messages = [
117
+ """
118
+ Bonjour, <br>
119
+ Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream.
120
+ """,
121
+ f"""
122
+ Env: <strong>{self.utils["env"]}</strong> <br>
123
+ Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
124
+ Champs: <strong>formFigs et/ou totalPrize</strong>
125
+ """,
126
+ ]
127
+
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"],
108
135
  )
109
136
 
110
- email_object = "Contrôle DATASTREAM - Fiche cheval"
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)
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
+ table_data = [("ID COURSE", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
141
+ for error_info in error_info_list["data"]:
142
+ table_data.append(
143
+ (
144
+ error_info["idCourse"],
145
+ error_info["dateCourse"],
146
+ error_info["nbInitialRunners_postgres"],
147
+ error_info["nbInitialRunners_mongo"],
148
+ error_info["nbNonRunners_postgres"],
149
+ error_info["nbNonRunners_mongo"],
150
+ error_info["nonRunners_postgres"],
151
+ error_info["nonRunners_mongo"],
152
+ error_info["nbRunners_postgres"],
153
+ error_info["nbRunners_mongo"],
154
+ )
155
+ )
156
+ email_object = "Contrôle DATASTREAM - Partants (COURSES)"
157
+ self.payload["email_object"] = email_object
158
+
159
+ email_messages = [
160
+ f"""
161
+ Bonjour, <br>
162
+ 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.
163
+ """,
164
+ f"""
165
+ Env: <strong>{self.utils["env"]}</strong> <br>
166
+ Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
167
+ Table name: <strong>tb_course</strong>
168
+ """,
169
+ ]
170
+
171
+ self.payload["email_template_html"] = format_email_template(
172
+ email_object, email_messages, [], self.utils["app_name"]
173
+ )
174
+ else:
175
+ print(
176
+ "⚠ ERREUR INTERNE : error_message health_check_check_partants_data n'est pas un JSON valide :",
177
+ self.payload["detail"]["message"],
178
+ )
teams_alerter/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import datetime
2
+ import json
2
3
 
3
4
  from typing import TypedDict
4
5
  from google.cloud import logging
@@ -31,7 +32,7 @@ class DateUtils:
31
32
  return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
32
33
 
33
34
 
34
- def format_email_template(email_object, email_messages, table_data):
35
+ def format_email_template(email_object, email_messages, table_data, app_name):
35
36
  html = f"""
36
37
  <html>
37
38
  <head lang="fr">
@@ -61,7 +62,7 @@ def format_email_template(email_object, email_messages, table_data):
61
62
 
62
63
  <tr>
63
64
  <td style="padding:0 16px 24px 16px;">
64
- {build_html_table(table_data)}
65
+ {build_html_table(table_data, app_name)}
65
66
  </td>
66
67
  </tr>
67
68
 
@@ -90,20 +91,60 @@ def format_email_template(email_object, email_messages, table_data):
90
91
  return html
91
92
 
92
93
 
93
- 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):
94
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;">'
95
121
 
96
122
  # format header
97
- html_table += "<tr>"
98
- for header in table_data[0]:
99
- html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
100
- html_table += "</tr>"
101
-
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
+ """
102
143
  # format rows
103
- for row in table_data[1:]:
144
+ for row in table_data:
104
145
  html_table += "<tr>"
105
146
  for cell in row:
106
- html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
147
+ html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border:1px solid #bbbbbb;">{cell}</td>'
107
148
  html_table += "</tr>"
108
149
 
109
150
  html_table += "</table>"
@@ -122,3 +163,13 @@ def build_html_message(email_messages: list[str]):
122
163
  </tr>
123
164
  """
124
165
  return content
166
+
167
+
168
+ def is_json(value):
169
+ if not isinstance(value, str):
170
+ return False # ce n'est même pas une chaîne
171
+ try:
172
+ json.loads(value)
173
+ return True
174
+ except json.JSONDecodeError:
175
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.5
3
+ Version: 0.2.7
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
@@ -0,0 +1,9 @@
1
+ teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
+ teams_alerter/core.py,sha256=0IsSXhiCKXbWcctViUO4G57bhd_vX1dAWRgt443CABY,7910
3
+ teams_alerter/utils.py,sha256=h96evthyIezxKxBauHxevVslyHSE_LJ0h6DcKy6KNBs,9619
4
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
6
+ teams_alerter-0.2.7.dist-info/METADATA,sha256=6W7QJ_P0pAkHHt-8wL8zZVrXtNe4-44ZYIClhqD7CC0,2194
7
+ teams_alerter-0.2.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ teams_alerter-0.2.7.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
9
+ teams_alerter-0.2.7.dist-info/RECORD,,
@@ -1,9 +0,0 @@
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,,