fix(snmp): ARP表缺少发现时间字段,在get_arp_table返回值中添加last_seen和discovered_at

This commit is contained in:
Your Name
2026-07-18 09:50:20 +08:00
parent 1e1e5957e8
commit bd68abee93
8 changed files with 4 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -2
View File
@@ -221,18 +221,20 @@ class SNMPService:
arp_data[ip_address]['if_index'] = if_index arp_data[ip_address]['if_index'] = if_index
# 转换为列表 # 转换为列表
now = datetime.utcnow()
for ip, data in arp_data.items(): for ip, data in arp_data.items():
if 'mac_address' in data: if 'mac_address' in data:
entry = { entry = {
'ip_address': ip, 'ip_address': ip,
'mac_address': data.get('mac_address'), 'mac_address': data.get('mac_address'),
'interface': str(data.get('if_index', '')), 'interface': str(data.get('if_index', '')),
'device_id': device.id 'device_id': device.id,
'last_seen': now.isoformat(),
'discovered_at': now.isoformat()
} }
arp_entries.append(entry) arp_entries.append(entry)
# 保存到数据库 # 保存到数据库
now = datetime.utcnow()
for entry_data in arp_entries: for entry_data in arp_entries:
# 查找是否已存在 # 查找是否已存在
existing = db.query(ARPEntry).filter( existing = db.query(ARPEntry).filter(