Labels
';
if (!empty($groupLabels)) {
$labelsContent .= '
Group Labels
';
}
if (!empty($commonLabels)) {
$labelsContent .= '
Common Labels
';
}
$labelsContent .= '
';
}
// Build common annotations section
$annotationsContent = '';
if (!empty($commonAnnotations)) {
$annotationsContent .= 'Alerts
';
foreach ($alerts as $index => $alert) {
$alertStatus = $alert['status'] ?? 'unknown';
$alertLabels = $alert['labels'] ?? [];
$alertAnnotations = $alert['annotations'] ?? [];
$startsAt = $alert['startsAt'] ?? null;
$endsAt = $alert['endsAt'] ?? null;
$generatorURL = $alert['generatorURL'] ?? null;
$fingerprint = $alert['fingerprint'] ?? null;
$alertStatusSafe = htmlspecialchars($alertStatus, ENT_QUOTES, 'UTF-8');
$alertNumber = $index + 1;
// Choose alert icon
$alertIcon = '🔔';
$alertColor = '#666666';
if ($alertStatus === 'firing') {
$alertIcon = '🔥';
$alertColor = '#dc3545';
} elseif ($alertStatus === 'resolved') {
$alertIcon = '✅';
$alertColor = '#28a745';
}
$alertsContent .= <<
$alertIcon Alert $alertNumber - $alertStatusSafe
Labels
Annotations
';
}
$alertsContent .= '';
}
$emailTitle = "$statusIcon Grafana Alert: $statusSafe";
$emailStamp = "$dateSafe";
$body = <<