GitXplorerGitXplorer
r

zabbix

public
44 stars
29 forks
1 issues

Commits

List of commits on branch master.
Unverified
1cf60ccd42f9f4f7f3196f7a4ff38256b236bb5e

Merge pull request #4 from fabianlee/logout

rrday committed 8 years ago
Unverified
b0c5fb1d5cbede9f7b8450d0c671dff7c643db93

removed debug

ffabianlee committed 8 years ago
Unverified
c7881876cca060fdde167e1a21af5bf6097cd2cb

debug for host

ffabianlee committed 8 years ago
Unverified
fbd629d4e1d37caeda33ff78f975de954683f058

logout method added, generic User access returns interface which does not work for user.logout

ffabianlee committed 8 years ago
Unverified
e5960781584fea8ead21e3bb9415d258ea3dc06e

Merge pull request #3 from blacked/custom-client-support

rrday committed 8 years ago
Verified
7d335364bc7f8c6a23214c836a8ef930feab0481

Add custom http client support

aadubkov committed 8 years ago

README

The README file for this repository.

zabbix

This Go library implements the Zabbix 2.0 API. The Zabbix API is a JSONRPC based API, although it is not compatable with Go's builtin JSONRPC libraries. So we implement that JSONRPC, and provide data types that mimic Zabbbix's return values.

Connecting to the API

func main() {
    api, err := zabbix.NewAPI("http://zabbix.yourhost.net/api_jsonrpc.php", "User", "Password")
    if err != nil {
        fmt.Println(err)
        return
    }

    versionresult, err := api.Version()
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(versionresult)

    _, err = api.Login()
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("Connected to API")
}

Making a call

I typically wrap the actual API call to hide the messy details. If the response has an Error field, and the code is greater than 0, the API will return that Error. Then my wrapper function return a ZabbixError to the caller.

// 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 {
        return nil, 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.
    return nil, &zabbix.ZabbixError{0,"","Host not found"}
}