Add test email generator for testing and development
Added feature to generate test emails in inbox for testing purposes: - Simulates backup notifications from Veeam, Synology, and NAKIVO - Configurable count (1-50 emails) - Random job names, statuses, and timestamps - Emails are parser-compatible for testing inbox approval workflow - Useful for testing orphaned jobs cleanup and other maintenance ops - Admin-only feature in Settings → Maintenance Templates include: - Veeam: Various job statuses with detailed backup info - Synology: Backup task notifications - NAKIVO: Job completion reports Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
08437aff7f
commit
96092517b4
@ -298,6 +298,160 @@ def settings_jobs_delete_orphaned():
|
|||||||
return redirect(url_for("main.settings", section="maintenance"))
|
return redirect(url_for("main.settings", section="maintenance"))
|
||||||
|
|
||||||
|
|
||||||
|
@main_bp.route("/settings/test-emails/generate", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
@roles_required("admin")
|
||||||
|
def settings_generate_test_emails():
|
||||||
|
"""Generate test emails in inbox for testing parsers and orphaned jobs cleanup."""
|
||||||
|
try:
|
||||||
|
count_str = request.form.get("count", "5")
|
||||||
|
try:
|
||||||
|
count = int(count_str)
|
||||||
|
count = max(1, min(count, 50)) # Limit between 1 and 50
|
||||||
|
except Exception:
|
||||||
|
count = 5
|
||||||
|
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import random
|
||||||
|
|
||||||
|
# Template configurations for different backup software
|
||||||
|
templates = [
|
||||||
|
{
|
||||||
|
"software": "Veeam",
|
||||||
|
"sender": "veeam@test.local",
|
||||||
|
"subject_template": "Backup job '{job}' completed {status}",
|
||||||
|
"body_template": """Job name: {job}
|
||||||
|
Status: {status}
|
||||||
|
Start time: {start_time}
|
||||||
|
End time: {end_time}
|
||||||
|
Total size: {size} GB
|
||||||
|
Objects processed: {objects}
|
||||||
|
|
||||||
|
{message}
|
||||||
|
""",
|
||||||
|
"statuses": ["successfully", "with warnings", "failed"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"software": "Synology",
|
||||||
|
"sender": "synology@test.local",
|
||||||
|
"subject_template": "[Synology] Backup Task {job} {status}",
|
||||||
|
"body_template": """Dear Administrator,
|
||||||
|
|
||||||
|
Backup task '{job}' has {status}.
|
||||||
|
|
||||||
|
Task: {job}
|
||||||
|
Status: {status}
|
||||||
|
Start: {start_time}
|
||||||
|
Finish: {end_time}
|
||||||
|
Data transferred: {size} GB
|
||||||
|
|
||||||
|
{message}
|
||||||
|
""",
|
||||||
|
"statuses": ["completed successfully", "completed with warnings", "failed"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"software": "NAKIVO",
|
||||||
|
"sender": "nakivo@test.local",
|
||||||
|
"subject_template": "Job '{job}' finished {status}",
|
||||||
|
"body_template": """NAKIVO Backup & Replication
|
||||||
|
|
||||||
|
Job: {job}
|
||||||
|
Status: {status}
|
||||||
|
Started: {start_time}
|
||||||
|
Completed: {end_time}
|
||||||
|
Size: {size} GB
|
||||||
|
|
||||||
|
{message}
|
||||||
|
""",
|
||||||
|
"statuses": ["successfully", "with warnings", "with errors"],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
job_names = [
|
||||||
|
"Daily VM Backup",
|
||||||
|
"Weekly File Server",
|
||||||
|
"SQL Database Backup",
|
||||||
|
"Exchange Mailbox",
|
||||||
|
"Critical Servers",
|
||||||
|
"Development Environment",
|
||||||
|
"Production Backup",
|
||||||
|
"Archive Job",
|
||||||
|
]
|
||||||
|
|
||||||
|
messages = {
|
||||||
|
"successfully": "All backup operations completed without issues.",
|
||||||
|
"with warnings": "Backup completed but some files were skipped.",
|
||||||
|
"failed": "Backup failed. Please check the logs for details.",
|
||||||
|
"with errors": "Some backup objects failed to process.",
|
||||||
|
}
|
||||||
|
|
||||||
|
created_count = 0
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
for i in range(count):
|
||||||
|
template = random.choice(templates)
|
||||||
|
job_name = random.choice(job_names)
|
||||||
|
status = random.choice(template["statuses"])
|
||||||
|
|
||||||
|
start_time = now - timedelta(hours=random.randint(1, 24), minutes=random.randint(0, 59))
|
||||||
|
end_time = start_time + timedelta(minutes=random.randint(5, 120))
|
||||||
|
size = random.randint(10, 500)
|
||||||
|
objects_count = random.randint(5, 50)
|
||||||
|
|
||||||
|
# Find message for status
|
||||||
|
message = messages.get(status, messages.get("successfully"))
|
||||||
|
for key in messages:
|
||||||
|
if key in status:
|
||||||
|
message = messages[key]
|
||||||
|
break
|
||||||
|
|
||||||
|
subject = template["subject_template"].format(
|
||||||
|
job=job_name,
|
||||||
|
status=status,
|
||||||
|
)
|
||||||
|
|
||||||
|
body = template["body_template"].format(
|
||||||
|
job=job_name,
|
||||||
|
status=status,
|
||||||
|
start_time=start_time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
end_time=end_time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
size=size,
|
||||||
|
objects=objects_count,
|
||||||
|
message=message,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create mail message in inbox
|
||||||
|
mail = MailMessage(
|
||||||
|
sender=template["sender"],
|
||||||
|
subject=subject,
|
||||||
|
body=body,
|
||||||
|
text_body=body,
|
||||||
|
html_body=f"<pre>{body}</pre>",
|
||||||
|
received_at=start_time,
|
||||||
|
location="inbox",
|
||||||
|
job_id=None,
|
||||||
|
)
|
||||||
|
db.session.add(mail)
|
||||||
|
created_count += 1
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
flash(f"Generated {created_count} test email(s) in inbox.", "success")
|
||||||
|
|
||||||
|
_log_admin_event(
|
||||||
|
event_type="maintenance_generate_test_emails",
|
||||||
|
message=f"Generated {created_count} test emails",
|
||||||
|
details=json.dumps({"count": created_count}),
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
db.session.rollback()
|
||||||
|
print(f"[settings-test] Failed to generate test emails: {exc}")
|
||||||
|
flash("Failed to generate test emails.", "danger")
|
||||||
|
|
||||||
|
return redirect(url_for("main.settings", section="maintenance"))
|
||||||
|
|
||||||
|
|
||||||
@main_bp.route("/settings/objects/backfill", methods=["POST"])
|
@main_bp.route("/settings/objects/backfill", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@roles_required("admin")
|
@roles_required("admin")
|
||||||
|
|||||||
@ -559,6 +559,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-6">
|
||||||
|
<div class="card h-100 border-info">
|
||||||
|
<div class="card-header bg-info text-white">Generate test emails</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="mb-3">Generate test emails in the inbox for testing parsers and maintenance operations. Emails simulate Veeam, Synology, and NAKIVO backups.</p>
|
||||||
|
<form method="post" action="{{ url_for('main.settings_generate_test_emails') }}" class="row g-2 align-items-end">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="test_email_count" class="form-label">Number of emails</label>
|
||||||
|
<input type="number" class="form-control" id="test_email_count" name="count" value="5" min="1" max="50" />
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<button type="submit" class="btn btn-info text-white w-100">Generate test emails</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-12 col-lg-6">
|
<div class="col-12 col-lg-6">
|
||||||
<div class="card h-100 border-danger">
|
<div class="card h-100 border-danger">
|
||||||
<div class="card-header bg-danger text-white">Jobs maintenance</div>
|
<div class="card-header bg-danger text-white">Jobs maintenance</div>
|
||||||
|
|||||||
@ -7,6 +7,7 @@ This file documents all changes made to this project via Claude Code.
|
|||||||
### Added
|
### Added
|
||||||
- Added "Cleanup orphaned jobs" maintenance option in Settings → Maintenance to delete jobs without valid customer links and their associated emails/runs permanently from database (useful when customers are removed)
|
- Added "Cleanup orphaned jobs" maintenance option in Settings → Maintenance to delete jobs without valid customer links and their associated emails/runs permanently from database (useful when customers are removed)
|
||||||
- Added "Preview orphaned jobs" button to show detailed list of jobs to be deleted with run/email counts before confirming deletion (verification step for safety)
|
- Added "Preview orphaned jobs" button to show detailed list of jobs to be deleted with run/email counts before confirming deletion (verification step for safety)
|
||||||
|
- Added "Generate test emails" feature in Settings → Maintenance to create test emails in inbox that simulate Veeam, Synology, and NAKIVO backup notifications (useful for testing parsers, orphaned jobs cleanup, and other maintenance operations)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Removed customer name from Autotask ticket title to keep titles concise (format changed from "[Backupchecks] Customer - Job Name - Status" to "[Backupchecks] Job Name - Status")
|
- Removed customer name from Autotask ticket title to keep titles concise (format changed from "[Backupchecks] Customer - Job Name - Status" to "[Backupchecks] Job Name - Status")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user