forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hostinterface.go
151 lines (123 loc) · 4.94 KB
/
hostinterface.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package zabbix
// For `HostinterfaceObject` field: `Main`
const (
HostinterfaceMainNotDefault = 0
HostinterfaceMainDefault = 1
)
// For `HostinterfaceObject` field: `Type`
const (
HostinterfaceTypeAgent = 1
HostinterfaceTypeSNMP = 2
HostinterfaceTypeIPMI = 3
HostinterfaceTypeJMX = 4
)
// For `HostinterfaceObject` field: `UseIP`
const (
HostinterfaceUseipDNS = 0
HostinterfaceUseipIP = 1
)
// For `HostinterfaceDetailsTagObject` field: `Bulk`
const (
HostinterfaceDetailsTagBulkDontUse = 0
HostinterfaceDetailsTagBulkUse = 1
)
// For `HostinterfaceDetailsTagObject` field: `Version`
const (
HostinterfaceDetailsTagVersionSNMPv1 = 1
HostinterfaceDetailsTagVersionSNMPv2c = 2
HostinterfaceDetailsTagVersionSNMPv3 = 3
)
// For `HostinterfaceDetailsTagObject` field: `SecurityLevel`
const (
HostinterfaceDetailsTagSecurityLevelNoAuthNoPriv = 0
HostinterfaceDetailsTagSecurityLevelAuthNoPriv = 1
HostinterfaceDetailsTagSecurityLevelAuthPriv = 2
)
// For `HostinterfaceDetailsTagObject` field: `AuthProtocol`
const (
HostinterfaceDetailsTagAuthProtocolMD5 = 0
HostinterfaceDetailsTagAuthProtocolSHA = 1
)
// For `HostinterfaceDetailsTagObject` field: `PrivProtocol`
const (
HostinterfaceDetailsTagPrivProtocolDES = 0
HostinterfaceDetailsTagPrivProtocolAES = 1
)
// HostinterfaceObject struct is used to store hostinterface operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostinterface/object#hostinterface
type HostinterfaceObject struct {
InterfaceID int `json:"interfaceid,omitempty"`
DNS string `json:"dns"`
HostID int `json:"hostid,omitempty"`
IP string `json:"ip"`
Main int `json:"main"` // has defined consts, see above
Port string `json:"port"`
Type int `json:"type"` // has defined consts, see above
UseIP int `json:"useip"` // has defined consts, see above
Details []HostinterfaceDetailsTagObject `json:"details,omitempty"`
// Items []ItemObject `json:"items,omitempty"` // not implemented yet
Hosts []HostObject `json:"hosts,omitempty"`
}
// HostinterfaceDetailsTagObject struct is used to store hostinterface details
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostinterface/object#details_tag
type HostinterfaceDetailsTagObject struct {
Version int `json:"version,omitempty"` // has defined consts, see above
Bulk int `json:"bulk,omitempty"` // has defined consts, see above
Community string `json:"community,omitempty"`
SecurityName string `json:"securityname,omitempty"`
SecurityLevel int `json:"securitylevel,omitempty"` // has defined consts, see above
AuthPassPhrase string `json:"authpassphrase,omitempty"`
PrivPassPhrase string `json:"privpassphrase,omitempty"`
AuthProtocol int `json:"authprotocol,omitempty"` // has defined consts, see above
PrivProtocol int `json:"privprotocol,omitempty"` // has defined consts, see above
ContextName string `json:"contextname,omitempty"`
}
// HostinterfaceGetParams struct is used for hostinterface get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/hostinterface/get#parameters
type HostinterfaceGetParams struct {
GetParameters
HostIDs []int `json:"hostids,omitempty"`
InterfaceIDs []int `json:"interfaceids,omitempty"`
ItemIDs []int `json:"itemids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`
// SelectItems SelectQuery `json:"selectItems,omitempty"` // not implemented yet
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
}
// Structure to store creation result
type hostinterfaceCreateResult struct {
InterfaceIDs []int `json:"interfaceids"`
}
// Structure to store deletion result
type hostinterfaceDeleteResult struct {
InterfaceIDs []int `json:"interfaceids"`
}
// HostinterfaceGet gets hostinterfaces
func (z *Context) HostinterfaceGet(params HostinterfaceGetParams) ([]HostinterfaceObject, int, error) {
var result []HostinterfaceObject
status, err := z.request("hostinterface.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// HostinterfaceCreate creates hostinterfaces
func (z *Context) HostinterfaceCreate(params []HostinterfaceObject) ([]int, int, error) {
var result hostinterfaceCreateResult
status, err := z.request("hostinterface.create", params, &result)
if err != nil {
return nil, status, err
}
return result.InterfaceIDs, status, nil
}
// HostinterfaceDelete deletes hostinterfaces
func (z *Context) HostinterfaceDelete(hostinterfaceIDs []int) ([]int, int, error) {
var result hostinterfaceDeleteResult
status, err := z.request("hostinterface.delete", hostinterfaceIDs, &result)
if err != nil {
return nil, status, err
}
return result.InterfaceIDs, status, nil
}