refactor: 调试提交
This commit is contained in:
parent
37e6813d6f
commit
c6803285fe
1
.gitignore
vendored
1
.gitignore
vendored
@ -171,4 +171,5 @@ Temporary Items
|
||||
|
||||
# Application
|
||||
config.dev.yaml
|
||||
compose.dev.yaml
|
||||
|
||||
|
16
compose.yaml
Normal file
16
compose.yaml
Normal 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
|
@ -1,4 +1,4 @@
|
||||
package plugin
|
||||
package zabbixagent
|
||||
|
||||
import (
|
||||
"context"
|
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"onvif-agent/config"
|
||||
"onvif-agent/integration/zabbixagent/plugin"
|
||||
"os"
|
||||
|
||||
"golang.zabbix.com/sdk/plugin/flag"
|
||||
@ -36,7 +35,7 @@ const (
|
||||
pluginLicenseYear = 2024
|
||||
)
|
||||
|
||||
func Run() error {
|
||||
func Run() {
|
||||
err := flag.HandleFlags(
|
||||
config.Conf.Integrations.ZabbixAgent.Plugin.Name,
|
||||
os.Args[0],
|
||||
@ -48,16 +47,16 @@ func Run() error {
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, zbxerr.ErrorOSExitZero) {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = plugin.Launch()
|
||||
err = Launch()
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
panic(err)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package plugin
|
||||
package zabbixagent
|
||||
|
||||
import (
|
||||
"context"
|
34
main.go
34
main.go
@ -1,12 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"onvif-agent/config"
|
||||
"onvif-agent/integration/zabbixagent"
|
||||
"onvif-agent/router"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -20,26 +17,23 @@ func main() {
|
||||
/**
|
||||
* Web server
|
||||
*/
|
||||
go func() {
|
||||
r := gin.Default()
|
||||
|
||||
router.SetupRoutes(r)
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", config.Conf.Server.Host, config.Conf.Server.Port)
|
||||
if err := r.Run(addr); err != nil {
|
||||
fmt.Println("Failed to start server:", err)
|
||||
}
|
||||
}()
|
||||
//go func() {
|
||||
// r := gin.Default()
|
||||
//
|
||||
// router.SetupRoutes(r)
|
||||
//
|
||||
// addr := fmt.Sprintf("%s:%d", config.Conf.Server.Host, config.Conf.Server.Port)
|
||||
// if err := r.Run(addr); err != nil {
|
||||
// fmt.Println("Failed to start server:", err)
|
||||
// }
|
||||
//}()
|
||||
|
||||
/**
|
||||
* Zabbix agent
|
||||
*/
|
||||
go func() {
|
||||
err := zabbixagent.Run()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to start Zabbix agent integration:", err)
|
||||
}
|
||||
}()
|
||||
//go func() {
|
||||
zabbixagent.Run()
|
||||
//}()
|
||||
|
||||
select {}
|
||||
//select {}
|
||||
}
|
||||
|
9
zabbixagent.dockerfile
Normal file
9
zabbixagent.dockerfile
Normal 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
|
Loading…
x
Reference in New Issue
Block a user