-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
40 lines (35 loc) · 825 Bytes
/
session.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
package go_zabbix
import (
"crypto/tls"
"github.com/cavaliercoder/go-zabbix"
"net/http"
)
type ZabbixServer struct {
Addr string `json:"address"`
User string `json:"user"`
Password string `json:"password"`
}
type Session struct {
*zabbix.Session
}
func (this *ZabbixServer) NewSession() (*Session, error) {
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
cache := zabbix.NewSessionFileCache().SetFilePath("./zabbix_session")
url := "http://" + this.Addr + "/zabbix/api_jsonrpc.php"
session, err := zabbix.CreateClient(url).
WithCache(cache).
WithHTTPClient(client).
WithCredentials(this.User, this.Password).
Connect()
if err != nil {
return nil, err
}
cdSession := &Session{
session,
}
return cdSession, nil
}