Golang package, implement zabbix sender protocol for send metrics to zabbix.
Example:
package main
import (
"errors"
"fmt"
"time"
"github.com/datadope-io/go-zabbix/v2"
)
const (
zabbixAddress = `localhost:10051`
agentActive = true
trapper = false
)
func main() {
var metrics []*zabbix.Metric
metrics = append(metrics, zabbix.NewMetric("localhost", "cpu", "1.22", agentActive, time.Now().Unix()))
metrics = append(metrics, zabbix.NewMetric("localhost", "status", "OK", agentActive))
metrics = append(metrics, zabbix.NewMetric("localhost", "someTrapper", "3.14", trapper))
// Send metrics to zabbix
z := zabbix.NewSender(zabbixAddress)
resActive, resTrapper, err := z.SendMetrics(metrics)
fmt.Printf("Agent active, response=%s, info=%s\n", resActive.Response, resActive.Info)
if errors.Is(err, zabbix.ErrActive) {
fmt.Printf("Error:\n%v\n", err)
}
fmt.Printf("\n----\n\n")
fmt.Printf("Trapper, response=%s, info=%s\n", resTrapper.Response, resTrapper.Info)
if errors.Is(err, zabbix.ErrTrapper) {
fmt.Printf("Error:\n%v\n", err)
}
}
- Go mimimum version 1.20
- Retracted v2.0.0
- Fix some errors format
- New v2 with better error handling,
NewSender
andNewSenderTimeout
using address (instead of host+port) andSendMetrics
returning both errors (active + trappers) joined.
- New methods to create a Sender using an address instead of host and port:
NewSenderAddr
andNewSenderAddrTimeout
.
- Better error handling if Zabbix server response is not valid
- Compatible with go modules.
- Now Active/Trapper response is formated in Response,Info strings and could be translated int ResponseInfo struct with Failed/Completed/Processed/Spent time.