Code Monkey home page Code Monkey logo

zabbix-1's Introduction

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"}
}

zabbix-1's People

Contributors

rday avatar fabianlee avatar kirs avatar adubkov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.