diff --git a/create_ticket_api.php b/create_ticket_api.php index 8ae57af..ff7e080 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -158,15 +158,24 @@ function generateTicketHash($data) $issueSubtype = 'clock_skew'; } elseif (stripos($title, 'cluster usage') !== false) { $issueSubtype = 'usage'; - } elseif (stripos($title, 'OSD down') !== false) { - $issueSubtype = 'osd_down'; + } elseif (stripos($title, 'OSD down') !== false || preg_match('/OSD\s+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'; + } } elseif (stripos($title, 'HEALTH_ERR') !== false) { $issueSubtype = 'health_err'; } } + // Include source type so automated tickets never collide with manual ones + $sourceType = stripos($title, '[auto]') !== false ? 'auto' : 'manual'; + // Build stable components $stableComponents = [ + 'source_type' => $sourceType, 'issue_category' => $issueCategory, 'issue_subtype' => $issueSubtype, 'environment_tags' => array_values(array_filter( @@ -218,8 +227,9 @@ if ($existing) { $newPriority = (int)$priority; if ($existingStatus !== 'Closed') { - // Ticket is still active — update title and escalate priority if the new - // report is more severe (lower number = higher severity). + // Ticket is still active — update title, escalate priority, and refresh + // the description with the latest sensor data if the new report is more severe + // (lower priority number = higher severity). $changes = []; $updateSql = "UPDATE tickets SET updated_at = NOW(), updated_by = ?"; $bindTypes = "i"; @@ -239,6 +249,14 @@ if ($existing) { $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)) { $updateSql .= " WHERE ticket_id = ?"; $bindTypes .= "s"; @@ -249,22 +267,27 @@ if ($existing) { $updStmt->execute(); $updStmt->close(); - // Comment summarising what changed - $changeLines = []; - if (isset($changes['title'])) { - $changeLines[] = "- **Title updated** to reflect current issue"; + // 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 = []; + if (isset($changes['title'])) { + $changeLines[] = "- **Title updated** to reflect current issue"; + } + if (isset($changes['priority'])) { + $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" . + implode("\n", $changeLines) . "\n\nLatest report:\n\n```\n" . $description . "\n```"; + $commentStmt = $conn->prepare( + "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->execute(); + $commentStmt->close(); } - if (isset($changes['priority'])) { - $changeLines[] = "- **Priority escalated** from P{$changes['priority']['from']} to P{$changes['priority']['to']}"; - } - $commentText = "**hwmonDaemon reported a worsened condition — ticket updated automatically.**\n\n" . - implode("\n", $changeLines) . "\n\nLatest report:\n\n" . $description; - $commentStmt = $conn->prepare( - "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->execute(); - $commentStmt->close(); $auditLog->log($userId, 'update', 'ticket', $existingId, array_merge( $changes, @@ -305,7 +328,7 @@ if ($existing) { $reopenStmt->close(); $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( "INSERT INTO ticket_comments (ticket_id, user_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, 'hwmonDaemon', ?, 1)" );