-
Notifications
You must be signed in to change notification settings - Fork 15
/
history.go
111 lines (96 loc) · 3.54 KB
/
history.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
package zabbix
import "fmt"
// For `HistoryGetParams` field: `History`
const (
HistoryObjectTypeFloat = 0
HistoryObjectTypeCharacter = 1
HistoryObjectTypeLog = 2
HistoryObjectTypeNumericUnsigned = 3
HistoryObjectTypeText = 4
)
// HistoryFloatObject struct is used to store history float operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#float_history
type HistoryFloatObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
NS int `json:"ns,omitempty"`
Value float64 `json:"value,omitempty"`
}
// HistoryIntegerObject struct is used to store history integer operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#integer_history
type HistoryIntegerObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
NS int `json:"ns,omitempty"`
Value int `json:"value,omitempty"`
}
// HistoryStringObject struct is used to store history string operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#string_history
type HistoryStringObject struct {
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
NS int `json:"ns,omitempty"`
Value string `json:"value,omitempty"`
}
// HistoryTextObject struct is used to store history text operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#text_history
type HistoryTextObject struct {
ID int `json:"id,omitempty"`
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
NS int `json:"ns,omitempty"`
Value string `json:"value,omitempty"`
}
// HistoryLogObject struct is used to store history log operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/object#log_history
type HistoryLogObject struct {
ID int `json:"id,omitempty"`
Clock int `json:"clock,omitempty"`
ItemID int `json:"itemid,omitempty"`
LogeventID int `json:"logeventid,omitempty"`
NS int `json:"ns,omitempty"`
Severity int `json:"severity,omitempty"`
Source int `json:"source,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
Value string `json:"value,omitempty"`
}
// HistoryGetParams struct is used for history get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/history/get#parameters
type HistoryGetParams struct {
GetParameters
History int `json:"history"` // has defined consts, see above
HostIDs []int `json:"hostids,omitempty"`
ItemIDs []int `json:"itemids,omitempty"`
TimeFrom int `json:"time_from,omitempty"`
TimeTill int `json:"time_till,omitempty"`
Sortfield string `json:"sortfield,omitempty"`
}
// HistoryGet gets history
func (z *Context) HistoryGet(params HistoryGetParams) (interface{}, int, error) {
var result interface{}
switch params.History {
case HistoryObjectTypeFloat:
result = &([]HistoryFloatObject{})
case HistoryObjectTypeCharacter:
result = &([]HistoryStringObject{})
case HistoryObjectTypeLog:
result = &([]HistoryLogObject{})
case HistoryObjectTypeNumericUnsigned:
result = &([]HistoryIntegerObject{})
case HistoryObjectTypeText:
result = &([]HistoryTextObject{})
default:
return nil, 0, fmt.Errorf("Unknown history type")
}
status, err := z.request("history.get", params, result)
if err != nil {
return nil, status, err
}
return result, status, nil
}