From 254b41e1607521a3ab11abe0e4ea32196284513f Mon Sep 17 00:00:00 2001 From: imbytecat Date: Tue, 27 Aug 2024 14:42:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E9=80=A0=20zbx=20=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E4=B8=BA=20RPC=20=E9=A3=8E=E6=A0=BC=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E9=80=9A=E7=9F=A5=E6=B6=88=E8=B4=B9=E8=80=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integration/zabbixagent/gin_handler.go | 21 +++++++++++++++++++-- router/router.go | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/integration/zabbixagent/gin_handler.go b/integration/zabbixagent/gin_handler.go index a5d41c7..60bf9cf 100644 --- a/integration/zabbixagent/gin_handler.go +++ b/integration/zabbixagent/gin_handler.go @@ -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) +} diff --git a/router/router.go b/router/router.go index 0e047d3..59f757a 100644 --- a/router/router.go +++ b/router/router.go @@ -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) } }