zabbix-tools / go-zabbix

Go bindings for the Zabbix API
GNU General Public License v2.0
108 stars 70 forks source link

Use session.GetHosts #18

Open modogo2000 opened 5 years ago

modogo2000 commented 5 years ago

Hello

Is it possible to have an example on how use GetHostt ?

I have hard time to use it.

Best regards

fabiang commented 5 years ago

Get a list of hosts by their hostname:

// ...
filter := make(map[string]interface{})
filter["host"] = "MyComputerName"
hosts, err := session.GetHosts(zabbix.HostGetParams{
    GetParameters: zabbix.GetParameters{
       Filter: filter,
}})

if err != nil {
    log.Fatalf("%v\n", err)
}

log.Printf("%v\n", hosts)

Of cause hostname should be unique and the list only contain on element.