mediatype.get

Description

integer/array mediatype.get(object parameters)

The method allows to retrieve media types according to the given parameters.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
mediatypeidsstring/arrayReturn only media types with the given IDs.
mediaidsstring/arrayReturn only media types used by the given media.
useridsstring/arrayReturn only media types used by the given users.
selectMessageTemplatesqueryReturn a message_templates property with an array of media type messages.
selectUsersqueryReturn a users property with the users that use the media type.
sortfieldstring/arraySort the result by the given properties.

Possible values: mediatypeid.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

Return values

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

Examples

Retrieving media types

Retrieve all configured media types. The following example returns two media types:

  • email media type;
  • SMS media type.

Request:

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

Response:

  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. "content_type": "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. "content_type": "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. }

Retrieve script and webhook media types

The following example returns three media types:

  • script media type with parameters;
  • script media type without parameters;
  • webhook media type with parameters.

Request:

  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. }

Response:

  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. }

See also

Source

CMediaType::get() in ui/include/classes/api/services/CMediaType.php.