zabbix_sender

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2013 License: BSD-2-Clause Imports: 10 Imported by: 2

README

zabbix-sender

This Go package provides interface to push data to Zabbix server's trapper items. It works similar to Zabbix's own zabbix_sender. It should work with Zabbix 1.8 and 2.0.

Install it: go get github.com/AlekSi/zabbix-sender

Documentation is available on godoc.org.

License: Simplified BSD License (see LICENSE).

Documentation

Overview

Package zabbix_sender provides interface to push data to Zabbix server's trapper items. (See https://www.zabbix.com/documentation/2.0/manual/config/items/itemtypes/trapper). It works similar to Zabbix's own zabbix_sender (https://www.zabbix.com/documentation/2.0/manpages/zabbix_sender). It should work with Zabbix 1.8 and 2.0.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrBadHeader = errors.New("bad header")

Unexpected header of Zabbix's response.

Functions

func ConvertValue

func ConvertValue(i interface{}) string

Converts value to format accepted by Zabbix server. It uses "%.6f" format for floats, and fmt.Sprint() (which will try String() and Error() methods) for other types. Keep in mind that Zabbix doesn't support negative integers, use floats instead.

Types

type DataItem

type DataItem struct {
	Hostname  string `json:"host"`
	Key       string `json:"key"`
	Timestamp int64  `json:"clock,omitempty"` // UNIX timestamp, 0 is ignored
	Value     string `json:"value"`           // Use ConvertValue() to fill
}

Single Zabbix data item.

type DataItems

type DataItems []DataItem

func MakeDataItems

func MakeDataItems(kv map[string]interface{}, hostname string) DataItems

Convert key/value pairs to DataItems using ConvertValue(). Each DataItem's Host is set to hostname, Timestamp is zeroed.

func (DataItems) Marshal

func (di DataItems) Marshal() (b []byte, err error)

Converts filled DataItems to format accepted by Zabbix server. It's like dense JSON with binary header, somewhat documented there: https://www.zabbix.com/documentation/2.0/manual/appendix/items/activepassive

type Response

type Response struct {
	Response  string `json:"response"` // "success" on success
	Info      string `json:"info"`     // String like "Processed 2 Failed 1 Total 3 Seconds spent 0.000034"
	Processed int    // Filled by parsing Info
	Failed    int    // Filled by parsing Info
}

func Send

func Send(addr *net.TCPAddr, di DataItems) (res *Response, err error)

Send DataItems to Zabbix server and wait for response. Returns encountered fatal error like I/O and marshalling/unmarshalling. Caller should inspect response (and in some situations also Zabbix server log) to check if all items are accepted.

Example
data := map[string]interface{}{"rpm": 42.12, "errors": 1}
di := MakeDataItems(data, "localhost")
addr, _ := net.ResolveTCPAddr("tcp", "localhost:10051")
res, _ := Send(addr, di)
fmt.Print(res)
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL