Add verbose logging to debug operator report email alerts
- Log when function is called with report details - Log SMTP config and recipients being used - Log before and after email send attempt - Change warning to error with full traceback for failures
This commit is contained in:
@@ -2942,12 +2942,18 @@ def _send_operator_report_alert(report, asset_id, hostname):
|
|||||||
from flask import url_for, request
|
from flask import url_for, request
|
||||||
from shopdb.utils.mailer import get_smtp_config, _normalize_recipients
|
from shopdb.utils.mailer import get_smtp_config, _normalize_recipients
|
||||||
|
|
||||||
|
current_app.logger.info('_send_operator_report_alert called for report %d, asset %d, hostname %s',
|
||||||
|
report.operatorreportid, asset_id, hostname)
|
||||||
|
|
||||||
# Check if we have recipients before doing expensive work
|
# Check if we have recipients before doing expensive work
|
||||||
config = get_smtp_config()
|
config = get_smtp_config()
|
||||||
|
current_app.logger.info('SMTP config: enabled=%s, host=%s, alert_recipients=%s',
|
||||||
|
config.get('enabled'), config.get('host'), config.get('alert_recipients'))
|
||||||
recipients = _normalize_recipients(config['alert_recipients'])
|
recipients = _normalize_recipients(config['alert_recipients'])
|
||||||
if not recipients:
|
if not recipients:
|
||||||
current_app.logger.debug('Skipping operator report alert: no alert recipients configured')
|
current_app.logger.warning('Skipping operator report alert: no alert recipients configured')
|
||||||
return
|
return
|
||||||
|
current_app.logger.info('Will send alert to %d recipient(s): %s', len(recipients), recipients)
|
||||||
|
|
||||||
asset = Asset.query.get(asset_id)
|
asset = Asset.query.get(asset_id)
|
||||||
if not asset:
|
if not asset:
|
||||||
@@ -3107,10 +3113,12 @@ def upload_operator_report():
|
|||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
|
||||||
# Send email alert to default alert recipients
|
# Send email alert to default alert recipients
|
||||||
|
current_app.logger.info('Operator report %d saved, attempting to send email alert', report.operatorreportid)
|
||||||
try:
|
try:
|
||||||
_send_operator_report_alert(report, asset_id, hostname)
|
_send_operator_report_alert(report, asset_id, hostname)
|
||||||
|
current_app.logger.info('Email alert function completed for report %d', report.operatorreportid)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning('Failed to send operator report alert email: %s', e)
|
current_app.logger.error('Failed to send operator report alert email for report %d: %s', report.operatorreportid, e, exc_info=True)
|
||||||
|
|
||||||
return success_response(report.to_dict(),
|
return success_response(report.to_dict(),
|
||||||
message='Operator report received', http_code=201)
|
message='Operator report received', http_code=201)
|
||||||
|
|||||||
Reference in New Issue
Block a user