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 ¶
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 ¶
Convert key/value pairs to DataItems using ConvertValue(). Each DataItem's Host is set to hostname, Timestamp is zeroed.
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 ¶
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: