forked from neogan74/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostinterface.go
141 lines (112 loc) · 4.13 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
package zabbix
import (
"fmt"
)
const (
// HostInterfaceTypeAgent represents the host interface flag for Agent type
HostInterfaceTypeAgent = 1
// HostInterfaceTypeSNMP represents the host interface flag for SNMP type
HostInterfaceTypeSNMP = 2
// HostInterfaceTypeIPMI represents the host interface flag for IPMI type
HostInterfaceTypeIPMI = 3
// HostInterfaceTypeJMX represents the host interface flag for JMX type
HostInterfaceTypeJMX = 4
)
const (
// HostInterfaceNotDefault represents the host interface flag when it not delfaut
HostInterfaceNotDefault = 0
// HostInterfaceDefault represents the host interface flag when if delfaut
HostInterfaceDefault = 1
)
const (
// HostInterfaceConnTypeDNS represents the host interface type flag when
// DNS name is default for performing the connection
HostInterfaceConnTypeDNS = "0"
// HostInterfaceConnTypeIP represents the host interface type flag when
// IP address is default for performing the connection
HostInterfaceConnTypeIP = "1"
)
const (
// HostInterfaceBulkDisabled represents SNMP host interface parameter for
// Disable state of SNMP Bulk polling
HostInterfaceBulkDisabled = 0
// HostInterfaceBulkEnabled represents SNMP host interface parameter for
// Enable state of SNMP Bulk polling
HostInterfaceBulkEnabled = 1
)
// HostInterface represents a Zabbix HostInterface returned from the Zabbix API.
//
// See: https://www.zabbix.com/documentation/3.4/manual/api/reference/hostinterface/object
type HostInterface struct {
// ID of the interface.
InterfaceID string `json:"interfaceid,omitempty"`
// DNS name used by the interface.
// Can be empty if the connection is made via IP.
DNS string `json:"dns,omitempty"`
// IP address used by the interface.
// Can be empty if the connection is made via DNS.
IP string `json:"ip,omitempty"`
// ID of the host the interface belongs to.
HostID string `json:"hostid,omitempty"`
// Whether the interface is used as default on the host.
//
// Default must be HostInterfaceDefault or HostInterfaceNotDefault
Default int `json:"main,string,omitempty"`
// Port number used by the interface.
Port string `json:"port,omitempty"`
// Interface type.
//
// Type must be one of the HostInterfaceType constants.
Type int `json:"type,string,omitempty"`
// Whether the connection should be made via IP.
//
// Type must be one of the HostInterfaceConnType constants.
ConnectionType string `json:"useip,omitempty"`
// Whether to use bulk SNMP requests.
//
// Type must be one of the HostInterfaceBulk constants.
Bulk int `json:"bulk,string,omitempty"`
// Host that uses the interface.
Host Host `json:"hosts,omitempty"`
// TODO
// Items []Item `json:"items,omitempty"`
}
// HostInterfaces represents the slice of Host interfaces returned from Zabbix API
type HostInterfaces []HostInterface
// HostInterfaceGetParams represent the parameters for a `hostinterface.get` API call.
//
// See: https://www.zabbix.com/documentation/3.4/manual/api/reference/hostinterface/get
type HostInterfaceGetParams struct {
GetParameters
InterfaceIDs []string `json:"interfaceids,omitempty"`
HostIDs []string `json:"hostids,omitempty"`
ItemIDs []string `json:"itemids,omitempty"`
TriggerIDs []string `json:"triggerids,omitempty"`
SelectItems SelectQuery `json:"selectItems,omitempty"`
SelectHosts SelectQuery `json:"selectHosts,omitempty"`
}
// GetHostInterfaces queries the Zabbix API for Host interfaces matching the given search
// parameters.
//
// ErrNotFound is returned if the search result set is empty.
// An error is returned if a transport, parsing or API error occurs.
func (c *Session) GetHostInterfaces(params HostInterfaceGetParams) ([]HostInterface, error) {
hostifs := make([]jHostInterface, 0)
err := c.Get("hostinterface.get", params, &hostifs)
if err != nil {
return nil, err
}
if len(hostifs) == 0 {
return nil, ErrNotFound
}
// map JSON HostInterfaces to Go HostInterfaces
out := make([]HostInterface, len(hostifs))
for i, jhostif := range hostifs {
hostif, err := jhostif.HostInterface()
if err != nil {
return nil, fmt.Errorf("Error mapping HostInterface %d in response: %v", i, err)
}
out[i] = *hostif
}
return out, nil
}