Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
653a79f
don't send error
tpretz Mar 1, 2020
6849df0
add module file
tpretz Mar 1, 2020
9d4202d
adjust
tpretz Mar 1, 2020
4e2922c
enable extra fields
tpretz Mar 2, 2020
c26772a
api returns strings
tpretz Mar 3, 2020
c7063e7
adding interfaceid
tpretz Mar 3, 2020
c610918
accept just groupids
tpretz Mar 3, 2020
699a7b7
adding extra fields for http item
tpretz Mar 4, 2020
894f0e3
typo
tpretz Mar 4, 2020
0b746f2
adding extra init options
tpretz Mar 4, 2020
aca6851
adding support for serializing requests
tpretz Mar 4, 2020
32eb4e4
adding preprocessors
tpretz Mar 4, 2020
99febac
starting snmp fields
tpretz Mar 4, 2020
ecf6896
adding fields
tpretz Mar 5, 2020
c5d1c2f
extra field
tpretz Mar 7, 2020
a671104
adding macros
tpretz Mar 7, 2020
a038a41
optional on create/global
tpretz Mar 7, 2020
ded284a
just unbox the IDs
tpretz Mar 7, 2020
2cc044d
adding tags
tpretz Mar 15, 2020
42f96e2
adding dependent item field
tpretz Mar 21, 2020
a286e12
adding basic proxy support
tpretz Mar 28, 2020
6039d7e
quick lld rule addition
tpretz May 24, 2020
da954ca
missed a few attrs
tpretz May 24, 2020
f206516
fixes
tpretz May 24, 2020
bc2e562
use types
tpretz May 25, 2020
0e28265
proto item
tpretz May 25, 2020
d674829
adding trigger prototypes
tpretz May 25, 2020
4a6ceca
add params
tpretz May 25, 2020
d40d728
dependent lld
tpretz May 25, 2020
7f38204
adding macro paths
tpretz May 26, 2020
b7f427b
application
tpretz May 26, 2020
f35fd6d
Merge pull request #1 from tpretz/lld
tpretz May 26, 2020
4218773
initial graph
tpretz May 26, 2020
f1dd659
adding prototype
tpretz May 26, 2020
cd7892f
graph
tpretz May 26, 2020
5729fbc
Merge pull request #2 from tpretz/graph
tpretz May 27, 2020
ede6c61
adding templates_clear
tpretz May 29, 2020
656b157
updates for v5
tpretz May 29, 2020
a0e5605
adding a warning as we have odd customisations
tpretz May 29, 2020
fce158f
Merge pull request #3 from tpretz/graph
tpretz May 29, 2020
c4a6fad
auth fields
tpretz May 30, 2020
267ba9c
headers support
tpretz May 31, 2020
3d3c296
fixed tests
tomasherout Nov 30, 2020
09c7f10
inventory proof of concept
tomasherout Dec 1, 2020
73da6b6
module name
tomasherout Dec 1, 2020
08cea48
invetory as json.RawMessage
tomasherout Dec 1, 2020
0f3d30c
Merge branch 'master' into inventory
tomasherout Dec 1, 2020
8ef9acb
inventory struct
tomasherout Dec 1, 2020
7fe0cc8
what about this
tpretz Dec 5, 2020
1dbf716
Merge remote-tracking branch 'orig/development/inventory' into inventory
tomasherout Dec 7, 2020
7a4edcf
rename module back to original name; fix in HostsGet func
tomasherout Dec 8, 2020
3d580a1
Inventory Changes
tpretz Dec 30, 2020
ca6c828
Merge pull request #6 from tpretz/feature/inventory
tpretz Dec 31, 2020
ae56f00
inventory mode omitted when default on 5.4, abstract
tpretz Aug 14, 2021
2a42ec0
adding tags to host
tpretz Aug 15, 2021
ab23bac
adding tags to item
tpretz Aug 15, 2021
be2af53
adding http proxy
tpretz Oct 8, 2021
46aefc8
adding retrievemode
tpretz Oct 8, 2021
9aeefba
adding follow redirects
tpretz Oct 8, 2021
520558d
lld as well
tpretz Oct 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Go zabbix api

