Fix hwmonDaemon hash collisions and automated comment formatting

- source_type (auto vs manual) added to dedup hash so automated
  tickets never collide with manually created ones
- OSD-specific subtype (osd_down_N) so each OSD gets its own ticket
- Description refreshed on every automated update (current sensor data)
- Comments on worsening condition only fire on meaningful changes
- ASCII art descriptions wrapped in fenced code blocks in comments
- Reopen comment also uses fenced code block

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-16 08:09:12 -04:00
parent 56007f7479
commit dad7c24bff
+29 -7
View File
@@ -152,15 +152,24 @@ function generateTicketHash($data) {
$issueSubtype = 'clock_skew'; $issueSubtype = 'clock_skew';
} elseif (stripos($title, 'cluster usage') !== false) { } elseif (stripos($title, 'cluster usage') !== false) {
$issueSubtype = 'usage'; $issueSubtype = 'usage';
} elseif (stripos($title, 'OSD down') !== false) { } elseif (stripos($title, 'OSD down') !== false || preg_match('/osd\.\d+\s+is\s+DOWN/i', $title)) {
// Include the specific OSD ID so each individual OSD gets its own ticket
if (preg_match('/osd\.(\d+)/i', $title, $osdMatch)) {
$issueSubtype = 'osd_down_' . $osdMatch[1];
} else {
$issueSubtype = 'osd_down'; $issueSubtype = 'osd_down';
}
} elseif (stripos($title, 'HEALTH_ERR') !== false) { } elseif (stripos($title, 'HEALTH_ERR') !== false) {
$issueSubtype = 'health_err'; $issueSubtype = 'health_err';
} }
} }
// Include source type so automated tickets never collide with manual ones
$sourceType = stripos($title, '[auto]') !== false ? 'auto' : 'manual';
// Build stable components // Build stable components
$stableComponents = [ $stableComponents = [
'source_type' => $sourceType,
'issue_category' => $issueCategory, 'issue_category' => $issueCategory,
'issue_subtype' => $issueSubtype, 'issue_subtype' => $issueSubtype,
'environment_tags' => array_values(array_filter( 'environment_tags' => array_values(array_filter(
@@ -212,8 +221,8 @@ if ($existing) {
$newPriority = (int)$priority; $newPriority = (int)$priority;
if ($existingStatus !== 'Closed') { if ($existingStatus !== 'Closed') {
// Ticket is still active — update title and escalate priority if the new // Ticket is still active — update title, escalate priority, and refresh
// report is more severe (lower number = higher severity). // description with latest sensor data.
$changes = []; $changes = [];
$updateSql = "UPDATE tickets SET updated_at = NOW(), updated_by = ?"; $updateSql = "UPDATE tickets SET updated_at = NOW(), updated_by = ?";
$bindTypes = "i"; $bindTypes = "i";
@@ -233,6 +242,14 @@ if ($existing) {
$changes['priority'] = ['from' => $existingPriority, 'to' => $newPriority]; $changes['priority'] = ['from' => $existingPriority, 'to' => $newPriority];
} }
// Always refresh the description so the ticket body shows current sensor data
if (!empty($description)) {
$updateSql .= ", description = ?";
$bindTypes .= "s";
$bindVals[] = $description;
$changes['description_refreshed'] = true;
}
if (!empty($changes)) { if (!empty($changes)) {
$updateSql .= " WHERE ticket_id = ?"; $updateSql .= " WHERE ticket_id = ?";
$bindTypes .= "s"; $bindTypes .= "s";
@@ -243,7 +260,9 @@ if ($existing) {
$updStmt->execute(); $updStmt->execute();
$updStmt->close(); $updStmt->close();
// Comment summarising what changed // Only add a comment when something meaningful changed (not just a description refresh)
$meaningfulChanges = array_diff_key($changes, ['description_refreshed' => true]);
if (!empty($meaningfulChanges)) {
$changeLines = []; $changeLines = [];
if (isset($changes['title'])) { if (isset($changes['title'])) {
$changeLines[] = "- **Title updated** to reflect current issue"; $changeLines[] = "- **Title updated** to reflect current issue";
@@ -251,17 +270,20 @@ if ($existing) {
if (isset($changes['priority'])) { if (isset($changes['priority'])) {
$changeLines[] = "- **Priority escalated** from P{$changes['priority']['from']} to P{$changes['priority']['to']}"; $changeLines[] = "- **Priority escalated** from P{$changes['priority']['from']} to P{$changes['priority']['to']}";
} }
// Wrap description in a fenced code block so ASCII art / box-drawing
// characters render correctly instead of collapsing into a paragraph blob
$commentText = "**hwmonDaemon reported a worsened condition — ticket updated automatically.**\n\n" . $commentText = "**hwmonDaemon reported a worsened condition — ticket updated automatically.**\n\n" .
implode("\n", $changeLines) . "\n\nLatest report:\n\n" . $description; implode("\n", $changeLines) . "\n\nLatest report:\n\n```\n" . $description . "\n```";
$commentStmt = $conn->prepare( $commentStmt = $conn->prepare(
"INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, 'hwmonDaemon', ?, 1)" "INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, 'hwmonDaemon', ?, 1)"
); );
$commentStmt->bind_param("sis", $existingId, $userId, $commentText); $commentStmt->bind_param("sis", $existingId, $userId, $commentText);
$commentStmt->execute(); $commentStmt->execute();
$commentStmt->close(); $commentStmt->close();
}
$auditLog->log($userId, 'update', 'ticket', $existingId, array_merge( $auditLog->log($userId, 'update', 'ticket', $existingId, array_merge(
$changes, array_diff_key($changes, ['description_refreshed' => true]),
['reason' => 'auto-updated by hwmonDaemon (condition worsened)'] ['reason' => 'auto-updated by hwmonDaemon (condition worsened)']
)); ));
@@ -299,7 +321,7 @@ if ($existing) {
$reopenStmt->close(); $reopenStmt->close();
$commentText = "**Issue recurred — ticket reopened automatically.**\n\n" . $commentText = "**Issue recurred — ticket reopened automatically.**\n\n" .
"New report received from hwmonDaemon:\n\n" . $description; "New report received from hwmonDaemon:\n\n```\n" . $description . "\n```";
$commentStmt = $conn->prepare( $commentStmt = $conn->prepare(
"INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, 'hwmonDaemon', ?, 1)" "INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, 'hwmonDaemon', ?, 1)"
); );