HgO (27828ec3) at 22 Jan 10:50
fix linting
HgO (d9e22c6e) at 22 Jan 10:43
fix linting and improve logs
HgO (86aa44b2) at 22 Jan 10:35
implement matrix client failover
Closes #10
HgO (6cfdf342) at 22 Jan 10:29
Permettre au bot de se connecter à des comptes matrix de secours, donc sur des serveurs différents, pour éviter d'être coincé parce que le serveur matrix est en panne.
En règle générale, il y aura un compte principal, et si le serveur est down, le bot envoie les alertes sur le second serveur, et ainsi de suite.
HgO (6cfdf342) at 29 Jan 21:26
Merge branch '9-meilleure-gestion-des-exceptions-pour-le-serveur-ht...
HgO (a08cd691) at 29 Jan 20:48
J'ai remarqué cette exception dans les logs:
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: 2023-01-15 04:41:04,617 | aiohttp.server [ERROR] Error handling request
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: Traceback (most recent call last):
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await request_handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp_prometheus_exporter/middleware.py", line 111, in prometheus_middleware
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: raise e from None
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp_prometheus_exporter/middleware.py", line 83, in prometheus_middleware
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: response = await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/webhook.py", line 107, in create_alerts
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await create_alert(alert, room_id, request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/webhook.py", line 157, in create_alert
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: event = await send_text_to_room(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/chat_functions.py", line 72, in send_text_to_room
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: response_event = await matrix_client.room_send(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1575, in room_send
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await self.share_group_session(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1918, in share_group_session
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await self.keys_claim(missing_sessions)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1866, in keys_claim
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return await self._send(KeysClaimResponse, method, path, data)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 761, in _send
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await self.create_matrix_response(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 535, in create_matrix_response
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = response_class.from_dict(parsed_dict, *data)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/responses.py", line 178, in wrapper
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return error_class.from_dict(parsed_dict, *args, **kwargs)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: TypeError: from_dict() missing 1 required positional argument: 'room_id'
A priori, cela s'est produit parce que le bot était en train de se reconnecter au moment où le serveur essayait d'envoyer l'alerte sur le salon… ce qui a fait complètement crasher le bot (plus d'alertes envoyées à partir de là).
Je vais donc faire en sorte que ce genre d'exception inattendue soit également gérée.
Closes #9
HgO (6cfdf342) at 29 Jan 20:48
Merge branch '9-meilleure-gestion-des-exceptions-pour-le-serveur-ht...
... and 1 more commit
HgO (a08cd691) at 29 Jan 20:44
handle generic exceptions
Closes #9
HgO (c34a823c) at 29 Jan 20:42
J'ai remarqué cette exception dans les logs:
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: 2023-01-15 04:41:04,617 | aiohttp.server [ERROR] Error handling request
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: Traceback (most recent call last):
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await request_handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp_prometheus_exporter/middleware.py", line 111, in prometheus_middleware
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: raise e from None
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/aiohttp_prometheus_exporter/middleware.py", line 83, in prometheus_middleware
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: response = await handler(request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/webhook.py", line 107, in create_alerts
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await create_alert(alert, room_id, request)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/webhook.py", line 157, in create_alert
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: event = await send_text_to_room(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/matrix_alertbot/chat_functions.py", line 72, in send_text_to_room
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: response_event = await matrix_client.room_send(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1575, in room_send
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await self.share_group_session(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1918, in share_group_session
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: await self.keys_claim(missing_sessions)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 1866, in keys_claim
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return await self._send(KeysClaimResponse, method, path, data)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 761, in _send
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = await self.create_matrix_response(
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/client/async_client.py", line 535, in create_matrix_response
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: resp = response_class.from_dict(parsed_dict, *data)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: File "/opt/matrix-alertbot/lib/python3.9/site-packages/nio/responses.py", line 178, in wrapper
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: return error_class.from_dict(parsed_dict, *args, **kwargs)
Jan 15 04:41:04 storage-01 matrix-alertbot[478]: TypeError: from_dict() missing 1 required positional argument: 'room_id'
A priori, cela s'est produit parce que le bot était en train de se reconnecter au moment où le serveur essayait d'envoyer l'alerte sur le salon… ce qui a fait complètement crasher le bot (plus d'alertes envoyées à partir de là).
Je vais donc faire en sorte que ce genre d'exception inattendue soit également gérée.
HgO (c34a823c) at 25 Nov 19:02
Merge branch '8-renvoyer-l-alerte-quand-on-recoit-une-roomsenderror...
HgO (29dcab15) at 25 Nov 18:59
Apparemment, la RoomSendError
contient un attribut retry_after_ms
. Au lieu d'émettre une exception, on pourrait juste attendre le temps nécessaire et essayer d'envoyer le message sur le serveur Matrix à nouveau. Au bout de x essais, on émettrait enfin l'exception.
Closes #8
HgO (c34a823c) at 25 Nov 18:59
Merge branch '8-renvoyer-l-alerte-quand-on-recoit-une-roomsenderror...
... and 1 more commit