Better deduplication

This commit is contained in:
2025-05-15 08:33:13 -04:00
parent d40d6c2844
commit 1fe7bc0f93
2 changed files with 61 additions and 15 deletions

View File

@ -67,14 +67,18 @@ function generateTicketHash($data) {
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] ?? [];
// Extract SMART attribute types without their values
preg_match_all('/Warning ([^:]+)/', $data['title'], $smartMatches);
$smartAttributes = $smartMatches[1] ?? [];
// Build stable components with only static data
$stableComponents = [
'hostname' => $hostname,
'error_types' => $errorTypes,
'title_base' => preg_replace('/\[\w+\]/', '', $data['title']), // Strip tags for base title
'smart_attributes' => $smartAttributes,
'environment_tags' => array_filter(
explode('][', $data['title']),
fn($tag) => in_array($tag, ['production', 'development', 'staging', 'single-node'])
)
];
// Only include device info for drive-specific tickets
@ -83,7 +87,8 @@ function generateTicketHash($data) {
}
// Sort arrays for consistent hashing
sort($stableComponents['error_types']);
sort($stableComponents['smart_attributes']);
sort($stableComponents['environment_tags']);
return hash('sha256', json_encode($stableComponents, JSON_UNESCAPED_SLASHES));
}