コード例 #1
0
// Find and return a single host object by name
func GetHost(api *zabbix.API, host string) (zabbix.ZabbixHost, error) {
	params := make(map[string]interface{}, 0)
	filter := make(map[string]string, 0)
	filter["host"] = host
	params["filter"] = filter
	params["output"] = "extend"
	params["select_groups"] = "extend"
	params["templated_hosts"] = 1
	ret, err := api.Host("get", params)

	// This happens if there was an RPC error
	if err != nil {
		var r zabbix.ZabbixHost
		return r, err
	}

	// If our call was successful
	if len(ret) > 0 {
		return ret[0], err
	}

	// This will be the case if the RPC call was successful, but
	// Zabbix had an issue with the data we passed.
	var r zabbix.ZabbixHost
	return r, &zabbix.ZabbixError{0, "", "Host not found"}
}
コード例 #2
0
func GetHostSnmpInterface(api *zabbix.API, hostid string) ([]zabbix.HostInterface, error) {
	params := make(map[string]interface{}, 0)
	params["hostids"] = hostid
	filter := make(map[string]string, 0)
	filter["type"] = "2"
	params["filter"] = filter
	ret, err := api.Interface("get", params)

	return ret, err
}
コード例 #3
0
func CreateHostSnmpInterface(api *zabbix.API, hostid, ip string) {
	params := make(map[string]interface{}, 0)
	params["hostid"] = hostid
	params["dns"] = ""
	params["ip"] = ip
	params["main"] = "1"
	params["port"] = "161"
	params["type"] = "2"
	params["useip"] = "1"

	_, err := api.Interface("create", params)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Create the interface successful")
}