forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
108 lines (81 loc) · 2.73 KB
/
proxy.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package zabbix
import (
"bytes"
"encoding/json"
"github.com/fabiang/go-zabbix/types"
)
const (
// ProxyStatusActive active proxy
ProxyStatusActive = 5
// ProxyStatusPassive passive proxy
ProxyStatusPassive = 6
// ProxyTLSConnectUnencryped connect unencrypted to or from host
ProxyTLSConnectUnencryped = 1
// ProxyTLSConnectPSK connect with PSK to or from host
ProxyTLSConnectPSK = 2
// ProxyTLSConnectCertificate connect with certificate to or from host
ProxyTLSConnectCertificate = 4
)
// Proxy Proxy infomation returned from Zabbix API
type Proxy struct {
ProxyID string `json:"proxyid"`
Host string `json:"host"`
Status int `json:"status,string"`
Description string `json:"description"`
// How should we connect to proxy
TLSConnect int `json:"tls_connect,string"`
// What type of connections we accept from proxy
TLSAccept int `json:"tls_accept,string"`
TLSIssuer string `json:"tls_issuer"`
TLSSubject string `json:"tls_subject"`
// Note those were removed in Zabbix 5.4
TLSPSKIdentity string `json:"tls_psk_identity"`
TLSPSK string `json:"tls_psk"`
ProxyAddresses types.ZBXProxyAddresses `json:"proxy_address"`
Interface ProxyInterface `json:"interface,omitempty"`
}
// ProxyInterface Interface information for a Zabbix proxy
// There is no way to query this directly, query for a Zabbix proxy and use SelectInterface
type ProxyInterface struct {
// (readonly) ID of the interface.
InterfaceID string `json:"interfaceid"`
// ID of the host the interface belongs to.
HostID string `json:"hostid"`
// DNS name used by the interface.
DNS string `json:"dns"`
// IP address used by the interface.
IP string `json:"ip"`
// Whether the connection should be made via IP.
UseIP types.ZBXBoolean `json:"useip,string"`
Port int `json:"port,string"`
}
// Handle PHPs empty associative arrays are arrays when turning them into JSON
func (t *ProxyInterface) UnmarshalJSON(in []byte) error {
if bytes.Equal(in, []byte("[]")) {
return nil
}
m := (*ProxyInterface)(t)
return json.Unmarshal(in, m)
}
type ProxyGetParams struct {
GetParameters
ProxyIDs []string `json:"proxyids,omitempty"`
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
SelectInterface SelectQuery `json:"selectInterface,omitempty"`
}
// GetProxies queries the Zabbix API for Proxies matching the given search
// parameters.
//
// ErrEventNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetProxies(params ProxyGetParams) ([]Proxy, error) {
proxies := make([]Proxy, 0)
err := c.Get("proxy.get", params, &proxies)
if err != nil {
return nil, err
}
if len(proxies) == 0 {
return nil, ErrNotFound
}
return proxies, nil
}