forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
383 lines (334 loc) · 15.2 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
package zabbix
// For `ActionObject` field: `Status`
const (
ActionStatusEnabled = 0
ActionStatusDisabled = 1
)
// For `ActionObject` field: `PauseSuppressed`
const (
ActionPauseSuppressedEnabled = 0
ActionPauseSuppressedDisabled = 1
)
// For `ActionOperationObject` field: `OperationType`
const (
ActionOperationTypeSendMsg = 0
ActionOperationTypeRemoteCmd = 1
ActionOperationTypeAddHost = 2
ActionOperationTypeRmHost = 3
ActionOperationTypeAddToHostGroup = 4
ActionOperationTypeRmFromHostGroup = 5
ActionOperationTypeLinkToTpl = 6
ActionOperationTypeUnlinkFromTpl = 7
ActionOperationTypeEnableHost = 8
ActionOperationTypeDisableHost = 9
ActionOperationTypeSetHostInventoryMode = 10
)
// For `ActionOperationObject` field: `EvalType`
const (
ActionOperationEvalTypeAndOR = 0
ActionOperationEvalTypeAnd = 1
ActionOperationEvalTypeOr = 2
)
// For `ActionOperationCommandObject` field: `Type`
const (
ActionOperationCommandTypeCustomScript = 0
ActionOperationCommandTypeIPMI = 1
ActionOperationCommandTypeSSH = 2
ActionOperationCommandTypeTelnet = 3
ActionOperationCommandTypeGlobalScript = 4
)
// For `ActionOperationCommandObject` field: `AuthType`
const (
ActionOperationCommandAuthTypePassword = 0
ActionOperationCommandAuthTypePubKey = 1
)
// For `ActionOperationCommandObject` field: `ExecuteOn`
const (
ActionOperationCommandExecuteOnAgent = 0
ActionOperationCommandExecuteOnServer = 1
ActionOperationCommandExecuteOnProxy = 2
)
// For `ActionOperationMessageObject` field: `DefaultMsg`
const (
ActionOperationMessageDefaultMsgFromOperation = 0
ActionOperationMessageDefaultMsgFromMediaType = 1
)
// For `ActionOperationConditionObject` field: `ConditionType`
const (
ActionOperationConditionTypeEventAcknowledged = 14
)
// For `ActionRecoveryOperationObject` field: `OperationType `
const (
ActionRecoveryOperationTypeSendMsg = 0
ActionRecoveryOperationTypeRemoteCmd = 1
ActionRecoveryOperationTypeNotifyAllInvolved = 11
)
// For `ActionUpdateOperationObject` field: `OperationType `
const (
ActionUpdateOperationTypeSendMsg = 0
ActionUpdateOperationTypeRemoteCmd = 1
ActionUpdateOperationTypeNotifyAllInvolved = 12
)
// For `ActionOperationConditionObject` field: `Operator`
const (
ActionOperationConditionOperatorEq = 0
)
// For `ActionFilterObject` field: `EvalType`
const (
ActionFilterEvalTypeAndOr = 0
ActionFilterEvalTypeAnd = 1
ActionFilterEvalTypeOr = 2
ActionFilterEvalTypeCustom = 3
)
// For `ActionFilterConditionObject` field: `ConditionType`
const (
ActionFilterConditionTypeHostroup = 0
ActionFilterConditionTypeHost = 1
ActionFilterConditionTypeTrigger = 2
ActionFilterConditionTypeTriggerName = 3
ActionFilterConditionTypeTriggerSeverity = 4
ActionFilterConditionTypeTriggerValue = 5
ActionFilterConditionTypeTimePeriod = 6
ActionFilterConditionTypeHostIP = 7
ActionFilterConditionTypeDiscoveryServiceType = 8
ActionFilterConditionTypeDiscoveryServicePort = 9
ActionFilterConditionTypeDiscoveryStatus = 10
ActionFilterConditionTypeUpdownTimeDuration = 11
ActionFilterConditionTypeRcvValue = 12
ActionFilterConditionTypeHostTemplate = 13
ActionFilterConditionTypeApplication = 15
ActionFilterConditionTypeProblemIsSuppressed = 16
ActionFilterConditionTypeDiscRule = 18
ActionFilterConditionTypeDiscCheck = 19
ActionFilterConditionTypeProxy = 20
ActionFilterConditionTypeDiscObject = 21
ActionFilterConditionTypeHostName = 22
ActionFilterConditionTypeEventType = 23
ActionFilterConditionTypeHostMetadata = 24
ActionFilterConditionTypeTag = 25
ActionFilterConditionTypeTagValue = 26
)
// For `ActionFilterConditionObject` field: `Operator`
const (
ActionFilterConditionOperatorEQ = 0 // =
ActionFilterConditionOperatorNE = 1 // <>
ActionFilterConditionOperatorContains = 2 // contains
ActionFilterConditionOperatorNotrContain = 3 // does not contain
ActionFilterConditionOperatorIN = 4 // in
ActionFilterConditionOperatorGE = 5 // >=
ActionFilterConditionOperatorLE = 6 // <=
ActionFilterConditionOperatorNotIn = 7 // not in
ActionFilterConditionOperatorMatches = 8 // matches
ActionFilterConditionOperatorNotMatches = 9 // does not match
ActionFilterConditionOperatorYes = 10 // yes
ActionFilterConditionOperatorNo = 11 // no
)
// ActionObject struct is used to store action operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action
type ActionObject struct {
ActionID int `json:"actionid,omitempty"`
EscPeriod int `json:"esc_period"`
Eventsource int `json:"eventsource"`
Name string `json:"name"`
Status int `json:"status,omitempty"` // has defined consts, see above
PauseSuppressed int `json:"pause_suppressed,omitempty"` // has defined consts, see above
Operations []ActionOperationObject `json:"operations,omitempty"`
Filter ActionFilterObject `json:"filter,omitempty"`
RecoveryOperations []ActionRecoveryOperationObject `json:"recovery_operations,omitempty"`
AcknowledgeOperations []ActionRecoveryOperationObject `json:"acknowledge_operations,omitempty"`
}
// ActionOperationObject struct is used to store action operations
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation
type ActionOperationObject struct {
OperationID int `json:"operationid,omitempty"`
OperationType int `json:"operationtype"` // has defined consts, see above
ActionID int `json:"actionid,omitempty"`
EscPeriod int `json:"esc_period,omitempty"`
EscStepFrom int `json:"esc_step_from,omitempty"`
EscStepTo int `json:"esc_step_to,omitempty"`
EvalType int `json:"evaltype,omitempty"` // has defined consts, see above
Opcommand ActionOperationCommandObject `json:"opcommand,omitempty"`
OpcommandGrp []ActionOpcommandGrpObject `json:"opcommand_grp,omitempty"`
OpcommandHst []ActionOpcommandHstObject `json:"opcommand_hst,omitempty"`
Opconditions []ActionOperationConditionObject `json:"opconditions,omitempty"`
Opgroup []ActionOpgroupObject `json:"opgroup,omitempty"`
Opmessage ActionOperationMessageObject `json:"opmessage,omitempty"`
OpmessageGrp []ActionOpmessageGrpObject `json:"opmessage_grp,omitempty"`
OpmessageUsr []ActionOpmessageUsrObject `json:"opmessage_usr,omitempty"`
Optemplate []ActionOptemplateObject `json:"optemplate,omitempty"`
Opinventory ActionOpinventoryObject `json:"opinventory,omitempty"`
}
// ActionOperationCommandObject struct is used to store action operation commands
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_command
type ActionOperationCommandObject struct {
Command string `json:"command"`
Type int `json:"type"` // has defined consts, see above
AuthType int `json:"authtype,omitempty"` // has defined consts, see above
ExecuteOn int `json:"execute_on,omitempty"` // has defined consts, see above
Password string `json:"password,omitempty"`
Port string `json:"port,omitempty"`
PrivateKey string `json:"privatekey,omitempty"`
PublicKey string `json:"publickey,omitempty"`
ScriptID int `json:"scriptid,omitempty"`
UserName string `json:"username,omitempty"`
}
// ActionOperationMessageObject struct is used to store action operation messages
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_message
type ActionOperationMessageObject struct {
DefaultMsg int `json:"default_msg,omitempty"` // has defined consts, see above
MediatypeID int `json:"mediatypeid,omitempty"`
Message string `json:"message,omitempty"`
Subject string `json:"subject,omitempty"`
}
// ActionOperationConditionObject struct is used to store action operation conditions
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_operation_condition
type ActionOperationConditionObject struct {
OpconditionID int `json:"opconditionid,omitempty"`
ConditionType int `json:"conditiontype"` // has defined consts, see above
Value string `json:"value"`
OperationID int `json:"operationid,omitempty"`
Operator int `json:"operator,omitempty"`
}
// ActionRecoveryOperationObject struct is used to store action recovery operations
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_recovery_operation
type ActionRecoveryOperationObject struct {
OperationID int `json:"operationid"`
OperationType int `json:"operationtype,omitempty"` // has defined consts, see above
ActionID int `json:"actionid,omitempty"`
Opcommand ActionOperationCommandObject `json:"opcommand,omitempty"`
OpcommandGrp []ActionOpcommandGrpObject `json:"opcommand_grp,omitempty"`
OpcommandHst []ActionOpcommandHstObject `json:"opcommand_hst,omitempty"`
Opmessage ActionOperationMessageObject `json:"opmessage,omitempty"`
OpmessageGrp []ActionOpmessageGrpObject `json:"opmessage_grp,omitempty"`
OpmessageUsr []ActionOpmessageUsrObject `json:"opmessage_usr,omitempty"`
}
// ActionUpdateOperationObject struct is used to store action update operations
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_update_operation
type ActionUpdateOperationObject struct {
OperationID int `json:"operationid"`
OperationType int `json:"operationtype,omitempty"` // has defined consts, see above
Opcommand ActionOperationCommandObject `json:"opcommand,omitempty"`
OpcommandGrp []ActionOpcommandGrpObject `json:"opcommand_grp,omitempty"`
OpcommandHst []ActionOpcommandHstObject `json:"opcommand_hst,omitempty"`
Opmessage ActionOperationMessageObject `json:"opmessage,omitempty"`
OpmessageGrp []ActionOpmessageGrpObject `json:"opmessage_grp,omitempty"`
OpmessageUsr []ActionOpmessageUsrObject `json:"opmessage_usr,omitempty"`
}
// ActionFilterObject struct is used to store action filters
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter
type ActionFilterObject struct {
Conditions []ActionFilterConditionObject `json:"conditions"`
EvalType int `json:"evaltype"` // has defined consts, see above
EvalFormula string `json:"eval_formula,omitempty"`
Formula string `json:"formula,omitempty"`
}
// ActionFilterConditionObject struct is used to store action filter conditions
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/object#action_filter_condition
type ActionFilterConditionObject struct {
ConditionID int `json:"conditionid,omitempty"`
ConditionType int `json:"conditiontype"` // has defined consts, see above
Value string `json:"value"`
Value2 string `json:"value2,omitempty"`
ActionID int `json:"actionid,omitempty"`
FormulaID string `json:"formulaid,omitempty"`
Operator int `json:"operator,omitempty"` // has defined consts, see above
}
// ActionOpcommandGrpObject struct is used to store action opcommand groups
type ActionOpcommandGrpObject struct {
OpcommandGrpID int `json:"opcommand_grpid,omitempty"`
OperationID int `json:"operationid,omitempty"`
GroupID int `json:"groupid,omitempty"`
}
// ActionOpcommandHstObject struct is used to store action opcommand hosts
type ActionOpcommandHstObject struct {
OpcommandHstID int `json:"opcommand_hstid,omitempty"`
OperationID int `json:"operationid,omitempty"`
HostID int `json:"hostid,omitempty"`
}
// ActionOpgroupObject struct is used to store action opgroups
type ActionOpgroupObject struct {
OperationID int `json:"operationid,omitempty"`
GroupID int `json:"groupid,omitempty"`
}
// ActionOpmessageGrpObject struct is used to store action opmessage groups
type ActionOpmessageGrpObject struct {
OperationID int `json:"operationid,omitempty"`
UsrgrpID int `json:"usrgrpid,omitempty"`
}
// ActionOpmessageUsrObject struct is used to store action opmessage users
type ActionOpmessageUsrObject struct {
OperationID int `json:"operationid,omitempty"`
UserID int `json:"userid,omitempty"`
}
// ActionOptemplateObject struct is used to store action optemplates
type ActionOptemplateObject struct {
OperationID int `json:"operationid,omitempty"`
TemplateID int `json:"templateid,omitempty"`
}
// ActionOpinventoryObject struct is used to store action opinventory
type ActionOpinventoryObject struct {
OperationID int `json:"operationid,omitempty"`
InventoryMode int `json:"inventory_mode,omitempty"`
}
// ActionGetParams struct is used for action get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/action/get#parameters
type ActionGetParams struct {
GetParameters
ActionIDs []int `json:"actionids,omitempty"`
GroupIDs []int `json:"groupids,omitempty"`
HostIDs []int `json:"hostids,omitempty"`
TriggerIDs []int `json:"triggerids,omitempty"`
MediatypeIDs []int `json:"mediatypeids,omitempty"`
UsrgrpIDs []int `json:"usrgrpids,omitempty"`
UserIDs []int `json:"userids,omitempty"`
ScriptIDs []int `json:"scriptids,omitempty"`
SelectFilter SelectQuery `json:"selectFilter,omitempty"`
SelectOperations SelectQuery `json:"selectOperations,omitempty"`
SelectRecoveryOperations SelectQuery `json:"selectRecoveryOperations,omitempty"`
SelectUpdateOperations SelectQuery `json:"selectUpdateOperations,omitempty"`
}
// Structure to store creation result
type actionCreateResult struct {
ActionIDs []int `json:"actionids"`
}
// Structure to store deletion result
type actionDeleteResult struct {
ActionIDs []int `json:"actionids"`
}
// ActionGet gets actions
func (z *Context) ActionGet(params ActionGetParams) ([]ActionObject, int, error) {
var result []ActionObject
status, err := z.request("action.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// ActionCreate creates actions
func (z *Context) ActionCreate(params []ActionObject) ([]int, int, error) {
var result actionCreateResult
status, err := z.request("action.create", params, &result)
if err != nil {
return nil, status, err
}
return result.ActionIDs, status, nil
}
// ActionDelete deletes actions
func (z *Context) ActionDelete(actionIDs []int) ([]int, int, error) {
var result actionDeleteResult
status, err := z.request("action.delete", actionIDs, &result)
if err != nil {
return nil, status, err
}
return result.ActionIDs, status, nil
}