chore: 添加注册设备条目数

This commit is contained in:
Liam Chan 2024-08-27 15:05:25 +08:00
parent 254b41e160
commit b1ad068073

View File

@ -1,28 +1,26 @@
package zabbixagent package zabbixagent
import ( import (
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"onvif-agent/response" "onvif-agent/response"
handler "onvif-agent/router/handler/onvif" handler "onvif-agent/router/handler/onvif"
service "onvif-agent/service/onvif" service "onvif-agent/service/onvif"
) )
func DiscoverONVIFDevices(c *gin.Context) { func DiscoverONVIFDevices(c *gin.Context) {
type ZBXDevice struct { type device struct {
Xaddr string `json:"{#XADDR}"` Xaddr string `json:"{#XADDR}"`
} }
arr := make([]ZBXDevice, 0) devices := make([]device, 0)
for xaddr := range service.Sessions { for xaddr := range service.Sessions {
arr = append(arr, ZBXDevice{ devices = append(devices, device{
Xaddr: xaddr, Xaddr: xaddr,
}) })
} }
c.JSON(http.StatusOK, gin.H{ response.NewResponse().WithData(devices).Send(c)
"data": arr,
})
} }
func RegisterONVIFDevices(c *gin.Context) { func RegisterONVIFDevices(c *gin.Context) {
@ -53,7 +51,7 @@ func RegisterONVIFDevices(c *gin.Context) {
service.Sessions = sessions service.Sessions = sessions
response.NewResponse().Success().Send(c) response.NewResponse().Success().WithMessage(fmt.Sprintf("%d device(s) registered", len(sessions))).Send(c)
} }
type ConsumeNotificationsRequest struct { type ConsumeNotificationsRequest struct {