diff --git a/create_ticket_api.php b/create_ticket_api.php index 2e7bc87..c8c009b 100644 --- a/create_ticket_api.php +++ b/create_ticket_api.php @@ -84,22 +84,32 @@ $data = json_decode($rawInput, true); // Generate hash from stable components function generateTicketHash($data) { - // Extract device name if present (matches /dev/sdX pattern) - preg_match('/\/dev\/sd[a-z]/', $data['title'], $deviceMatches); + // Extract device name if present (matches /dev/sdX, /dev/nvmeXnY patterns) + preg_match('/\/dev\/(sd[a-z]|nvme\d+n\d+)/', $data['title'], $deviceMatches); $isDriveTicket = !empty($deviceMatches); - + // Extract hostname from title [hostname][tags]... preg_match('/\[([\w\d-]+)\]/', $data['title'], $hostMatches); $hostname = $hostMatches[1] ?? ''; - // Extract SMART attribute types without their values - preg_match_all('/Warning ([^:]+)/', $data['title'], $smartMatches); - $smartAttributes = $smartMatches[1] ?? []; + // Detect issue category (not specific attribute values) + $issueCategory = ''; + if (stripos($data['title'], 'SMART issues') !== false) { + $issueCategory = 'smart'; + } elseif (stripos($data['title'], 'LXC') !== false || stripos($data['title'], 'storage usage') !== false) { + $issueCategory = 'storage'; + } elseif (stripos($data['title'], 'memory') !== false) { + $issueCategory = 'memory'; + } elseif (stripos($data['title'], 'cpu') !== false) { + $issueCategory = 'cpu'; + } elseif (stripos($data['title'], 'network') !== false) { + $issueCategory = 'network'; + } // Build stable components with only static data $stableComponents = [ 'hostname' => $hostname, - 'smart_attributes' => $smartAttributes, + 'issue_category' => $issueCategory, // Generic category, not specific errors 'environment_tags' => array_filter( explode('][', $data['title']), fn($tag) => in_array($tag, ['production', 'development', 'staging', 'single-node']) @@ -112,9 +122,8 @@ function generateTicketHash($data) { } // Sort arrays for consistent hashing - sort($stableComponents['smart_attributes']); sort($stableComponents['environment_tags']); - + return hash('sha256', json_encode($stableComponents, JSON_UNESCAPED_SLASHES)); }