获取

描述

integer/array mediatype.get(object parameters)

此方法允许根据给定参数检索媒体类型。

此方法对于任何用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看 用户角色

参数

(object) 定义所需输出的参数。

此方法支持以下参数。

参数类型描述
mediatypeidsID/array仅返回具有给定 ID 的媒介类型。
mediaidsID/array仅返回给定媒介使用的媒介类型。
useridsID/array仅返回给定用户使用的媒介类型。
selectActionsquery返回一个包含消息模板消息数组的属性。
selectMessageTemplatesquery返回一个包含消息模板消息数组的属性。
selectUsersquery返回使用媒介类型的用户属性。
sortfieldstring/array按给定属性对结果进行排序。

可能值:mediatypeid
countOutputboolean对于所有 get 方法通用的参数在参考评论中有详细描述。
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(整型/数组) 返回其中之一:

  • 一个对象数组;
  • 如果使用countOutput参数,返回被检索对象的数量。

示例

检索媒介类型

检索所有配置的媒介类型。以下示例返回两种媒介类型:

  • 电子邮件媒介类型;
  • 短信媒介类型。

请求

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "mediatype.get",
  4. "params": {
  5. "output": "extend",
  6. "selectMessageTemplates": "extend"
  7. },
  8. "id": 1
  9. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "mediatypeid": "1",
  6. "type": "0",
  7. "name": "Email",
  8. "smtp_server": "mail.example.com",
  9. "smtp_helo": "example.com",
  10. "smtp_email": "[email protected]",
  11. "exec_path": "",
  12. "gsm_modem": "",
  13. "username": "",
  14. "passwd": "",
  15. "status": "0",
  16. "smtp_port": "25",
  17. "smtp_security": "0",
  18. "smtp_verify_peer": "0",
  19. "smtp_verify_host": "0",
  20. "smtp_authentication": "0",
  21. "maxsessions": "1",
  22. "maxattempts": "3",
  23. "attempt_interval": "10s",
  24. "message_format": "0",
  25. "script": "",
  26. "timeout": "30s",
  27. "process_tags": "0",
  28. "show_event_menu": "1",
  29. "event_menu_url": "",
  30. "event_menu_name": "",
  31. "description": "",
  32. "message_templates": [
  33. {
  34. "eventsource": "0",
  35. "recovery": "0",
  36. "subject": "Problem: {EVENT.NAME}",
  37. "message": "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\nSeverity: {EVENT.SEVERITY}\r\nOperational data: {EVENT.OPDATA}\r\nOriginal problem ID: {EVENT.ID}\r\n{TRIGGER.URL}"
  38. },
  39. {
  40. "eventsource": "0",
  41. "recovery": "1",
  42. "subject": "Resolved: {EVENT.NAME}",
  43. "message": "Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}\r\nProblem name: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\nSeverity: {EVENT.SEVERITY}\r\n\r\nOriginal problem ID: {EVENT.ID}\r\n{TRIGGER.URL}"
  44. },
  45. {
  46. "eventsource": "0",
  47. "recovery": "2",
  48. "subject": "Updated problem: {EVENT.NAME}",
  49. "message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.\r\n{EVENT.UPDATE.MESSAGE}\r\n\r\nCurrent problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}."
  50. },
  51. {
  52. "eventsource": "1",
  53. "recovery": "0",
  54. "subject": "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}",
  55. "message": "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}\r\nDevice DNS: {DISCOVERY.DEVICE.DNS}\r\nDevice status: {DISCOVERY.DEVICE.STATUS}\r\nDevice uptime: {DISCOVERY.DEVICE.UPTIME}\r\n\r\nDevice service name: {DISCOVERY.SERVICE.NAME}\r\nDevice service port: {DISCOVERY.SERVICE.PORT}\r\nDevice service status: {DISCOVERY.SERVICE.STATUS}\r\nDevice service uptime: {DISCOVERY.SERVICE.UPTIME}"
  56. },
  57. {
  58. "eventsource": "2",
  59. "recovery": "0",
  60. "subject": "Autoregistration: {HOST.HOST}",
  61. "message": "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}"
  62. }
  63. ],
  64. "parameters": []
  65. },
  66. {
  67. "mediatypeid": "3",
  68. "type": "2",
  69. "name": "SMS",
  70. "smtp_server": "",
  71. "smtp_helo": "",
  72. "smtp_email": "",
  73. "exec_path": "",
  74. "gsm_modem": "/dev/ttyS0",
  75. "username": "",
  76. "passwd": "",
  77. "status": "0",
  78. "smtp_port": "25",
  79. "smtp_security": "0",
  80. "smtp_verify_peer": "0",
  81. "smtp_verify_host": "0",
  82. "smtp_authentication": "0",
  83. "maxsessions": "1",
  84. "maxattempts": "3",
  85. "attempt_interval": "10s",
  86. "message_format": "1",
  87. "script": "",
  88. "timeout": "30s",
  89. "process_tags": "0",
  90. "show_event_menu": "1",
  91. "event_menu_url": "",
  92. "event_menu_name": "",
  93. "description": "",
  94. "message_templates": [
  95. {
  96. "eventsource": "0",
  97. "recovery": "0",
  98. "subject": "",
  99. "message": "{EVENT.SEVERITY}: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
  100. },
  101. {
  102. "eventsource": "0",
  103. "recovery": "1",
  104. "subject": "",
  105. "message": "RESOLVED: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
  106. },
  107. {
  108. "eventsource": "0",
  109. "recovery": "2",
  110. "subject": "",
  111. "message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}"
  112. },
  113. {
  114. "eventsource": "1",
  115. "recovery": "0",
  116. "subject": "",
  117. "message": "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}"
  118. },
  119. {
  120. "eventsource": "2",
  121. "recovery": "0",
  122. "subject": "",
  123. "message": "Autoregistration: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}"
  124. }
  125. ],
  126. "parameters": []
  127. }
  128. ],
  129. "id": 1
  130. }

