Updated precog for regex drive ticket deduplication
This commit is contained in:
@ -59,17 +59,31 @@ $data = json_decode($rawInput, true);
|
|||||||
|
|
||||||
// Generate hash from stable components
|
// Generate hash from stable components
|
||||||
function generateTicketHash($data) {
|
function generateTicketHash($data) {
|
||||||
$stableComponents = [
|
// Extract device name if present (matches /dev/sdX pattern)
|
||||||
'title' => $data['title'],
|
preg_match('/\/dev\/sd[a-z]/', $data['title'], $deviceMatches);
|
||||||
// Extract metadata tags from title
|
$isDriveTicket = !empty($deviceMatches);
|
||||||
'tags' => array_filter(
|
|
||||||
explode(']', str_replace(['[', ']'], '', $data['title'])),
|
|
||||||
'strlen'
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
// Sort components for consistent hashing
|
// Extract hostname from title [hostname][tags]...
|
||||||
sort($stableComponents['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));
|
return hash('sha256', json_encode($stableComponents, JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user