Add emoji notification fields
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
func TestNotificationMessageIncludesBackupStatistics(t *testing.T) {
|
||||
started := time.Date(2026, 6, 14, 12, 0, 0, 0, time.UTC)
|
||||
finished := started.Add(2*time.Minute + 8*time.Second)
|
||||
run := model.Run{TaskType: "backup", Status: "success", StartedAt: &started, FinishedAt: &finished, SnapshotID: "abc123", BytesAdded: 1536, FilesNew: 7, FilesChanged: 2, BytesProcessed: 5 * 1024 * 1024, FilesProcessed: 120}
|
||||
run := model.Run{TaskType: "backup", Status: "success", StartedAt: &started, FinishedAt: &finished, SnapshotID: "abc123456789abcdef", BytesAdded: 1536, FilesNew: 7, FilesChanged: 2, BytesProcessed: 5 * 1024 * 1024, FilesProcessed: 120}
|
||||
message := notificationMessage("Freigaben", "LV-426", run, finished)
|
||||
for _, expected := range []string{"📊 URBM-Zusammenfassung", "Status: Erfolgreich", "Job: Freigaben", "Repository: LV-426", "Dauer: 2 Min. 8 Sek.", "Snapshot: abc123", "Verarbeitete Daten: 5.0 MiB", "Verarbeitete Dateien: 120", "Neu gespeichert: 1.5 KiB", "Neue Dateien: 7", "Geänderte Dateien: 2"} {
|
||||
for _, expected := range []string{"📊 Backup-Zusammenfassung", "📦 Repository: LV-426", "🗂️ Job: Freigaben", "📸 Snapshot: abc123456789", "⏱️ Dauer: 2 Min. 8 Sek.", "📂 Dateien: 120 verarbeitet", "💾 Verarbeitet: 5.0 MiB", "➕ Neu: 7 Dateien", "✏️ Geändert: 2 Dateien", "📤 Neu gespeichert: 1.5 KiB", "🔐 Ziel: Restic Repository", "✅ Status: Erfolgreich"} {
|
||||
if !strings.Contains(message, expected) {
|
||||
t.Errorf("message %q does not contain %q", message, expected)
|
||||
}
|
||||
|
||||
+52
-16
@@ -795,12 +795,15 @@ func notificationMessage(name, repository string, run model.Run, now time.Time)
|
||||
if status == "" {
|
||||
status = run.Status
|
||||
}
|
||||
lines := []string{"📊 URBM-Zusammenfassung", "", "Status: " + status}
|
||||
if name != "" {
|
||||
lines = append(lines, "Job: "+name)
|
||||
}
|
||||
lines := []string{"📊 Backup-Zusammenfassung", ""}
|
||||
if repository != "" {
|
||||
lines = append(lines, "Repository: "+repository)
|
||||
lines = append(lines, "📦 Repository: "+repository)
|
||||
}
|
||||
if name != "" {
|
||||
lines = append(lines, "🗂️ Job: "+name)
|
||||
}
|
||||
if run.TaskType == "backup" && run.SnapshotID != "" {
|
||||
lines = append(lines, "📸 Snapshot: "+shortID(run.SnapshotID))
|
||||
}
|
||||
if run.StartedAt != nil {
|
||||
finished := now
|
||||
@@ -808,33 +811,66 @@ func notificationMessage(name, repository string, run model.Run, now time.Time)
|
||||
finished = *run.FinishedAt
|
||||
}
|
||||
if duration := finished.Sub(*run.StartedAt); duration >= 0 {
|
||||
lines = append(lines, "Dauer: "+formatDuration(duration))
|
||||
lines = append(lines, "", "⏱️ Dauer: "+formatDuration(duration))
|
||||
}
|
||||
}
|
||||
if (run.TaskType == "backup" || run.TaskType == "rsync") && (run.Status == "success" || run.Status == "warning") {
|
||||
if run.TaskType == "backup" && run.SnapshotID != "" {
|
||||
lines = append(lines, "Snapshot: "+run.SnapshotID)
|
||||
}
|
||||
lines = append(lines,
|
||||
"Verarbeitete Daten: "+formatBytes(run.BytesProcessed),
|
||||
fmt.Sprintf("Verarbeitete Dateien: %d", run.FilesProcessed),
|
||||
fmt.Sprintf("📂 Dateien: %d verarbeitet", run.FilesProcessed),
|
||||
"💾 Verarbeitet: "+formatBytes(run.BytesProcessed),
|
||||
)
|
||||
if run.TaskType == "backup" {
|
||||
lines = append(lines,
|
||||
"Neu gespeichert: "+formatBytes(run.BytesAdded),
|
||||
fmt.Sprintf("Neue Dateien: %d", run.FilesNew),
|
||||
fmt.Sprintf("Geänderte Dateien: %d", run.FilesChanged),
|
||||
fmt.Sprintf("➕ Neu: %d Dateien", run.FilesNew),
|
||||
fmt.Sprintf("✏️ Geändert: %d Dateien", run.FilesChanged),
|
||||
"📤 Neu gespeichert: "+formatBytes(run.BytesAdded),
|
||||
)
|
||||
} else {
|
||||
lines = append(lines, "Kopierte Daten: "+formatBytes(run.BytesAdded))
|
||||
lines = append(lines, "📤 Kopiert: "+formatBytes(run.BytesAdded))
|
||||
}
|
||||
}
|
||||
lines = append(lines, "", "🔐 Ziel: "+notificationTargetLabel(run.TaskType), statusIcon(run.Status)+" Status: "+status)
|
||||
if run.Message != "" && run.Message != "backup completed" && run.Message != "rsync completed" {
|
||||
lines = append(lines, "Details: "+run.Message)
|
||||
lines = append(lines, "⚠️ Details: "+run.Message)
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func statusIcon(status string) string {
|
||||
switch status {
|
||||
case "success":
|
||||
return "✅"
|
||||
case "warning":
|
||||
return "⚠️"
|
||||
case "failed":
|
||||
return "❌"
|
||||
default:
|
||||
return "ℹ️"
|
||||
}
|
||||
}
|
||||
|
||||
func notificationTargetLabel(taskType string) string {
|
||||
switch taskType {
|
||||
case "backup":
|
||||
return "Restic Repository"
|
||||
case "rsync":
|
||||
return "Rsync Ziel"
|
||||
case "restore":
|
||||
return "Restore Ziel"
|
||||
case "check", "prune":
|
||||
return "Restic Repository"
|
||||
default:
|
||||
return "URBM"
|
||||
}
|
||||
}
|
||||
|
||||
func shortID(value string) string {
|
||||
if len(value) <= 12 {
|
||||
return value
|
||||
}
|
||||
return value[:12]
|
||||
}
|
||||
|
||||
func formatBytes(value int64) string {
|
||||
const unit = int64(1024)
|
||||
if value < unit {
|
||||
|
||||
Reference in New Issue
Block a user