Coder Social home page Coder Social logo

zabbix'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's People

Contributors

adubkov avatar fabianlee avatar kirs avatar rday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

zabbix's Issues

x509: certificate signed by unknown authority

Hi,

when I try to log in with your api I get following error message:
x509: certificate signed by unknown authority

The problem is that my colleagues used a self signed certificate.
Do you have any ideas how to solve this?

Unable to get and compile zabbix on ubuntu 16.04

I seem to be unable to compile and install the zabbix package for Ubuntu 16.04.

predatorian@phil-ubuntu [11:33:43] ~/Documents/Go/src/github.com/predatorian3   
$ go get -u -v  github.com/rday/zabbix
github.com/rday/zabbix (download)
runtime
# runtime
/usr/local/go/src/runtime/mstkbar.go:151:10: debug.gcstackbarrieroff undefined (type struct { allocfreetrace int32; cgocheck int32; efence int32; gccheckmark int32; gcpacertrace int32; gcshrinkstackoff int32; gcrescanstacks int32; gcstoptheworld int32; gctrace int32; invalidptr int32; sbrk int32; scavenge int32; scheddetail int32; schedtrace int32 } has no field or method gcstackbarrieroff)
/usr/local/go/src/runtime/mstkbar.go:162:24: division by zero
/usr/local/go/src/runtime/mstkbar.go:162:43: invalid expression unsafe.Sizeof(composite literal)
/usr/local/go/src/runtime/mstkbar.go:162:44: undefined: stkbar
/usr/local/go/src/runtime/mstkbar.go:212:4: gp.stkbar undefined (type *g has no field or method stkbar)
/usr/local/go/src/runtime/mstkbar.go:213:15: gp.stkbar undefined (type *g has no field or method stkbar)
/usr/local/go/src/runtime/mstkbar.go:216:23: undefined: stackBarrierPC
/usr/local/go/src/runtime/mstkbar.go:226:28: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
/usr/local/go/src/runtime/mstkbar.go:227:19: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
/usr/local/go/src/runtime/mstkbar.go:248:41: undefined: stkbar
/usr/local/go/src/runtime/mstkbar.go:227:19: too many errors
predatorian@phil-ubuntu [11:34:28] ~/Documents/Go/src/github.com/predatorian3   
$ uname -a
Linux phil-ubuntu 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
predatorian@phil-ubuntu [11:34:51] ~/Documents/Go/src/github.com/predatorian3   
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.3 LTS
Release:	16.04
Codename:	xenial
predatorian@phil-ubuntu [11:34:56] ~/Documents/Go/src/github.com/predatorian3   
$ go version
go version go1.9.2 linux/amd64

However, I was able to just build this using the same version of Golang, but on Windows and MacOS.

No license

This package doesn't have a license. May you apply one?

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.