Compare commits

..

No commits in common. "d82a83cca1897e0ecac3488f3743c7f16faf2997" and "554da113e36deb51a2a897a64ee0c547aa853d8f" have entirely different histories.

6 changed files with 16 additions and 24 deletions

View File

@ -1,17 +1,15 @@
services: services:
onvif-agent: zabbixagent:
build: build:
context: . context: .
dockerfile: zabbixagent.dockerfile dockerfile: zabbixagent.dockerfile
environment: environment:
ZBX_HOSTNAME: ONVIF ZBX_HOSTNAME: OnvifAgent plugin
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: "0.0.0.0" host: "localhost"
url: "http://onvif-agent:8080" url: "http://localhost:8080"

View File

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

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.app.version": { "onvif.version": {
metric: metric.New( metric: metric.New(
"App version", "ONVIF app version",
nil, nil,
false, false,
), ),

18
main.go
View File

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