feat: 为 zbx 添加批量注册设备能力
This commit is contained in:
parent
0ef8af021f
commit
67de79e230
@ -3,7 +3,9 @@ package zabbixagent
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"onvif-agent/service/onvif"
|
"onvif-agent/response"
|
||||||
|
handler "onvif-agent/router/handler/onvif"
|
||||||
|
service "onvif-agent/service/onvif"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ONVIFDeviceDiscovery(c *gin.Context) {
|
func ONVIFDeviceDiscovery(c *gin.Context) {
|
||||||
@ -12,7 +14,7 @@ func ONVIFDeviceDiscovery(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
arr := make([]ZBXDevice, 0)
|
arr := make([]ZBXDevice, 0)
|
||||||
for xaddr := range onvif.Sessions {
|
for xaddr := range service.Sessions {
|
||||||
arr = append(arr, ZBXDevice{
|
arr = append(arr, ZBXDevice{
|
||||||
Xaddr: xaddr,
|
Xaddr: xaddr,
|
||||||
})
|
})
|
||||||
@ -22,3 +24,29 @@ func ONVIFDeviceDiscovery(c *gin.Context) {
|
|||||||
"data": arr,
|
"data": arr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ONVIFDeviceRegister(c *gin.Context) {
|
||||||
|
var req []handler.CreateSessionRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.NewResponse().Error(err).Send(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range req {
|
||||||
|
session, err := service.NewSession(v.Xaddr, v.Username, v.Password)
|
||||||
|
if err != nil {
|
||||||
|
response.NewResponse().Error(err).Send(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = session.GetDeviceInfo()
|
||||||
|
if err != nil {
|
||||||
|
response.NewResponse().Error(err).Send(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
service.Sessions[session.Device.GetDeviceParams().Xaddr] = session
|
||||||
|
}
|
||||||
|
|
||||||
|
response.NewResponse().Success().Send(c)
|
||||||
|
}
|
||||||
|
@ -35,5 +35,6 @@ func SetupRoutes(r *gin.Engine) {
|
|||||||
zabbixGroup := r.Group("/zabbix")
|
zabbixGroup := r.Group("/zabbix")
|
||||||
{
|
{
|
||||||
zabbixGroup.POST("/onvifDeviceDiscovery", zabbixagent.ONVIFDeviceDiscovery)
|
zabbixGroup.POST("/onvifDeviceDiscovery", zabbixagent.ONVIFDeviceDiscovery)
|
||||||
|
zabbixGroup.POST("/onvifDeviceRegister", zabbixagent.ONVIFDeviceRegister)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user