Compare commits

...

9 Commits

6 changed files with 24 additions and 16 deletions

View File

@ -1,15 +1,17 @@
services: services:
zabbixagent: onvif-agent:
build: build:
context: . context: .
dockerfile: zabbixagent.dockerfile dockerfile: zabbixagent.dockerfile
environment: environment:
ZBX_HOSTNAME: OnvifAgent plugin ZBX_HOSTNAME: ONVIF
ZBX_SERVER_HOST: server ZBX_SERVER_HOST: server
ZBX_SERVER_PORT: 10051 ZBX_SERVER_PORT: 10051
volumes: volumes:
- ./log:/var/log/onvif-agent - ./log:/var/log/onvif-agent
- ./config.yaml:/etc/onvif-agent/config.yaml - ./config.yaml:/etc/onvif-agent/config.yaml
ports:
- "8080:8080"
networks: networks:
- zabbix-network - zabbix-network
restart: unless-stopped restart: unless-stopped

View File

@ -1,4 +1,4 @@
app: app:
port: 8080 port: 8080
host: "localhost" host: "0.0.0.0"
url: "http://localhost:8080" url: "http://onvif-agent:8080"

View File

@ -1,5 +1,5 @@
package zabbixagent package zabbixagent
const ( const (
PluginName = "OnvifAgent" PluginName = "ONVIF"
) )

View File

@ -76,9 +76,9 @@ func (p *zabbixAgentPlugin) registerMetrics() error {
h := NewHandler() h := NewHandler()
p.metrics = map[metricKey]*metricBinding{ p.metrics = map[metricKey]*metricBinding{
"onvif.version": { "onvif.app.version": {
metric: metric.New( metric: metric.New(
"ONVIF app version", "App version",
nil, nil,
false, false,
), ),

18
main.go
View File

@ -19,8 +19,7 @@ func main() {
/** /**
* Logging * Logging
*/ */
date := time.Now().Format("2006-01-02") logFile := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02"))
logFile := fmt.Sprintf("%s.log", date)
var logFilePath string var logFilePath string
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
logFilePath = fmt.Sprintf("/var/log/%s/%s", constant.AppName, logFile) logFilePath = fmt.Sprintf("/var/log/%s/%s", constant.AppName, logFile)
@ -63,9 +62,16 @@ func main() {
/** /**
* Zabbix agent * Zabbix agent
*/ */
go func() { //go func() {
zabbixagent.Run() // zabbixagent.Run()
}() //}()
//
//select {}
select {} err = zabbixagent.Launch()
if err != nil {
return
}
panic(err)
} }

View File

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