refactor: update email HTML structure and enhance notification generator - Modified email HTML to reflect updated model names and error/warning messages. - Adjusted notification generator to improve execution counts and streamline output handling. - Refactored activities in orchestrator to correct parameter names and improve type hints for better clarity. - Enhanced email builder to handle error, warning, and info models more efficiently.
280 lines
13 KiB
Plaintext
280 lines
13 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "1786cbf0",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Generated 10 notifications\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from unittest.mock import MagicMock\n",
|
|
"from orchestrator.activities.mongo_db import MongoDB\n",
|
|
"from orchestrator.utils.connectors_config import build_mongodb_config\n",
|
|
"import random\n",
|
|
"from datetime import datetime, timezone\n",
|
|
"import json\n",
|
|
"\n",
|
|
"word_list = [\n",
|
|
" 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',\n",
|
|
" 'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',\n",
|
|
" 'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua'\n",
|
|
" ]\n",
|
|
"\n",
|
|
"config = build_mongodb_config()\n",
|
|
"\n",
|
|
"mongo_db = MongoDB(\n",
|
|
" connection_string=config['connection_string'],\n",
|
|
" database_name=config['database_name'],\n",
|
|
" ttl_index_seconds=config['ttl_index_seconds'],\n",
|
|
" logger=MagicMock(),\n",
|
|
" notification_handler=MagicMock()\n",
|
|
")\n",
|
|
"\n",
|
|
"AMOUT = 10\n",
|
|
"\n",
|
|
"notification_ids = [\n",
|
|
" \"TAG_node<tag>:<name>_LISTENNING_STOPPED\",\n",
|
|
" \"OPC_<event>__<server>\",\n",
|
|
" \"REPORT_PARTITION_MANAGER\",\n",
|
|
" \"<random_id>\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"notifications = []\n",
|
|
"\n",
|
|
"for _ in range(AMOUT):\n",
|
|
" # Choose random notification ID and fill in placeholders\n",
|
|
" notification_id = random.choice(notification_ids)\n",
|
|
" \n",
|
|
" if \"<tag>\" in notification_id:\n",
|
|
" notification_id = notification_id.replace(\"<tag>\", str(random.randint(1,100)))\n",
|
|
" if \"<name>\" in notification_id:\n",
|
|
" notification_id = notification_id.replace(\"<name>\", f\"tag_{random.randint(1,100)}\")\n",
|
|
" if \"<event>\" in notification_id:\n",
|
|
" events = [\"LISTENNING_STOPPED\", \"CONNECTION_RETRY\", \"LISTENNING_BACK\", \"SUBSCRIPTION\", \"QUEUE_RETRIEVE\"]\n",
|
|
" notification_id = notification_id.replace(\"<event>\", random.choice(events))\n",
|
|
" if \"<server>\" in notification_id:\n",
|
|
" notification_id = notification_id.replace(\"<server>\", f\"server_{random.randint(1,10)}\")\n",
|
|
" if \"<random_id>\" in notification_id:\n",
|
|
" notification_id = notification_id.replace(\"<random_id>\", \"_\".join(random.choices(word_list, k=random.randint(3,5))).upper())\n",
|
|
"\n",
|
|
" notification = {\n",
|
|
" \"project\": \"sientia-laborious\",\n",
|
|
" \"pipeline\": \"_\".join(random.choices(word_list, k=random.randint(2,4))), \n",
|
|
" \"trigger\": \"_\".join(random.choices(word_list, k=random.randint(3,6))),\n",
|
|
" \"model_name\": \" \".join(random.choices(word_list, k=random.randint(2,4))),\n",
|
|
" \"model_id\": str(random.randint(1,100)),\n",
|
|
" \"block\": \"_\".join(random.choices(word_list, k=random.randint(2,4))),\n",
|
|
" \"level\": random.choice([\"INFO\", \"WARNING\", \"ERROR\"]),\n",
|
|
" \"message\": \" \".join(random.choices(word_list, k=random.randint(5,10))),\n",
|
|
" \"attachment_content\": \" \".join(random.choices(word_list, k=random.randint(20,30))),\n",
|
|
" \"notification_id\": notification_id,\n",
|
|
" \"timestamp\": datetime.now(timezone.utc)\n",
|
|
" }\n",
|
|
" \n",
|
|
" notifications.append(notification)\n",
|
|
"\n",
|
|
"print(f\"Generated {len(notifications)} notifications\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "c1467b72",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from orchestrator.utils.email_builder import EmailBuilder\n",
|
|
"from unittest.mock import MagicMock\n",
|
|
"\n",
|
|
"\n",
|
|
"email_builder = EmailBuilder(logger=MagicMock())\n",
|
|
"\n",
|
|
"html = email_builder.build_email(notifications, \"Alerts\")\n",
|
|
"\n",
|
|
"with open('email.html', 'w') as file:\n",
|
|
" file.write(html)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"id": "ffd7be77",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[{'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'magna_incididunt',\n",
|
|
" 'trigger': 'dolor_dolor_aliqua_ipsum_do_magna',\n",
|
|
" 'model_name': 'et sed',\n",
|
|
" 'model_id': '53',\n",
|
|
" 'block': 'labore_do_ipsum_ipsum',\n",
|
|
" 'level': 'INFO',\n",
|
|
" 'message': 'tempor dolore eiusmod sit sit sed elit',\n",
|
|
" 'attachment_content': 'sit labore sed amet sit magna ut ut labore do ut adipiscing amet incididunt magna do sit eiusmod dolor do sit incididunt amet incididunt consectetur elit et ipsum elit amet',\n",
|
|
" 'notification_id': 'OPC_LISTENNING_STOPPED__server_6',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650570, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'adipiscing_do',\n",
|
|
" 'trigger': 'sit_lorem_dolore',\n",
|
|
" 'model_name': 'incididunt adipiscing elit sit',\n",
|
|
" 'model_id': '64',\n",
|
|
" 'block': 'eiusmod_aliqua_incididunt',\n",
|
|
" 'level': 'WARNING',\n",
|
|
" 'message': 'magna incididunt dolore sed eiusmod sit incididunt ut',\n",
|
|
" 'attachment_content': 'incididunt incididunt adipiscing do ipsum tempor ut eiusmod sit tempor tempor aliqua aliqua dolor labore incididunt amet do sed tempor dolor labore',\n",
|
|
" 'notification_id': 'ADIPISCING_AMET_IPSUM',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650621, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'sed_aliqua',\n",
|
|
" 'trigger': 'aliqua_adipiscing_adipiscing_sed_do_sit',\n",
|
|
" 'model_name': 'do elit',\n",
|
|
" 'model_id': '73',\n",
|
|
" 'block': 'lorem_adipiscing',\n",
|
|
" 'level': 'ERROR',\n",
|
|
" 'message': 'incididunt dolor lorem incididunt elit incididunt dolor consectetur ipsum ut',\n",
|
|
" 'attachment_content': 'dolor ut do amet dolore dolor do eiusmod eiusmod incididunt aliqua et sed labore incididunt aliqua sed et tempor consectetur elit et consectetur do ipsum',\n",
|
|
" 'notification_id': 'REPORT_PARTITION_MANAGER',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650661, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'dolore_et_aliqua_et',\n",
|
|
" 'trigger': 'adipiscing_amet_sit_do',\n",
|
|
" 'model_name': 'do adipiscing et',\n",
|
|
" 'model_id': '10',\n",
|
|
" 'block': 'amet_dolor',\n",
|
|
" 'level': 'WARNING',\n",
|
|
" 'message': 'dolore do et consectetur adipiscing do magna eiusmod eiusmod',\n",
|
|
" 'attachment_content': 'sit adipiscing adipiscing consectetur magna sed magna adipiscing dolor incididunt et adipiscing adipiscing elit et labore tempor tempor adipiscing sit dolore sed dolore dolor labore sed',\n",
|
|
" 'notification_id': 'TAG_node46:tag_73_LISTENNING_STOPPED',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650706, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'ipsum_lorem_sit_sit',\n",
|
|
" 'trigger': 'et_ut_sit_dolore',\n",
|
|
" 'model_name': 'dolore sit',\n",
|
|
" 'model_id': '58',\n",
|
|
" 'block': 'et_lorem_incididunt_ipsum',\n",
|
|
" 'level': 'INFO',\n",
|
|
" 'message': 'adipiscing magna adipiscing adipiscing sit tempor',\n",
|
|
" 'attachment_content': 'incididunt amet dolor incididunt dolore et lorem amet ut magna tempor amet do consectetur dolore magna elit aliqua eiusmod ipsum labore',\n",
|
|
" 'notification_id': 'REPORT_PARTITION_MANAGER',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650742, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'dolor_sit_aliqua',\n",
|
|
" 'trigger': 'lorem_incididunt_labore',\n",
|
|
" 'model_name': 'lorem dolore amet',\n",
|
|
" 'model_id': '13',\n",
|
|
" 'block': 'ipsum_tempor_ipsum',\n",
|
|
" 'level': 'WARNING',\n",
|
|
" 'message': 'et sed adipiscing tempor dolor magna do lorem',\n",
|
|
" 'attachment_content': 'do incididunt dolore eiusmod adipiscing amet amet amet eiusmod lorem dolor labore labore ipsum dolore amet labore ipsum labore do amet',\n",
|
|
" 'notification_id': 'TAG_node13:tag_59_LISTENNING_STOPPED',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650785, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'lorem_do_consectetur',\n",
|
|
" 'trigger': 'sit_aliqua_sit',\n",
|
|
" 'model_name': 'eiusmod sed',\n",
|
|
" 'model_id': '9',\n",
|
|
" 'block': 'do_ipsum',\n",
|
|
" 'level': 'WARNING',\n",
|
|
" 'message': 'eiusmod et consectetur do dolore dolor sed amet',\n",
|
|
" 'attachment_content': 'sed dolore dolore et et dolore dolor eiusmod aliqua adipiscing incididunt dolor lorem tempor consectetur dolor amet elit et aliqua lorem ipsum consectetur tempor tempor elit labore labore dolore',\n",
|
|
" 'notification_id': 'OPC_SUBSCRIPTION__server_2',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650826, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'labore_elit_adipiscing',\n",
|
|
" 'trigger': 'dolore_incididunt_tempor_lorem_dolore',\n",
|
|
" 'model_name': 'adipiscing do',\n",
|
|
" 'model_id': '63',\n",
|
|
" 'block': 'tempor_elit',\n",
|
|
" 'level': 'INFO',\n",
|
|
" 'message': 'et do aliqua lorem incididunt',\n",
|
|
" 'attachment_content': 'ut eiusmod consectetur sit labore ut tempor et sit sit do incididunt incididunt sed eiusmod dolor adipiscing dolor ut sed amet labore amet amet sed et elit sed ipsum',\n",
|
|
" 'notification_id': 'TAG_node76:tag_73_LISTENNING_STOPPED',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650875, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'ut_lorem_et',\n",
|
|
" 'trigger': 'labore_labore_ipsum_magna',\n",
|
|
" 'model_name': 'dolor magna',\n",
|
|
" 'model_id': '74',\n",
|
|
" 'block': 'tempor_dolore_eiusmod',\n",
|
|
" 'level': 'ERROR',\n",
|
|
" 'message': 'ipsum amet ipsum aliqua et eiusmod',\n",
|
|
" 'attachment_content': 'incididunt dolore do sit sed ut sed sit magna sed amet elit elit consectetur dolor labore magna consectetur tempor magna',\n",
|
|
" 'notification_id': 'REPORT_PARTITION_MANAGER',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650910, tzinfo=datetime.timezone.utc)},\n",
|
|
" {'project': 'sientia-laborious',\n",
|
|
" 'pipeline': 'magna_sit_amet_sed',\n",
|
|
" 'trigger': 'ut_dolor_sed',\n",
|
|
" 'model_name': 'labore sit lorem',\n",
|
|
" 'model_id': '13',\n",
|
|
" 'block': 'dolor_labore_lorem',\n",
|
|
" 'level': 'ERROR',\n",
|
|
" 'message': 'et adipiscing ipsum ut aliqua ut adipiscing aliqua amet',\n",
|
|
" 'attachment_content': 'aliqua labore aliqua lorem labore aliqua sed sit magna ut do amet do eiusmod sit consectetur sed ipsum elit amet aliqua labore sit',\n",
|
|
" 'notification_id': 'OPC_CONNECTION_RETRY__server_6',\n",
|
|
" 'timestamp': datetime.datetime(2025, 7, 28, 20, 5, 38, 650949, tzinfo=datetime.timezone.utc)}]"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"notifications"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"id": "55aed216",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"InsertManyResult([ObjectId('6887d812645b7515e8402983'), ObjectId('6887d812645b7515e8402984'), ObjectId('6887d812645b7515e8402985'), ObjectId('6887d812645b7515e8402986'), ObjectId('6887d812645b7515e8402987'), ObjectId('6887d812645b7515e8402988'), ObjectId('6887d812645b7515e8402989'), ObjectId('6887d812645b7515e840298a'), ObjectId('6887d812645b7515e840298b'), ObjectId('6887d812645b7515e840298c')], acknowledged=True)"
|
|
]
|
|
},
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"mongo_db.database['notification_queue'].insert_many(notifications)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.13"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|