forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
145 lines (107 loc) · 5 KB
/
host.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
package zabbix
const (
// HostSourceDefault indicates that a Host was created in the normal way.
HostSourceDefault = 0
// HostSourceDiscovery indicates that a Host was created by Host discovery.
HostSourceDiscovery = 4
)
// Host represents a Zabbix Host returned from the Zabbix API.
//
// See: https://www.zabbix.com/documentation/2.2/manual/config/hosts
type Host struct {
// HostID is the unique ID of the Host.
HostID string `json:"hostid"`
// Hostname is the technical name of the Host.
Hostname string `json:"host"`
// DisplayName is the visible name of the Host.
DisplayName string `json:"name,omitempty"`
// Source is the origin of the Host and must be one of the HostSource
// constants.
Source int `json:"flags,string,omitempty"`
// Macros contains all Host Macros assigned to the Host.
Macros []HostMacro `json:"macros,omitempty"`
// Groups contains all Host Groups assigned to the Host.
Groups []Hostgroup `json:"groups,omitempty"`
MaintenanceStatus string `json:"maintenance_status"`
MaintenanceID string `json:"maintenanceid"`
MaintenanceType string `json:"maintenance_type"`
MaintenanceFrom string `json:"maintenance_from"`
}
// HostGetParams represent the parameters for a `host.get` API call.
//
// See: https://www.zabbix.com/documentation/2.2/manual/api/reference/host/get#parameters
type HostGetParams struct {
GetParameters
// GroupIDs filters search results to hosts that are members of the given
// Group IDs.
GroupIDs []string `json:"groupids,omitempty"`
// ApplicationIDs filters search results to hosts that have items in the
// given Application IDs.
ApplicationIDs []string `json:"applicationids,omitempty"`
// DiscoveredServiceIDs filters search results to hosts that are related to
// the given discovered service IDs.
DiscoveredServiceIDs []string `json:"dserviceids,omitempty"`
// GraphIDs filters search results to hosts that have the given graph IDs.
GraphIDs []string `json:"graphids,omitempty"`
// HostIDs filters search results to hosts that matched the given Host IDs.
HostIDs []string `json:"hostids,omitempty"`
// WebCheckIDs filters search results to hosts with the given Web Check IDs.
WebCheckIDs []string `json:"httptestids,omitempty"`
// InterfaceIDs filters search results to hosts that use the given Interface
// IDs.
InterfaceIDs []string `json:"interfaceids,omitempty"`
// ItemIDs filters search results to hosts with the given Item IDs.
ItemIDs []string `json:"itemids,omitempty"`
// MaintenanceIDs filters search results to hosts that are affected by the
// given Maintenance IDs
MaintenanceIDs []string `json:"maintenanceids,omitempty"`
// MonitoredOnly filters search results to return only monitored hosts.
MonitoredOnly bool `json:"monitored_hosts,omitempty"`
// ProxyOnly filters search results to hosts which are Zabbix proxies.
ProxiesOnly bool `json:"proxy_host,omitempty"`
// ProxyIDs filters search results to hosts monitored by the given Proxy
// IDs.
ProxyIDs []string `json:"proxyids,omitempty"`
// IncludeTemplates extends search results to include Templates.
IncludeTemplates bool `json:"templated_hosts,omitempty"`
// SelectGroups causes the Host Groups that each Host belongs to to be
// attached in the search results.
SelectGroups SelectQuery `json:"selectGroups,omitempty"`
// SelectApplications causes the Applications from each Host to be attached
// in the search results.
SelectApplications SelectQuery `json:"selectApplications,omitempty"`
// SelectDiscoveries causes the Low-Level Discoveries from each Host to be
// attached in the search results.
SelectDiscoveries SelectQuery `json:"selectDiscoveries,omitempty"`
// SelectDiscoveryRule causes the Low-Level Discovery Rule that created each
// Host to be attached in the search results.
SelectDiscoveryRule SelectQuery `json:"selectDiscoveryRule,omitempty"`
// SelectGraphs causes the Graphs from each Host to be attached in the
// search results.
SelectGraphs SelectQuery `json:"selectGraphs,omitempty"`
SelectHostDiscovery SelectQuery `json:"selectHostDiscovery,omitempty"`
SelectWebScenarios SelectQuery `json:"selectHttpTests,omitempty"`
SelectInterfaces SelectQuery `json:"selectInterfaces,omitempty"`
SelectInventory SelectQuery `json:"selectInventory,omitempty"`
SelectItems SelectQuery `json:"selectItems,omitempty"`
SelectMacros SelectQuery `json:"selectMacros,omitempty"`
SelectParentTemplates SelectQuery `json:"selectParentTemplates,omitempty"`
SelectScreens SelectQuery `json:"selectScreens,omitempty"`
SelectTriggers SelectQuery `json:"selectTriggers,omitempty"`
}
// GetHosts queries the Zabbix API for Hosts 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) GetHosts(params HostGetParams) ([]Host, error) {
hosts := make([]Host, 0)
err := c.Get("host.get", params, &hosts)
if err != nil {
return nil, err
}
if len(hosts) == 0 {
return nil, ErrNotFound
}
return hosts, nil
}