Documentation
¶
Overview ¶
Package zbx is a Zabbix Agent implementation in golang that allows your application to act as a zabbix agent and respond to simple requests.
It is compatible with Zabbix version 4 and newer, however it does not support compression or TLS PSK authentication.
Example ¶
package main import ( "runtime" "github.com/ecnepsnai/zbx" ) func main() { // This function is called for each incoming request from the Zabbix server getItem := func(itemKey string) (interface{}, error) { if itemKey == "agent.ping" { return "1", nil } else if itemKey == "runtime.version" { return runtime.Version, nil } // Returning nil, nil means the itemKey was unknown return nil, nil } // This will block zbx.Start(getItem, "0.0.0.0:10050") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrorLog io.Writer = os.Stderr
ErrorLog is the writer that error messages are written to. By default this is stderr.
Functions ¶
func Start ¶
Start the Zabbix agent on the specified address. Will block and always return on error. Will panic if itemFunc is nil.
Example ¶
package main import ( "runtime" "github.com/ecnepsnai/zbx" ) func main() { // This function is called for each incoming request from the Zabbix server getItem := func(itemKey string) (interface{}, error) { if itemKey == "agent.ping" { return "1", nil } else if itemKey == "runtime.version" { return runtime.Version, nil } // Returning nil, nil means the itemKey was unknown return nil, nil } // This will block zbx.Start(getItem, "0.0.0.0:10050") }
Output:
func StartListener ¶ added in v1.1.4
Start the Zabbix agent on the specified listener.
func StartTLS ¶ added in v1.1.4
func StartTLS(itemFunc ItemFunc, address string, certificate tls.Certificate) error
StartTLS will start the Zabbix agent on the specified address with TLS. The agent will present the given certificate to the server when connected. Will panic if itemFunc is nil.
Example ¶
package main import ( "crypto/tls" "runtime" "github.com/ecnepsnai/zbx" ) func main() { // This function is called for each incoming request from the Zabbix server getItem := func(itemKey string) (interface{}, error) { if itemKey == "agent.ping" { return "1", nil } else if itemKey == "runtime.version" { return runtime.Version, nil } // Returning nil, nil means the itemKey was unknown return nil, nil } // Load the certificate and key that the zabbix agent will use for incoming connections // from the Zabbix server cert, err := tls.LoadX509KeyPair("zabbix.crt", "zabbix.key") if err != nil { panic(err) } // This will block zbx.StartTLS(getItem, "0.0.0.0:10050", cert) }
Output:
Types ¶
type ItemFunc ¶ added in v1.1.0
ItemFunc describes the method invoked when the Zabbix Server (or proxy) is requesting an item from this agent. The returned interface be encoded as a string and returned to the server.
If error is not nil, it will be sent back to the server. If (nil, nil) is returned then it is assumed the key is unknown.
Any calls to `panic()` will be recovered from and written to ErrorLog and the server will act as if the key was unknown.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
zabbix-query
Command zabbix-query provides a simply utility to return a item value from a running zabbix agent.
|
Command zabbix-query provides a simply utility to return a item value from a running zabbix agent. |