Compare commits

..

9 Commits

6 changed files with 24 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

18
main.go
View File

@ -19,8 +19,7 @@ func main() {
/**
* Logging
*/
date := time.Now().Format("2006-01-02")
logFile := fmt.Sprintf("%s.log", date)
logFile := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02"))
var logFilePath string
if runtime.GOOS == "linux" {
logFilePath = fmt.Sprintf("/var/log/%s/%s", constant.AppName, logFile)
@ -63,9 +62,16 @@ func main() {
/**
* Zabbix agent
*/
go func() {
zabbixagent.Run()
}()
//go func() {
// 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
COPY . ./
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
COPY --from=builder /build/out/app /usr/sbin/onvif-agent
RUN echo "Plugins.Onvif.System.Path=/usr/sbin/onvif-agent" >> /etc/zabbix/zabbix_agent2.d/plugins.d/onvif.conf
COPY --from=builder /build/out/app /usr/sbin/zabbix-agent2-plugin/onvif-agent
RUN echo "Plugins.ONVIF.System.Path=/usr/sbin/zabbix-agent2-plugin/onvif-agent" >> /etc/zabbix/zabbix_agent2.d/plugins.d/onvif.conf