forked from AlekSi/zabbix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger.go
50 lines (42 loc) · 1.34 KB
/
trigger.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
package zabbix
type (
PriorityType int
)
const (
Default PriorityType = 0
Information PriorityType = 1
Warning PriorityType = 2
Average PriorityType = 3
High PriorityType = 4
Disaster PriorityType = 5
)
// https://www.zabbix.com/documentation/2.0/manual/appendix/api/trigger/definitions
type Trigger struct {
TriggerId string `json:"triggerid,omitempty"`
Description string `json:"description"`
Expression string `json:"expression"`
Comments string `json:"comments,omitempty"`
Priority PriorityType `json:"priority,omitempty"`
}
// Wrapper for trigger.eists: https://www.zabbix.com/documentation/2.0/manual/appendix/api/trigger/exists
func (api *API) TriggerExists(trigger Trigger) (bool, error) {
response, err := api.CallWithError("trigger.exists", trigger)
if err != nil {
return false, err
}
result := response.Result.(bool)
return result, err
}
// Wrapper for trigger.create: https://www.zabbix.com/documentation/2.0/manual/appendix/api/trigger/create
func (api *API) TriggerCreate(trigger Trigger) (err error) {
response, err := api.CallWithError("trigger.create", trigger)
if err != nil {
return
}
result := response.Result.(map[string]interface{})
triggerids := result["triggerids"].([]interface{})
for _, id := range triggerids {
trigger.TriggerId = id.(string)
}
return
}