fix(snmp): 修复 SNMP 采集 ARP 表时只补 MAC 不补厂商的问题
问题原因: - snmp_service.py get_arp_table 第267行条件为 if ip_addr and not ip_addr.mac_address: - 只给原本没有 MAC 的 IP 设置 MAC + 厂商 - 如果 IP 已有 MAC(来自 Ping/ARP 扫描)但没有 vendor, 则永远不会补全厂商 解决方案: - 拆分为两个 if: 1. if not ip_addr.mac_address: 写入 MAC 2. if not ip_addr.vendor and ip_addr.mac_address: 补全厂商 - 确保已有 MAC 但无厂商的 IP 也能被补全 - 已有 backfill_vendor.py 脚本可批量回填历史数据
This commit is contained in:
@@ -258,16 +258,18 @@ class SNMPService:
|
||||
|
||||
db.commit()
|
||||
|
||||
# 更新 IP 资产台账中的 MAC 地址
|
||||
# 更新 IP 资产台账中的 MAC 地址和厂商信息
|
||||
for entry in arp_entries:
|
||||
from app.models.network import IPAddress as IPAddressModel
|
||||
ip_addr = db.query(IPAddressModel).filter(
|
||||
IPAddressModel.ip_address == entry['ip_address']
|
||||
).first()
|
||||
if ip_addr and not ip_addr.mac_address:
|
||||
ip_addr.mac_address = entry['mac_address']
|
||||
# 识别厂商
|
||||
ip_addr.vendor = EnhancedScanService.get_mac_vendor(entry['mac_address'])
|
||||
if ip_addr:
|
||||
if not ip_addr.mac_address:
|
||||
ip_addr.mac_address = entry['mac_address']
|
||||
# 始终尝试补全厂商(有 MAC 但没厂商时也需要)
|
||||
if not ip_addr.vendor and ip_addr.mac_address:
|
||||
ip_addr.vendor = EnhancedScanService.get_mac_vendor(ip_addr.mac_address)
|
||||
|
||||
db.commit()
|
||||
device.last_successful_poll = now
|
||||
|
||||
Reference in New Issue
Block a user