forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
117 lines (94 loc) · 3.39 KB
/
action.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
package zabbix
import (
"github.com/fabiang/go-zabbix/types"
)
const (
// ActionEvalTypeAndOr indicated that an Action will evaluate its conditions
// using AND/OR bitwise logic.
ActionEvalTypeAndOr = iota
// ActionEvalTypeAnd indicated that an Action will evaluate its conditions
// using AND bitwise logic.
ActionEvalTypeAnd
// ActionEvalTypeOr indicated that an Action will evaluate its conditions
// using OR bitwise logic.
ActionEvalTypeOr
)
// Action represents a Zabbix Action returned from the Zabbix API.
//
// See: https://www.zabbix.com/documentation/2.2/manual/config/notifications/action
type Action struct {
// ActionID is the unique ID of the Action.
ActionID string `json:"actionid"`
// StepDuration is the interval in seconds between each operation step.
StepDuration types.ZBXDuration `json:"esc_period"`
// EvaluationType determines the bitwise logic used to evaluate the Actions
// conditions.
//
// EvaluationType must be one of the ActionEvalType constants.
//
// EvaluationType is only supported up to Zabbix v2.2.
// EvaluationType Removed in Zabbix 5.0
EvaluationType int `json:"evaltype,string"`
// EventType is the type of Events that this Action will handle.
//
// Source must be one of the EventSource constants.
EventType int `json:"eventsource,string"`
// Name is the name of the Action.
Name string `json:"name"`
// ProblemMessageBody is the message body text to be submitted for this
// Action.
//
// ProblemMessageBody Removed in Zabbix 5.0
ProblemMessageBody string `json:"def_longdata"`
// ProblemMessageSubject is the short summary text to be submitted for this
// Action.
//
// ProblemMessageSubject Removed in Zabbix 5.0
ProblemMessageSubject string `json:"def_shortdata"`
// RecoveryMessageBody is the message body text to be submitted for this
// Action.
//
// RecoveryMessageBody Removed in Zabbix 5.0
RecoveryMessageBody string `json:"r_longdata"`
// RecoveryMessageSubject is the short summary text to be submitted for this
// Action.
//
// RecoveryMessageSubject Removed in Zabbix 5.0
RecoveryMessageSubject string `json:"r_shortdata"`
// RecoveryMessageEnabled determines whether recovery messages will be
// submitted for the Action when the source problem is resolved.
//
// RecoveryMessageEnabled Removed in Zabbix 5.0
RecoveryMessageEnabled types.ZBXBoolean `json:"recovery_msg,string"`
// Enabled determines whether the Action is enabled or disabled.
Enabled types.ZBXBoolean `json:"status,string"`
// Conditions are the conditions which must be met for this Action to
// execute.
Conditions []ActionCondition
// Operations are the operations which will be exectuted for this Action.
Operations []ActionOperation
}
// ActionCondition is action condition
type ActionCondition struct{}
// ActionOperation is action operation
type ActionOperation struct{}
// ActionGetParams is query params for action.get call
type ActionGetParams struct {
GetParameters
}
// GetActions queries the Zabbix API for Actions 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) GetActions(params ActionGetParams) ([]Action, error) {
actions := make([]Action, 0)
err := c.Get("action.get", params, &actions)
if err != nil {
return nil, err
}
if len(actions) == 0 {
return nil, ErrNotFound
}
return actions, nil
}