refactor: 调试提交

This commit is contained in:
Liam Chan 2024-08-23 11:06:31 +08:00
parent 37e6813d6f
commit c6803285fe
7 changed files with 48 additions and 29 deletions

1
.gitignore vendored
View File

@ -171,4 +171,5 @@ Temporary Items
# Application # Application
config.dev.yaml config.dev.yaml
compose.dev.yaml

16
compose.yaml Normal file
View File

@ -0,0 +1,16 @@
services:
zabbixagent:
build:
context: .
dockerfile: zabbixagent.dockerfile
environment:
ZBX_HOSTNAME: ONVIF plugin for Zabbix agent 2
ZBX_SERVER_HOST: server
ZBX_SERVER_PORT: 10051
networks:
- zabbix-network
restart: unless-stopped
networks:
zabbix-network:
external: true

View File

@ -1,4 +1,4 @@
package plugin package zabbixagent
import ( import (
"context" "context"

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"onvif-agent/config" "onvif-agent/config"
"onvif-agent/integration/zabbixagent/plugin"
"os" "os"
"golang.zabbix.com/sdk/plugin/flag" "golang.zabbix.com/sdk/plugin/flag"
@ -36,7 +35,7 @@ const (
pluginLicenseYear = 2024 pluginLicenseYear = 2024
) )
func Run() error { func Run() {
err := flag.HandleFlags( err := flag.HandleFlags(
config.Conf.Integrations.ZabbixAgent.Plugin.Name, config.Conf.Integrations.ZabbixAgent.Plugin.Name,
os.Args[0], os.Args[0],
@ -48,16 +47,16 @@ func Run() error {
) )
if err != nil { if err != nil {
if errors.Is(err, zbxerr.ErrorOSExitZero) { if errors.Is(err, zbxerr.ErrorOSExitZero) {
return nil return
} }
return err panic(err)
} }
err = plugin.Launch() err = Launch()
if err != nil { if err != nil {
return err return
} }
return nil panic(err)
} }

View File

@ -1,4 +1,4 @@
package plugin package zabbixagent
import ( import (
"context" "context"

34
main.go
View File

@ -1,12 +1,9 @@
package main package main
import ( import (
"fmt"
"github.com/gin-gonic/gin"
"log" "log"
"onvif-agent/config" "onvif-agent/config"
"onvif-agent/integration/zabbixagent" "onvif-agent/integration/zabbixagent"
"onvif-agent/router"
) )
func main() { func main() {
@ -20,26 +17,23 @@ func main() {
/** /**
* Web server * Web server
*/ */
go func() { //go func() {
r := gin.Default() // r := gin.Default()
//
router.SetupRoutes(r) // router.SetupRoutes(r)
//
addr := fmt.Sprintf("%s:%d", config.Conf.Server.Host, config.Conf.Server.Port) // addr := fmt.Sprintf("%s:%d", config.Conf.Server.Host, config.Conf.Server.Port)
if err := r.Run(addr); err != nil { // if err := r.Run(addr); err != nil {
fmt.Println("Failed to start server:", err) // fmt.Println("Failed to start server:", err)
} // }
}() //}()
/** /**
* Zabbix agent * Zabbix agent
*/ */
go func() { //go func() {
err := zabbixagent.Run() zabbixagent.Run()
if err != nil { //}()
fmt.Println("Failed to start Zabbix agent integration:", err)
}
}()
select {} //select {}
} }

9
zabbixagent.dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM golang:1.23 AS builder
WORKDIR /build
COPY . ./
RUN GOPROXY=https://goproxy.cn go mod download
RUN PROFILE=dev CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o /app
FROM zabbix/zabbix-agent2:ubuntu-7.0-latest
COPY --from=builder /app /usr/sbin/zabbix-agent2-plugin/onvif
RUN echo "Plugins.Onvif.System.Path=/usr/sbin/zabbix-agent2-plugin/onvif" >> /etc/zabbix/zabbix_agent2.d/plugins.d/onvif.conf