检索脚本和 webhook 媒介类型

以下示例返回三种媒介类型:

  • 带参数的脚本媒介类型;
  • 不带参数的脚本媒介类型;
  • 带参数的 Webhook 媒介类型。

请求

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "mediatype.get",
  4. "params": {
  5. "output": ["mediatypeid", "name", "parameters"],
  6. "filter": {
  7. "type": [1, 4]
  8. }
  9. },
  10. "id": 1
  11. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "mediatypeid": "10",
  6. "name": "Script with parameters",
  7. "parameters": [
  8. {
  9. "sortorder": "0",
  10. "value": "{ALERT.SENDTO}"
  11. },
  12. {
  13. "sortorder": "1",
  14. "value": "{EVENT.NAME}"
  15. },
  16. {
  17. "sortorder": "2",
  18. "value": "{ALERT.MESSAGE}"
  19. },
  20. {
  21. "sortorder": "3",
  22. "value": "Zabbix alert"
  23. }
  24. ]
  25. },
  26. {
  27. "mediatypeid": "13",
  28. "name": "Script without parameters",
  29. "parameters": []
  30. },
  31. {
  32. "mediatypeid": "11",
  33. "name": "Webhook",
  34. "parameters": [
  35. {
  36. "name": "alert_message",
  37. "value": "{ALERT.MESSAGE}"
  38. },
  39. {
  40. "name": "event_update_message",
  41. "value": "{EVENT.UPDATE.MESSAGE}"
  42. },
  43. {
  44. "name": "host_name",
  45. "value": "{HOST.NAME}"
  46. },
  47. {
  48. "name": "trigger_description",
  49. "value": "{TRIGGER.DESCRIPTION}"
  50. },
  51. {
  52. "name": "trigger_id",
  53. "value": "{TRIGGER.ID}"
  54. },
  55. {
  56. "name": "alert_source",
  57. "value": "Zabbix"
  58. }
  59. ]
  60. }
  61. ],
  62. "id": 1
  63. }

参见

来源

ui/include/classes/api/services/CMediaType.php 中的 CMediaType::get()。