forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitem.go
131 lines (99 loc) · 3.94 KB
/
item.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
package zabbix
// Item represents a Zabbix Item returned from the Zabbix API.
//
// See: https://www.zabbix.com/documentation/4.0/manual/api/reference/item/object
type Item struct {
// Error is the error text indicating any problems with updating the item.
Error string `json:"error,omitempty"`
// HostID is the unique ID of the Host.
HostID string `json:"hostid,omitempty"`
// ItemID is the unique ID of the Item.
ItemID string `json:"itemid"`
// ItemKey is the key name of the item.
ItemKey string `json:"key_"`
// Itemname is the technical name of the Item.
ItemName string `json:"name"`
// ItemDescr is the description of the Item.
ItemDescr string `json:"description,omitempty"`
// LastClock is the last Item epoh time.
LastClock int `json:"lastclock,string,omitempty"`
// LastValue is the last value of the Item.
LastValue string `json:"lastvalue,omitempty"`
// LastValueType is the type of LastValue
// 0 - float; 1 - text; 3 - int;
LastValueType int `json:"value_type,string"`
}
type ItemTagFilter struct {
Tag string `json:"tag"`
Value string `json:"value"`
Operator int `json:"operator"`
}
type ItemGetParams struct {
GetParameters
// ItemIDs filters search results to items with the given Item ID's.
ItemIDs []string `json:"itemids,omitempty"`
// GroupIDs filters search results to items belong to the hosts
// of the given Group ID's.
GroupIDs []string `json:"groupids,omitempty"`
// TemplateIDs filters search results to items belong to the
// given templates of the given Template ID's.
TemplateIDs []string `json:"templateids,omitempty"`
// HostIDs filters search results to items belong to the
// given Host ID's.
HostIDs []string `json:"hostids,omitempty"`
// ProxyIDs filters search results to items that are
// monitored by the given Proxy ID's.
ProxyIDs []string `json:"proxyids,omitempty"`
// InterfaceIDs filters search results to items that use
// the given host Interface ID's.
InterfaceIDs []string `json:"interfaceids,omitempty"`
// GraphIDs filters search results to items that are used
// in the given graph ID's.
GraphIDs []string `json:"graphids,omitempty"`
// TriggerIDs filters search results to items that are used
// in the given Trigger ID's.
TriggerIDs []string `json:"triggerids,omitempty"`
// ApplicationIDs filters search results to items that
// belong to the given Applications ID's.
ApplicationIDs []string `json:"applicationids,omitempty"`
// WebItems flag includes web items in the result.
WebItems bool `json:"webitems,omitempty"`
// Inherited flag return only items inherited from a template
// if set to 'true'.
Inherited bool `json:"inherited,omitempty"`
// Templated flag return only items that belong to templates
// if set to 'true'.
Templated bool `json:"templated,omitempty"`
// Monitored flag return only enabled items that belong to
// monitored hosts if set to 'true'.
Monitored bool `json:"monitored,omitempty"`
// Group filters search results to items belong to a group
// with the given name.
Group string `json:"group,omitempty"`
// Host filters search results to items that belong to a host
// with the given name.
Host string `json:"host,omitempty"`
// Application filters search results to items that belong to
// an application with the given name.
Application string `json:"application,omitempty"`
// WithTriggers flag return only items that are used in triggers
WithTriggers bool `json:"with_triggers,omitempty"`
// Filter by tags
Tags []ItemTagFilter `json:"tags,omitempty"`
}
// GetItems queries the Zabbix API for Items 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) GetItems(params ItemGetParams) ([]Item, error) {
items := make([]Item, 0)
err := c.Get("item.get", params, &items)
if err != nil {
return nil, err
}
if len(items) == 0 {
return nil, ErrNotFound
}
return items, nil
}