add jose
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,7 @@ from typing import Optional
|
||||
from app.core.database import get_db
|
||||
from app.core.security import get_current_user
|
||||
from app.services.alert_service import AlertService
|
||||
from app.schemas._tz_util import serialize_dt_fields, serialize_dt_list, to_business_iso
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/alerts",
|
||||
@@ -37,7 +38,7 @@ def get_alerts(
|
||||
total = query.count()
|
||||
items = query.order_by(Alert.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
return {"total": total, "items": items}
|
||||
return {"total": total, "items": serialize_dt_list(items)}
|
||||
|
||||
|
||||
@router.get("/{alert_id}", summary="获取告警详情")
|
||||
@@ -47,7 +48,7 @@ def get_alert(alert_id: int, db: Session = Depends(get_db)):
|
||||
alert = db.query(Alert).filter(Alert.id == alert_id).first()
|
||||
if not alert:
|
||||
raise HTTPException(status_code=404, detail="告警不存在")
|
||||
return alert
|
||||
return serialize_dt_fields(alert)
|
||||
|
||||
|
||||
@router.post("/{alert_id}/acknowledge", summary="确认告警")
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.core.security import get_current_user, require_permission
|
||||
from app.models.auth import User
|
||||
from app.models.audit import AuditAction, AuditResource
|
||||
from app.services.audit_service import AuditService
|
||||
from app.schemas._tz_util import to_business_iso
|
||||
|
||||
router = APIRouter(prefix="/audit", tags=["审计日志"])
|
||||
|
||||
@@ -66,7 +67,7 @@ def get_audit_logs(
|
||||
"request_path": item.request_path,
|
||||
"success": bool(item.success),
|
||||
"error_message": item.error_message,
|
||||
"created_at": item.created_at
|
||||
"created_at": to_business_iso(item.created_at)
|
||||
})
|
||||
|
||||
return {"total": total, "items": result_items}
|
||||
|
||||
+17
-30
@@ -7,6 +7,7 @@ from app.core.security import get_current_user
|
||||
from app.models.auth import User
|
||||
from app.services.snmp_service import SNMPService
|
||||
from app.services.audit_service import AuditService, AuditAction
|
||||
from app.schemas._tz_util import serialize_dt_fields, serialize_dt_list
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/snmp",
|
||||
@@ -34,7 +35,7 @@ def get_snmp_credentials(
|
||||
query = db.query(SNMPCredential)
|
||||
total = query.count()
|
||||
items = query.order_by(SNMPCredential.id.desc()).offset(skip).limit(limit).all()
|
||||
return {"total": total, "items": items}
|
||||
return {"total": total, "items": serialize_dt_list(items)}
|
||||
|
||||
|
||||
@router.get("/credentials/{credential_id}", summary="获取凭据详情")
|
||||
@@ -43,7 +44,7 @@ def get_snmp_credential(credential_id: int, db: Session = Depends(get_db)):
|
||||
credential = db.query(SNMPCredential).filter(SNMPCredential.id == credential_id).first()
|
||||
if not credential:
|
||||
raise HTTPException(status_code=404, detail="凭据不存在")
|
||||
return credential
|
||||
return serialize_dt_fields(credential)
|
||||
|
||||
|
||||
@router.post("/credentials", summary="创建 SNMP 凭据")
|
||||
@@ -100,7 +101,7 @@ def create_snmp_credential(
|
||||
user_agent=u,
|
||||
detail={"version": credential.version, "name": credential.name},
|
||||
)
|
||||
return credential
|
||||
return serialize_dt_fields(credential)
|
||||
|
||||
|
||||
@router.put("/credentials/{credential_id}", summary="更新 SNMP 凭据")
|
||||
@@ -172,7 +173,7 @@ def update_snmp_credential(
|
||||
"after": {"name": credential.name, "description": credential.description, "is_active": credential.is_active, "timeout": credential.timeout, "retries": credential.retries},
|
||||
},
|
||||
)
|
||||
return credential
|
||||
return serialize_dt_fields(credential)
|
||||
|
||||
|
||||
@router.delete("/credentials/{credential_id}", summary="删除 SNMP 凭据")
|
||||
@@ -243,29 +244,15 @@ def get_network_devices(
|
||||
|
||||
serialized = []
|
||||
for d in items:
|
||||
item = {
|
||||
"id": d.id,
|
||||
"name": d.name,
|
||||
"description": d.description,
|
||||
"ip_address": d.ip_address,
|
||||
"port": d.port,
|
||||
"device_type": d.device_type.value if hasattr(d.device_type, 'value') else d.device_type,
|
||||
"vendor": d.vendor,
|
||||
"model": d.model,
|
||||
"firmware_version": d.firmware_version,
|
||||
"serial_number": d.serial_number,
|
||||
"location": d.location,
|
||||
"snmp_credential_id": d.snmp_credential_id,
|
||||
"credential_name": cred_map.get(d.snmp_credential_id),
|
||||
"is_active": d.is_active,
|
||||
"last_polled_at": d.last_polled_at.isoformat() if d.last_polled_at else None,
|
||||
"last_successful_poll": d.last_successful_poll.isoformat() if d.last_successful_poll else None,
|
||||
"arp_poll_interval": d.arp_poll_interval,
|
||||
"mac_poll_interval": d.mac_poll_interval,
|
||||
"interface_poll_interval": d.interface_poll_interval,
|
||||
"created_at": d.created_at.isoformat() if d.created_at else None,
|
||||
"updated_at": d.updated_at.isoformat() if d.updated_at else None,
|
||||
}
|
||||
item = serialize_dt_fields(d)
|
||||
# 补充手写的关联字段(datetime 已经由 serialize_dt_fields 序列化)
|
||||
item["device_type"] = d.device_type.value if hasattr(d.device_type, 'value') else d.device_type
|
||||
item["credential_name"] = cred_map.get(d.snmp_credential_id)
|
||||
item["last_polled_at"] = item.get("last_polled_at") # 已是 ISO 字符串
|
||||
item["last_successful_poll"] = item.get("last_successful_poll")
|
||||
item["arp_poll_interval"] = d.arp_poll_interval
|
||||
item["mac_poll_interval"] = d.mac_poll_interval
|
||||
item["interface_poll_interval"] = d.interface_poll_interval
|
||||
serialized.append(item)
|
||||
|
||||
return {"total": total, "items": serialized}
|
||||
@@ -278,7 +265,7 @@ def get_network_device(device_id: int, db: Session = Depends(get_db)):
|
||||
device = db.query(NetworkDevice).filter(NetworkDevice.id == device_id).first()
|
||||
if not device:
|
||||
raise HTTPException(status_code=404, detail="设备不存在")
|
||||
return device
|
||||
return serialize_dt_fields(device)
|
||||
|
||||
|
||||
@router.post("/devices", summary="创建网络设备")
|
||||
@@ -329,7 +316,7 @@ def create_network_device(
|
||||
user_agent=u,
|
||||
detail={"ip_address": device.ip_address, "port": device.port, "device_type": device.device_type.value if hasattr(device.device_type, 'value') else device.device_type},
|
||||
)
|
||||
return device
|
||||
return serialize_dt_fields(device)
|
||||
|
||||
|
||||
@router.put("/devices/{device_id}", summary="更新网络设备")
|
||||
@@ -400,7 +387,7 @@ def update_network_device(
|
||||
},
|
||||
},
|
||||
)
|
||||
return device
|
||||
return serialize_dt_fields(device)
|
||||
|
||||
|
||||
@router.delete("/devices/{device_id}", summary="删除网络设备")
|
||||
|
||||
Reference in New Issue
Block a user