feat: 改造 zbx 路由为 RPC 风格,添加了通知消费者接口

This commit is contained in:
Liam Chan 2024-08-27 14:42:11 +08:00
parent c8b33a27f6
commit 254b41e160
2 changed files with 22 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import (
service "onvif-agent/service/onvif"
)
func ONVIFDeviceDiscovery(c *gin.Context) {
func DiscoverONVIFDevices(c *gin.Context) {
type ZBXDevice struct {
Xaddr string `json:"{#XADDR}"`
}
@ -25,7 +25,7 @@ func ONVIFDeviceDiscovery(c *gin.Context) {
})
}
func ONVIFDeviceRegister(c *gin.Context) {
func RegisterONVIFDevices(c *gin.Context) {
var req []handler.CreateSessionRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.NewResponse().Error(err).Send(c)
@ -55,3 +55,20 @@ func ONVIFDeviceRegister(c *gin.Context) {
response.NewResponse().Success().Send(c)
}
type ConsumeNotificationsRequest struct {
Xaddr string `json:"xaddr"`
}
func ConsumeONVIFNotifications(c *gin.Context) {
var req ConsumeNotificationsRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.NewResponse().Error(err).Send(c)
return
}
n := service.Notifications[req.Xaddr]
delete(service.Notifications, req.Xaddr)
response.NewResponse().WithData(n).Send(c)
}

View File

@ -36,7 +36,8 @@ func SetupRoutes(r *gin.Engine) {
zabbixGroup := r.Group("/zabbix")
{
zabbixGroup.POST("/onvifDeviceDiscovery", zabbixagent.ONVIFDeviceDiscovery)
zabbixGroup.POST("/onvifDeviceRegister", zabbixagent.ONVIFDeviceRegister)
zabbixGroup.POST("/DiscoverONVIFDevices", zabbixagent.DiscoverONVIFDevices)
zabbixGroup.POST("/RegisterONVIFDevices", zabbixagent.RegisterONVIFDevices)
zabbixGroup.POST("/ConsumeONVIFNotifications", zabbixagent.ConsumeONVIFNotifications)
}
}