Sidebar

Become a monitoring expert!
Sign up for Zabbix training

创建

描述

object mediatype.create(object/array mediaTypes)

此方法允许创建新的媒体类型。

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

参数

(object/array)` 需要创建的媒介类型。

除了标准媒介类型属性外,该方法还接受以下参数。

参数 类型 描述
parameters array 要为媒体类型创建的 Webhook 参数
message_templates array 为媒体类型创建的消息模板

返回值

(object)返回一个包含在"mediatypeids"属性下创建的媒介类型的IDs的对象,返回的顺序与传递的媒介类型的ID顺序匹配。

示例

创建电子邮件媒介类型

使用自定义 SMTP 端口和消息模板创建新的电子邮件媒介类型。

请求:

{
           "jsonrpc": "2.0",
           "method": "mediatype.create",
           "params": {
               "type": "0",
               "name": "E-mail",
               "smtp_server": "mail.example.com",
               "smtp_helo": "example.com",
               "smtp_email": "[email protected]",
               "smtp_port": "587",
               "content_type": "1",
               "message_templates": [
                   {
                       "eventsource": "0",
                       "recovery": "0",
                       "subject": "Problem: {EVENT.NAME}",
                       "message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" started at {EVENT.TIME}."
                   },
                   {
                       "eventsource": "0",
                       "recovery": "1",
                       "subject": "Resolved in {EVENT.DURATION}: {EVENT.NAME}",
                       "message": "Problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}."
                   },
                   {
                       "eventsource": "0",
                       "recovery": "2",
                       "subject": "Updated problem in {EVENT.AGE}: {EVENT.NAME}",
                       "message": "{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem \"{EVENT.NAME}\" on host \"{HOST.NAME}\" at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}."
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "7"
               ]
           },
           "id": 1
       }

创建脚本媒介类型

使用自定义值创建一个新的脚本媒介类型,用于尝试次数和它们之间的间隔.

请求:

{
           "jsonrpc": "2.0",
           "method": "mediatype.create",
           "params": {
               "type": 1,
               "description": "Push notifications",
               "exec_path": "push-notification.sh",
               "exec_params": "{ALERT.SENDTO}\n{ALERT.SUBJECT}\n{ALERT.MESSAGE}\n",
               "maxattempts": "5",
               "attempt_interval": "11s"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "8"
               ]
           },
           "id": 1
       }

创建 webhook 媒介类型

创建新的 webhook 媒介类型。

请求:

{
           "jsonrpc": "2.0",
           "method": "mediatype.create",
           "params": {
               "type": 1,
               "description": "Push notifications",
               "exec_path": "push-notification.sh",
               "exec_params": "{ALERT.SENDTO}\n{ALERT.SUBJECT}\n{ALERT.MESSAGE}\n",
               "maxattempts": "5",
               "attempt_interval": "11s"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "mediatypeids": [
                   "9"
               ]
           },
           "id": 1
       }

来源

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