forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
55 lines (44 loc) · 1.67 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Package zabbix provides bindings to interoperate between programs written in Go
language and the Zabbix monitoring API.
A number of Zabbix API bindings already exist for Go with varying levels of
maturity. This project aims to provide an alternative implementation which is
stable, fast, and allows for loose typing (using types such as interface{} or
map[string]interface{}) as well as strong types (such as zabbix.Host or
zabbix.Event).
The package aims to have comprehensive coverage of Zabbix API methods from v1.8
through to v3.0 without introducing limitations to the native API methods.
package main
import (
"fmt"
"github.com/cavaliercoder/go-zabbix"
)
func main() {
// Default approach - without session caching
session, err := zabbix.NewSession("http://zabbix/api_jsonrpc.php", "Admin", "zabbix")
if err != nil {
panic(err)
}
fmt.Printf("Connected to Zabbix API v%s", session.GetVersion())
// Use session builder with caching.
// You can use own cache by implementing SessionAbstractCache interface
// Optionally an http.Client can be passed to the builder, allowing to skip TLS verification,
// pass proxy settings, etc.
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true
}
}
}
cache := zabbix.NewSessionFileCache().SetFilePath("./zabbix_session")
session, err := zabbix.CreateClient("http://zabbix/api_jsonrpc.php").
WithCache(cache).
WithHTTPClient(client).
WithCredentials("Admin", "zabbix").
Connect()
fmt.Printf("Connected to Zabbix API v%s", session.GetVersion())
}
For more information see: https://github.com/cavaliercoder/go-zabbix
*/
package zabbix