[![GoDoc](https://godoc.org/github.com/claranet/go-zabbix-api?status.svg)](https://godoc.org/github.com/claranet/go-zabbix-api) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Build Status](https://travis-ci.org/claranet/go-zabbix-api.svg?branch=master)](https://travis-ci.org/claranet/go-zabbix-api)
Note, this is not tested and is adjusted for use of tpretz/terraform-provider-zabbix

[![GoDoc](https://godoc.org/github.com/tpretz/go-zabbix-api?status.svg)](https://godoc.org/github.com/tpretz/go-zabbix-api) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Build Status](https://travis-ci.org/tpretz/go-zabbix-api.svg?branch=master)](https://travis-ci.org/tpretz/go-zabbix-api)

This Go package provides access to Zabbix API.

Expand All @@ -10,7 +12,7 @@ This package aims to support multiple zabbix resources from its API like trigger

## Install

Install it: `go get github.com/claranet/go-zabbix-api`
Install it: `go get github.com/tpretz/go-zabbix-api`

## Getting started

Expand All @@ -20,7 +22,7 @@ package main
import (
"fmt"

"github.com/claranet/go-zabbix-api"
"github.com/tpretz/go-zabbix-api"
)

func main() {
Expand Down Expand Up @@ -67,7 +69,7 @@ go test -v

## References

Documentation is available on [godoc.org](https://godoc.org/github.com/claranet/go-zabbix-api).
Documentation is available on [godoc.org](https://godoc.org/github.com/tpretz/go-zabbix-api).
Also, Rafael Fernandes dos Santos wrote a [great article](http://www.sourcecode.net.br/2014/02/zabbix-api-with-golang.html) about using and extending this package.

License: Simplified BSD License (see [LICENSE](LICENSE)).
2 changes: 1 addition & 1 deletion application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"testing"

zapi "github.com/claranet/go-zabbix-api"
zapi "github.com/tpretz/go-zabbix-api"
)

func CreateApplication(host *zapi.Host, t *testing.T) *zapi.Application {
Expand Down
41 changes: 39 additions & 2 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package zabbix

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"sync"
"sync/atomic"
)

Expand Down Expand Up @@ -75,14 +77,44 @@ type API struct {
url string
c http.Client
id int32
ex sync.Mutex
Config Config
}

type Config struct {
Url string
TlsNoVerify bool
Log *log.Logger
Serialize bool
Version int
}

// NewAPI Creates new API access object.
// Typical URL is http://host/api_jsonrpc.php or http://host/zabbix/api_jsonrpc.php.
// It also may contain HTTP basic auth username and password like
// http://username:password@host/api_jsonrpc.php.
func NewAPI(url string) (api *API) {
return &API{url: url, c: http.Client{}, UserAgent: "github.com/claranet/zabbix"}
func NewAPI(c Config) (api *API) {
api = &API{
url: c.Url,
c: http.Client{},
UserAgent: "github.com/tpretz/go-zabbix-api",
Logger: c.Log,
Config: c,
}

if c.TlsNoVerify {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
api.c = http.Client{
Transport: tr,
}
api.printf("TLS running in insecure mode, do not use this configuration in production")
}

return
}

// SetClient Allows one to use specific http.Client, for example with InsecureSkipVerify transport.
Expand Down Expand Up @@ -113,6 +145,11 @@ func (api *API) callBytes(method string, params interface{}) (b []byte, err erro
req.Header.Add("Content-Type", "application/json-rpc")
req.Header.Add("User-Agent", api.UserAgent)

if api.Config.Serialize {
api.ex.Lock()
defer api.ex.Unlock()
}

res, err := api.c.Do(req)
if err != nil {
api.printf("Error : %s", err)
Expand Down
16 changes: 7 additions & 9 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

zapi "github.com/claranet/go-zabbix-api"
zapi "github.com/tpretz/go-zabbix-api"
)

var (
Expand Down Expand Up @@ -42,7 +42,12 @@ func getAPI(t *testing.T) *zapi.API {
}

url, user, password := os.Getenv("TEST_ZABBIX_URL"), os.Getenv("TEST_ZABBIX_USER"), os.Getenv("TEST_ZABBIX_PASSWORD")
_api = zapi.NewAPI(url)

// Zabbix client connection configuration
var c zapi.Config
c.Url = url

_api = zapi.NewAPI(c)
_api.SetClient(http.DefaultClient)
v := os.Getenv("TEST_ZABBIX_VERBOSE")
if v != "" && v != "0" {
Expand Down Expand Up @@ -84,10 +89,3 @@ func TestVersion(t *testing.T) {
t.Errorf("Unexpected version: %s", v)
}
}

func ExampleAPI_Call() {
api := zapi.NewAPI("http://host/api_jsonrpc.php")
api.Login("user", "password")
res, _ := api.Call("item.get", zapi.Params{"itemids": "23970", "output": "extend"})
log.Print(res)
}
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ language and the Zabbix monitoring API.
Tested on Zabbix 3.2 but should work since 2.0 version.
This package aims to support multiple zabbix resources from its API like trigger, application, host group, host, item, template..

Install it: `go get github.com/claranet/go-zabbix-api`
Install it: `go get github.com/tpretz/go-zabbix-api`

Getting started

Expand All @@ -14,7 +14,7 @@ Getting started
import (
"fmt"

"github.com/claranet/go-zabbix-api"
"github.com/tpretz/go-zabbix-api"
)

func main() {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tpretz/go-zabbix-api

go 1.12

require github.com/AlekSi/reflector v0.4.1 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/AlekSi/reflector v0.4.1/go.mod h1:K9Yt9Jbte9Xw4QZ3e/ovaWduyRSlKVmwnze4z3+bVxs=
github.com/tpretz/go-zabbix-api v0.3.1/go.mod h1:vCzbm8q1QYUHmeWisZSfJzt5MfPj+JeRoNW5o4sG72o=
github.com/tpretz/go-zabbix-api v0.8.0 h1:5xlz9QCcwApIvrPru/WzTUkPltlo+x8tBpbExW9mrjU=
github.com/tpretz/go-zabbix-api v0.8.0/go.mod h1:SFemU2FNM7aeT3/NinjDw0SQEZGVOoU5d+CqXKTetbw=
Loading