fix: incohérence UA count et note source pays
- analysis.py: suppression du LIMIT 10 dans la requête user-agents → limitée à 500 (cohérent avec la page /detections/ip/<ip> qui montre 278) → total_count calculé via requête séparée pour des pourcentages corrects - CountryAnalysis.tsx: ajout d'un InfoTip ⓘ sur 'PAYS DE L'IP' expliquant que la source est le GeoIP du pipeline d'ingestion (ClickHouse) et peut différer des APIs de réputation externes pour les IPs anycast/CDN/cloud Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@ -373,10 +373,19 @@ async def analyze_user_agents(ip: str):
|
|||||||
AND time >= now() - INTERVAL 24 HOUR
|
AND time >= now() - INTERVAL 24 HOUR
|
||||||
GROUP BY ua
|
GROUP BY ua
|
||||||
ORDER BY count DESC
|
ORDER BY count DESC
|
||||||
LIMIT 10
|
LIMIT 500
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Total réel des requêtes (pour les pourcentages corrects)
|
||||||
|
ip_total_query = """
|
||||||
|
SELECT count()
|
||||||
|
FROM mabase_prod.http_logs
|
||||||
|
WHERE src_ip = %(ip)s
|
||||||
|
AND time >= now() - INTERVAL 24 HOUR
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ip_ua_result = db.query(ip_ua_query, {"ip": ip})
|
ip_ua_result = db.query(ip_ua_query, {"ip": ip})
|
||||||
|
ip_total_result = db.query(ip_total_query, {"ip": ip})
|
||||||
|
|
||||||
# Classification des UAs
|
# Classification des UAs
|
||||||
def classify_ua(ua: str) -> str:
|
def classify_ua(ua: str) -> str:
|
||||||
@ -389,8 +398,10 @@ async def analyze_user_agents(ip: str):
|
|||||||
return 'script'
|
return 'script'
|
||||||
return 'normal'
|
return 'normal'
|
||||||
|
|
||||||
# Calculer le total
|
# Total réel de toutes les requêtes (pour des pourcentages corrects même avec LIMIT)
|
||||||
total_count = sum(row[1] for row in ip_ua_result.result_rows)
|
total_count = ip_total_result.result_rows[0][0] if ip_total_result.result_rows else 0
|
||||||
|
if total_count == 0:
|
||||||
|
total_count = sum(row[1] for row in ip_ua_result.result_rows)
|
||||||
|
|
||||||
ip_user_agents = [
|
ip_user_agents = [
|
||||||
UserAgentData(
|
UserAgentData(
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { InfoTip } from '../ui/Tooltip';
|
||||||
|
|
||||||
interface CountryData {
|
interface CountryData {
|
||||||
code: string;
|
code: string;
|
||||||
@ -84,6 +85,15 @@ export function CountryAnalysis({ ip, asn }: CountryAnalysisProps) {
|
|||||||
<div className="bg-background-secondary rounded-lg p-6">
|
<div className="bg-background-secondary rounded-lg p-6">
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between mb-4">
|
||||||
<h3 className="text-lg font-medium text-text-primary">2. PAYS DE L'IP</h3>
|
<h3 className="text-lg font-medium text-text-primary">2. PAYS DE L'IP</h3>
|
||||||
|
<InfoTip content={
|
||||||
|
'Source : logs de détection internes (ClickHouse).\n' +
|
||||||
|
'Le pays est enregistré au moment de l\'ingestion des logs,\n' +
|
||||||
|
'via la base GeoIP du pipeline d\'enrichissement.\n\n' +
|
||||||
|
'Peut différer des sources de réputation externes\n' +
|
||||||
|
'(ip-api.com, ipinfo.io) pour les IPs anycast/CDN\n' +
|
||||||
|
'et les grands fournisseurs cloud (Microsoft, Google,\n' +
|
||||||
|
'Amazon) dont les plages IP sont routées vers plusieurs pays.'
|
||||||
|
} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Pays de l'IP */}
|
{/* Pays de l'IP */}
|
||||||
|
|||||||
Reference in New Issue
Block a user