forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediatype.go
192 lines (160 loc) · 7.16 KB
/
mediatype.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
package zabbix
// For `MediatypeObject` field: `Type`
const (
MediatypeEmail = 0
MediatypeScript = 1
MediatypeSMS = 2
MediatypeWebhook = 4
)
// For `MediatypeObject` field: `SMTPSecurity`
const (
MediatypeSMTPSecurityNone = 0
MediatypeSMTPSecuritySTARTTLS = 1
MediatypeSMTPSecuritySSLTLS = 2
)
// For `MediatypeObject` field: `SMTPVerifyHost`
const (
MediatypeSMTPVerifyHostNo = 0
MediatypeSMTPVerifyHostYes = 1
)
// For `MediatypeObject` field: `SMTPVerifyPeer`
const (
MediatypeSMTPVerifyPeerNo = 0
MediatypeSMTPVerifyPeerYes = 1
)
// For `MediatypeObject` field: `SMTPAuthentication`
const (
MediatypeSMTPAuthenticationNone = 0
MediatypeSMTPAuthenticationNormalPassword = 1
)
// For `MediatypeObject` field: `Status`
const (
MediatypeStatusEnabled = 0
MediatypeScriptDisabled = 1
)
// For `MediatypeObject` field: `ContentType`
const (
MediatypeContentTypePlainText = 0
MediatypeContentTypeHTML = 1
)
// For `MediatypeObject` field: `ProcessTags`
const (
MediatypeProcessTagsNo = 0
MediatypeProcessTagsYes = 1
)
// For `MediatypeObject` field: `ShowEventMenu`
const (
MediatypeShowEventMenuNo = 0
MediatypeShowEventMenuYes = 1
)
// For `MediatypeMessageTemplateObject` field: `EventSource`
const (
MediatypeMessageTemplateEventSourceTriggers = 0
MediatypeMessageTemplateEventSourceDiscovery = 1
MediatypeMessageTemplateEventSourceAutoregistration = 2
MediatypeMessageTemplateEventSourceInternal = 3
)
// For `MediatypeMessageTemplateObject` field: `Recovery`
const (
MediatypeMessageTemplateRecoveryOperations = 0
MediatypeMessageTemplateRecoveryRecoveryOperations = 1
MediatypeMessageTemplateRecoveryUpdateOperations = 2
)
// MediatypeObject struct is used to store mediatype operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/mediatype/object
type MediatypeObject struct {
MediatypeID int `json:"mediatypeid,omitempty"`
Name string `json:"name,omitempty"`
Type int `json:"type,omitempty"` // has defined consts, see above
ExecPath string `json:"exec_path,omitempty"`
GsmModem string `json:"gsm_modem,omitempty"`
Passwd string `json:"passwd,omitempty"`
SMTPEmail string `json:"smtp_email,omitempty"`
SMTPHelo string `json:"smtp_helo,omitempty"`
SMTPServer string `json:"smtp_server,omitempty"`
SMTPPort int `json:"smtp_port,omitempty"`
SMTPSecurity int `json:"smtp_security,omitempty"` // has defined consts, see above
SMTPVerifyHost int `json:"smtp_verify_host,omitempty"` // has defined consts, see above
SMTPVerifyPeer int `json:"smtp_verify_peer,omitempty"` // has defined consts, see above
SMTPAuthentication int `json:"smtp_authentication,omitempty"` // has defined consts, see above
Status int `json:"status,omitempty"` // has defined consts, see above
Username string `json:"username,omitempty"`
ExecParams string `json:"exec_params,omitempty"`
MaxSessions int `json:"maxsessions,omitempty"`
MaxAttempts int `json:"maxattempts,omitempty"`
AttemptInterval string `json:"attempt_interval,omitempty"`
ContentType int `json:"content_type,omitempty"` // has defined consts, see above
Script string `json:"script,omitempty"`
Timeout string `json:"timeout,omitempty"`
ProcessTags int `json:"process_tags,omitempty"` // has defined consts, see above
ShowEventMenu int `json:"show_event_menu,omitempty"` // has defined consts, see above
EventMenuURL string `json:"event_menu_url,omitempty"`
EventMenuName string `json:"event_menu_name,omitempty"`
Parameters []MediatypeWebhookParametersObject `json:"parameters,omitempty"`
Description string `json:"description,omitempty"`
MessageTemplates []MediatypeMessageTemplateObject `json:"message_templates,omitempty"`
Users []UserObject `json:"users,omitempty"`
}
// MediatypeWebhookParametersObject struct is used for mediatypes webhook parameters
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/mediatype/object#webhook_parameters
type MediatypeWebhookParametersObject struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
// MediatypeMessageTemplateObject struct is used for mediatypes message template
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/mediatype/object#message_template
type MediatypeMessageTemplateObject struct {
EventSource int `json:"eventsource"` // has defined consts, see above
Recovery int `json:"recovery"` // has defined consts, see above
Subject string `json:"subject,omitempty"`
Message string `json:"message,omitempty"`
}
// MediatypeGetParams struct is used for mediatype get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/mediatype/get#parameters
type MediatypeGetParams struct {
GetParameters
MediatypeIDs []int `json:"mediatypeids,omitempty"`
MediaIDs []int `json:"mediaids,omitempty"`
UserIDs []int `json:"userids,omitempty"`
SelectMessageTemplates SelectQuery `json:"selectMessageTemplates,omitempty"`
SelectUsers SelectQuery `json:"selectUsers,omitempty"`
}
// Structure to store creation result
type mediatypeCreateResult struct {
MediatypeIDs []int `json:"mediatypeids"`
}
// Structure to store deletion result
type mediatypeDeleteResult struct {
MediatypeIDs []int `json:"mediatypeids"`
}
// MediatypeGet gets mediatypes
func (z *Context) MediatypeGet(params MediatypeGetParams) ([]MediatypeObject, int, error) {
var result []MediatypeObject
status, err := z.request("mediatype.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// MediatypeCreate creates mediatypes
func (z *Context) MediatypeCreate(params []MediatypeObject) ([]int, int, error) {
var result mediatypeCreateResult
status, err := z.request("mediatype.create", params, &result)
if err != nil {
return nil, status, err
}
return result.MediatypeIDs, status, nil
}
// MediatypeDelete deletes mediatypes
func (z *Context) MediatypeDelete(mediatypeIDs []int) ([]int, int, error) {
var result mediatypeDeleteResult
status, err := z.request("mediatype.delete", mediatypeIDs, &result)
if err != nil {
return nil, status, err
}
return result.MediatypeIDs, status, nil
}