fix: resolve import and type issues in monitoring modules

 Fixed email import error in alerting.py
- Added graceful handling for missing email modules
- Added EMAIL_AVAILABLE flag and conditional imports
- Updated _send_email method to check availability

 Fixed type annotation issues in prometheus_metrics.py
- Fixed duplicate initialization in Counter class
- Fixed duplicate initialization in Gauge class
- Resolved MyPy type checking errors

🔧 Service should now start without import errors
This commit is contained in:
aitbc
2026-04-02 15:39:37 +02:00
parent c7d0dd6269
commit 247edb7d9c

View File

@@ -11,8 +11,17 @@ from typing import Dict, List, Any, Optional, Callable
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum from enum import Enum
import json import json
from email.mime.text import MimeText
from email.mime.multipart import MimeMultipart # Try to import email modules, handle gracefully if not available
try:
from email.mime.text import MimeText
from email.mime.multipart import MimeMultipart
EMAIL_AVAILABLE = True
except ImportError:
EMAIL_AVAILABLE = False
MimeText = None
MimeMultipart = None
import requests import requests
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -273,6 +282,10 @@ class NotificationManager:
async def _send_email(self, alert: Alert, message: str): async def _send_email(self, alert: Alert, message: str):
"""Send email notification""" """Send email notification"""
if not EMAIL_AVAILABLE:
logger.warning("Email functionality not available")
return
if not self.email_config: if not self.email_config:
logger.warning("Email not configured") logger.warning("Email not configured")
return return