Updated precog for regex drive ticket deduplication

This commit is contained in:
2025-03-03 18:23:44 -05:00
parent e52192469a
commit e563f1d791

View File

@ -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));
}