Skip to content

datadope-io/go-zabbix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-zabbix

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)
	}
}

CHANGELOG

v2.0.1 - 2023-08-11

  • Go mimimum version 1.20
  • Retracted v2.0.0
  • Fix some errors format

v2.0.0 - 2023-08-10

  • New v2 with better error handling, NewSender and NewSenderTimeout using address (instead of host+port) and SendMetrics returning both errors (active + trappers) joined.

v1.6.0 - 2023-08-09

  • New methods to create a Sender using an address instead of host and port: NewSenderAddr and NewSenderAddrTimeout.

v1.5.1 - 2021-10-20

  • Better error handling if Zabbix server response is not valid

v1.4.0 - 2021-10-20

  • Compatible with go modules.

v1.3.0 - 2020-10-20

  • Now Active/Trapper response is formated in Response,Info strings and could be translated int ResponseInfo struct with Failed/Completed/Processed/Spent time.