获取

描述

integer/array mediatype.get(object parameters)

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

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

参数

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

此方法支持以下参数。

参数 类型 描述
mediatypeids ID/array 仅返回具有给定 ID 的媒介类型。
mediaids ID/array 仅返回给定媒介使用的媒介类型。
userids ID/array 仅返回给定用户使用的媒介类型。
selectActions query 返回一个包含消息模板消息数组的属性。
selectMessageTemplates query 返回一个包含消息模板消息数组的属性。
selectUsers query 返回使用媒介类型的用户属性。
sortfield string/array 按给定属性对结果进行排序。

可能值:mediatypeid
countOutput boolean 对于所有 get 方法通用的参数在参考评论中有详细描述。
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

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

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

示例

检索媒介类型

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

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

请求

{
           "jsonrpc": "2.0",
           "method": "mediatype.get",
           "params": {
               "output": "extend",
               "selectMessageTemplates": "extend"
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "mediatypeid": "1",
                   "type": "0",
                   "name": "Email",
                   "smtp_server": "mail.example.com",
                   "smtp_helo": "example.com",
                   "smtp_email": "[email protected]",
                   "exec_path": "",
                   "gsm_modem": "",
                   "username": "",
                   "passwd": "",
                   "status": "0",
                   "smtp_port": "25",
                   "smtp_security": "0",
                   "smtp_verify_peer": "0",
                   "smtp_verify_host": "0",
                   "smtp_authentication": "0",
                   "maxsessions": "1",
                   "maxattempts": "3",
                   "attempt_interval": "10s",
                   "message_format": "0",
                   "script": "",
                   "timeout": "30s",
                   "process_tags": "0",
                   "show_event_menu": "1",
                   "event_menu_url": "",
                   "event_menu_name": "",
                   "description": "",
                   "message_templates": [
                       {
                           "eventsource": "0",
                           "recovery": "0",
                           "subject": "Problem: {EVENT.NAME}",
                           "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}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "1",
                           "subject": "Resolved: {EVENT.NAME}",
                           "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}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "2",
                           "subject": "Updated problem: {EVENT.NAME}",
                           "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}."
                       },
                       {
                           "eventsource": "1",
                           "recovery": "0",
                           "subject": "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}",
                           "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}"
                       },
                       {
                           "eventsource": "2",
                           "recovery": "0",
                           "subject": "Autoregistration: {HOST.HOST}",
                           "message": "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}"
                       }
                   ],
                   "parameters": []
               },
               {
                   "mediatypeid": "3",
                   "type": "2",
                   "name": "SMS",
                   "smtp_server": "",
                   "smtp_helo": "",
                   "smtp_email": "",
                   "exec_path": "",
                   "gsm_modem": "/dev/ttyS0",
                   "username": "",
                   "passwd": "",
                   "status": "0",
                   "smtp_port": "25",
                   "smtp_security": "0",
                   "smtp_verify_peer": "0",
                   "smtp_verify_host": "0",
                   "smtp_authentication": "0",
                   "maxsessions": "1",
                   "maxattempts": "3",
                   "attempt_interval": "10s",
                   "message_format": "1",
                   "script": "",
                   "timeout": "30s",
                   "process_tags": "0",
                   "show_event_menu": "1",
                   "event_menu_url": "",
                   "event_menu_name": "",
                   "description": "",
                   "message_templates": [
                       {
                           "eventsource": "0",
                           "recovery": "0",
                           "subject": "",
                           "message": "{EVENT.SEVERITY}: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "1",
                           "subject": "",
                           "message": "RESOLVED: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "2",
                           "subject": "",
                           "message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}"
                       },
                       {
                           "eventsource": "1",
                           "recovery": "0",
                           "subject": "",
                           "message": "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}"
                       },
                       {
                           "eventsource": "2",
                           "recovery": "0",
                           "subject": "",
                           "message": "Autoregistration: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}"
                       }
                   ],
                   "parameters": []
               }
           ],
           "id": 1
       }

检索脚本和 webhook 媒介类型

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

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

请求

{
           "jsonrpc": "2.0",
           "method": "mediatype.get",
           "params": {
               "output": ["mediatypeid", "name", "parameters"],
               "filter": {
                   "type": [1, 4]
               }
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "mediatypeid": "10",
                   "name": "Script with parameters",
                   "parameters": [
                       {
                           "sortorder": "0",
                           "value": "{ALERT.SENDTO}"
                       },
                       {
                           "sortorder": "1",
                           "value": "{EVENT.NAME}"
                       },
                       {
                           "sortorder": "2",
                           "value": "{ALERT.MESSAGE}"
                       },
                       {
                           "sortorder": "3",
                           "value": "Zabbix alert"
                       }
                   ]
               },
               {
                   "mediatypeid": "13",
                   "name": "Script without parameters",
                   "parameters": []
               },
               {
                   "mediatypeid": "11",
                   "name": "Webhook",
                   "parameters": [
                       {
                           "name": "alert_message",
                           "value": "{ALERT.MESSAGE}"
                       },
                       {
                           "name": "event_update_message",
                           "value": "{EVENT.UPDATE.MESSAGE}"
                       },
                       {
                           "name": "host_name",
                           "value": "{HOST.NAME}"
                       },
                       {
                           "name": "trigger_description",
                           "value": "{TRIGGER.DESCRIPTION}"
                       },
                       {
                           "name": "trigger_id",
                           "value": "{TRIGGER.ID}"
                       },
                       {
                           "name": "alert_source",
                           "value": "Zabbix"
                       }
                   ]
               }
           ],
           "id": 1
       }

参见

来源

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