5 Media types

Overview

Media types are exported with all related objects and object relations.

Exporting

To export media types, do the following:

  • Go to: AdministrationMedia types
  • Mark the checkboxes of the media types to export
  • Click on Export below the list

5 Media types - 图1

Depending on the selected format, media types are exported to a local file with a default name:

  • zabbix_export_mediatypes.yaml - in YAML export (default option for export)
  • zabbix_export_mediatypes.xml - in XML export
  • zabbix_export_mediatypes.json - in JSON export

Importing

To import media types, do the following:

  • Go to: AdministrationMedia types
  • Click on Import to the right
  • Select the import file
  • Mark the required options in import rules
  • Click on Import

5 Media types - 图2

A success or failure message of the import will be displayed in the frontend.

Import rules:

RuleDescription
Update existingExisting elements will be updated with data taken from the import file. Otherwise they will not be updated.
Create newThe import will add new elements using data from the import file. Otherwise it will not add them.
Delete missingThe import will remove existing elements not present in the import file. Otherwise it will not remove them.

Export format

Export to YAML:

  1. zabbix_export:
  2. version: '5.4'
  3. date: '2021-08-31T13:35:52Z'
  4. media_types:
  5. -
  6. name: Pushover
  7. type: WEBHOOK
  8. parameters:
  9. 8:
  10. name: endpoint
  11. value: 'https://api.pushover.net/1/messages.json'
  12. 6:
  13. name: eventid
  14. value: '{EVENT.ID}'
  15. 11:
  16. name: event_nseverity
  17. value: '{EVENT.NSEVERITY}'
  18. 12:
  19. name: event_source
  20. value: '{EVENT.SOURCE}'
  21. 13:
  22. name: event_value
  23. value: '{EVENT.VALUE}'
  24. 10:
  25. name: expire
  26. value: '1200'
  27. 2:
  28. name: message
  29. value: '{ALERT.MESSAGE}'
  30. 14:
  31. name: priority_average
  32. value: '0'
  33. 15:
  34. name: priority_default
  35. value: '0'
  36. 16:
  37. name: priority_disaster
  38. value: '0'
  39. 17:
  40. name: priority_high
  41. value: '0'
  42. 18:
  43. name: priority_information
  44. value: '0'
  45. 19:
  46. name: priority_not_classified
  47. value: '0'
  48. 20:
  49. name: priority_warning
  50. value: '0'
  51. 9:
  52. name: retry
  53. value: '60'
  54. 3:
  55. name: title
  56. value: '{ALERT.SUBJECT}'
  57. 0:
  58. name: token
  59. value: '<PUSHOVER TOKEN HERE>'
  60. 7:
  61. name: triggerid
  62. value: '{TRIGGER.ID}'
  63. 4:
  64. name: url
  65. value: '{$ZABBIX.URL}'
  66. 5:
  67. name: url_title
  68. value: Zabbix
  69. 1:
  70. name: user
  71. value: '{ALERT.SENDTO}'
  72. max_sessions: '0'
  73. script: |
  74. try {
  75. var params = JSON.parse(value),
  76. request = new HttpRequest(),
  77. data,
  78. response,
  79. severities = [
  80. {name: 'not_classified', color: '#97AAB3'},
  81. {name: 'information', color: '#7499FF'},
  82. {name: 'warning', color: '#FFC859'},
  83. {name: 'average', color: '#FFA059'},
  84. {name: 'high', color: '#E97659'},
  85. {name: 'disaster', color: '#E45959'},
  86. {name: 'resolved', color: '#009900'},
  87. {name: 'default', color: '#000000'}
  88. ],
  89. priority;
  90. if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
  91. request.setProxy(params.HTTPProxy);
  92. }
  93. if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
  94. throw 'Incorrect "event_source" parameter given: "' + params.event_source + '".\nMust be 0-3.';
  95. }
  96. if (params.event_value !== '0' && params.event_value !== '1'
  97. && (params.event_source === '0' || params.event_source === '3')) {
  98. throw 'Incorrect "event_value" parameter given: ' + params.event_value + '\nMust be 0 or 1.';
  99. }
  100. if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
  101. params.event_nseverity = '7';
  102. }
  103. if (params.event_value === '0') {
  104. params.event_nseverity = '6';
  105. }
  106. priority = params['priority_' + severities[params.event_nseverity].name] || params.priority_default;
  107. if (isNaN(priority) || priority < -2 || priority > 2) {
  108. throw '"priority" should be -2..2';
  109. }
  110. if (params.event_source === '0' && isNaN(params.triggerid)) {
  111. throw 'field "triggerid" is not a number';
  112. }
  113. if (isNaN(params.eventid)) {
  114. throw 'field "eventid" is not a number';
  115. }
  116. if (typeof params.message !== 'string' || params.message.trim() === '') {
  117. throw 'field "message" cannot be empty';
  118. }
  119. data = {
  120. token: params.token,
  121. user: params.user,
  122. title: params.title,
  123. message: params.message,
  124. url: (params.event_source === '0')
  125. ? params.url + '/tr_events.php?triggerid=' + params.triggerid + '&eventid=' + params.eventid
  126. : params.url,
  127. url_title: params.url_title,
  128. priority: priority
  129. };
  130. if (priority == 2) {
  131. if (isNaN(params.retry) || params.retry < 30) {
  132. throw 'field "retry" should be a number with value of at least 30 if "priority" is set to 2';
  133. }
  134. if (isNaN(params.expire) || params.expire > 10800) {
  135. throw 'field "expire" should be a number with value of at most 10800 if "priority" is set to 2';
  136. }
  137. data.retry = params.retry;
  138. data.expire = params.expire;
  139. }
  140. data = JSON.stringify(data);
  141. Zabbix.log(4, '[ Pushover Webhook ] Sending request: ' + params.endpoint + '\n' + data);
  142. request.addHeader('Content-Type: application/json');
  143. response = request.post(params.endpoint, data);
  144. Zabbix.log(4, '[ Pushover Webhook ] Received response with status code ' + request.getStatus() + '\n' + response);
  145. if (response !== null) {
  146. try {
  147. response = JSON.parse(response);
  148. }
  149. catch (error) {
  150. Zabbix.log(4, '[ Pushover Webhook ] Failed to parse response received from Pushover');
  151. response = null;
  152. }
  153. }
  154. if (request.getStatus() != 200 || response === null || typeof response !== 'object' || response.status !== 1) {
  155. if (response !== null && typeof response === 'object' && typeof response.errors === 'object'
  156. && typeof response.errors[0] === 'string') {
  157. throw response.errors[0];
  158. }
  159. else {
  160. throw 'Unknown error. Check debug log for more information.';
  161. }
  162. }
  163. return 'OK';
  164. }
  165. catch (error) {
  166. Zabbix.log(4, '[ Pushover Webhook ] Pushover notification failed: ' + error);
  167. throw 'Pushover notification failed: ' + error;
  168. }
  169. description: |
  170. Please refer to setup guide here: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/pushover
  171. Set token parameter with to your Pushover application key.
  172. When assigning Pushover media to the Zabbix user - add user key into send to field.
  173. message_templates:
  174. -
  175. event_source: TRIGGERS
  176. operation_mode: PROBLEM
  177. subject: 'Problem: {EVENT.NAME}'
  178. message: |
  179. Problem started at {EVENT.TIME} on {EVENT.DATE}
  180. Problem name: {EVENT.NAME}
  181. Host: {HOST.NAME}
  182. Severity: {EVENT.SEVERITY}
  183. Operational data: {EVENT.OPDATA}
  184. Original problem ID: {EVENT.ID}
  185. {TRIGGER.URL}
  186. -
  187. event_source: TRIGGERS
  188. operation_mode: RECOVERY
  189. subject: 'Resolved in {EVENT.DURATION}: {EVENT.NAME}'
  190. message: |
  191. Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
  192. Problem name: {EVENT.NAME}
  193. Problem duration: {EVENT.DURATION}
  194. Host: {HOST.NAME}
  195. Severity: {EVENT.SEVERITY}
  196. Original problem ID: {EVENT.ID}
  197. {TRIGGER.URL}
  198. -
  199. event_source: TRIGGERS
  200. operation_mode: UPDATE
  201. subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}'
  202. message: |
  203. {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
  204. {EVENT.UPDATE.MESSAGE}
  205. Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
  206. -
  207. event_source: DISCOVERY
  208. operation_mode: PROBLEM
  209. subject: 'Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}'
  210. message: |
  211. Discovery rule: {DISCOVERY.RULE.NAME}
  212. Device IP: {DISCOVERY.DEVICE.IPADDRESS}
  213. Device DNS: {DISCOVERY.DEVICE.DNS}
  214. Device status: {DISCOVERY.DEVICE.STATUS}
  215. Device uptime: {DISCOVERY.DEVICE.UPTIME}
  216. Device service name: {DISCOVERY.SERVICE.NAME}
  217. Device service port: {DISCOVERY.SERVICE.PORT}
  218. Device service status: {DISCOVERY.SERVICE.STATUS}
  219. Device service uptime: {DISCOVERY.SERVICE.UPTIME}
  220. -
  221. event_source: AUTOREGISTRATION
  222. operation_mode: PROBLEM
  223. subject: 'Autoregistration: {HOST.HOST}'
  224. message: |
  225. Host name: {HOST.HOST}
  226. Host IP: {HOST.IP}
  227. Agent port: {HOST.PORT}

Element tags

Element tag values are explained in the table below.

ElementElement propertyRequiredTypeRange1Description
media_types-Root element for media_types.
namexstringMedia type name.
typexstring0 - EMAIL
1 - SMS
2 - SCRIPT
4 - WEBHOOK
Transport used by the media type.
status-string0 - ENABLED (default)
1 - DISABLED
Whether the media type is enabled.
max_sessions-integerPossible values for SMS: 1 - (default)

Possible values for other media types: 0-100, 0 - unlimited
The maximum number of alerts that can be processed in parallel.
attempts-integer1-10 (default: 3)The maximum number of attempts to send an alert.
attempt_interval-string0-60s (default: 10s)The interval between retry attempts.

Accepts seconds and time unit with suffix.
description-stringMedia type description.
message_templates-Root element for media type message templates.
event_sourcexstring0 - TRIGGERS
1 - DISCOVERY
2 - AUTOREGISTRATION
3 - INTERNAL
Event source.
operation_modexstring0 - PROBLEM
1 - RECOVERY
2 - UPDATE
Operation mode.
subject-stringMessage subject.
message-stringMessage body.
Used only by e-mail media type
smtp_serverxstringSMTP server.
smtp_port-integerDefault: 25SMTP server port to connect to.
smtp_heloxstringSMTP helo.
smtp_emailxstringEmail address from which notifications will be sent.
smtp_security-string0 - NONE (default)
1 - STARTTLS
2 - SSL_OR_TLS
SMTP connection security level to use.
smtp_verify_host-string0 - NO (default)
1 - YES
SSL verify host for SMTP. Optional if smtp_security is STARTTLS or SSL_OR_TLS.
smtp_verify_peer-string0 - NO (default)
1 - YES
SSL verify peer for SMTP. Optional if smtp_security is STARTTLS or SSL_OR_TLS.
smtp_authentication-string0 - NONE (default)
1 - PASSWORD
SMTP authentication method to use.
username-stringUsername.
password-stringAuthentication password.
content_type-string0 - TEXT
1 - HTML (default)
Message format.
Used only by SMS media type
gsm_modemxstringSerial device name of the GSM modem.
Used only by script media type
script namexstringScript name.
parameters-Root element for script parameters.
Used only by webhook media type
scriptxstringScript.
timeout-string1-60s (default: 30s)Javascript script HTTP request timeout interval.
process_tags-string0 - NO (default)
1 - YES
Whether to process returned tags.
show_event_menu-string0 - NO (default)
1 - YES
If {EVENT.TAGS.} were successfully resolved in event_menu_url and event_menu_name fields, this field indicates presence of entry in the event menu.
event_menu_url-stringURL of the event menu entry. Supports {EVENT.TAGS.} macro.
event_menu_name-stringName of the event menu entry. Supports {EVENT.TAGS.*} macro.
parameters-Root element for webhook media type parameters.
namexstringWebhook parameter name.
value-stringWebhook parameter value.
Footnotes

1 For string values, only the string will be exported (e.g. “EMAIL”) without the numbering used in this table. The numbers for range values (corresponding to the API values) in this table is used for ordering only.