All checks were successful
Template Cleanup / Template Cleanup (push) Has been skipped
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package onvif
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/IOTechSystems/onvif/event"
|
|
"github.com/IOTechSystems/onvif/gosoap"
|
|
"github.com/gin-gonic/gin"
|
|
"log"
|
|
"net/http"
|
|
"zabbixagent2plugintemplate/config"
|
|
"zabbixagent2plugintemplate/response"
|
|
"zabbixagent2plugintemplate/service/onvif"
|
|
)
|
|
|
|
func CreateSubscription(c *gin.Context) {
|
|
xaddr := c.Param("xaddr")
|
|
callbackURL := event.AttributedURIType(fmt.Sprintf("%s/onvif/subscriptions/%s/callback", config.Config.App.URL, xaddr))
|
|
log.Printf("CreateSubscription callback URL: %s", callbackURL)
|
|
|
|
session := onvif.Sessions[xaddr]
|
|
if session == nil {
|
|
response.NewResponse().Fail("Connection not found").WithCode(http.StatusNotFound).Send(c)
|
|
return
|
|
}
|
|
|
|
result, err := session.EventSubscribe(callbackURL, "PT60S")
|
|
if err != nil {
|
|
response.NewResponse().Error(err).Send(c)
|
|
return
|
|
}
|
|
|
|
response.NewResponse().Success().WithData(result).Send(c)
|
|
}
|
|
|
|
func NotifyCallback(c *gin.Context) {
|
|
xaddr := c.Param("xaddr")
|
|
log.Printf("NotifyCallback xaddr: %s", xaddr)
|
|
|
|
var notify event.Notify
|
|
envelope := gosoap.NewSOAPEnvelope(¬ify)
|
|
if err := c.ShouldBindXML(&envelope); err != nil {
|
|
response.NewResponse().Error(err).WithCode(http.StatusBadRequest).Send(c)
|
|
return
|
|
}
|
|
|
|
onvif.Notifications[xaddr] = append(onvif.Notifications[xaddr], notify.NotificationMessage...)
|
|
|
|
response.NewResponse().Success().Send(c)
|
|
}
|