diff --git a/create_ticket_api.php b/create_ticket_api.php index ef44380..348ffd9 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -59,17 +59,31 @@ $data = json_decode($rawInput, true); // Generate hash from stable components function generateTicketHash($data) { - $stableComponents = [ - 'title' => $data['title'], - // Extract metadata tags from title - 'tags' => array_filter( - explode(']', str_replace(['[', ']'], '', $data['title'])), - 'strlen' - ) - ]; + // Extract device name if present (matches /dev/sdX pattern) + preg_match('/\/dev\/sd[a-z]/', $data['title'], $deviceMatches); + $isDriveTicket = !empty($deviceMatches); - // Sort components for consistent hashing - sort($stableComponents['tags']); + // Extract hostname from title [hostname][tags]... + preg_match('/\[([\w\d-]+)\]/', $data['title'], $hostMatches); + $hostname = $hostMatches[1] ?? ''; + + // Extract error types from title + preg_match_all('/Critical ([^:,]+)/', $data['title'], $errorMatches); + $errorTypes = $errorMatches[1] ?? []; + + $stableComponents = [ + 'hostname' => $hostname, + 'error_types' => $errorTypes, + 'title_base' => preg_replace('/\[\w+\]/', '', $data['title']), // Strip tags for base title + ]; + + // Only include device info for drive-specific tickets + if ($isDriveTicket) { + $stableComponents['device'] = $deviceMatches[0]; + } + + // Sort arrays for consistent hashing + sort($stableComponents['error_types']); return hash('sha256', json_encode($stableComponents, JSON_UNESCAPED_SLASHES)); }