object mediatype.create(object/array mediaTypes)
此方法允许创建新的媒体类型。
此方法仅适用于超级管理员用户类型。 可以在用户角色设置中撤销调用该方法的权限。 查阅用户角色 了解更多信息。
(object/array)
需要创建的媒介类型。
除了标准媒介类型属性外,该方法还接受以下参数。
(object)
返回一个对象,其中包含在 mediatypeids
属性下创建的媒体类型的 ID。返回的 ID 的顺序与传递的媒体类型的顺序匹配。
使用自定义 SMTP 端口和消息模板创建新的电子邮件媒介类型。
请求:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "0",
"name": "Email",
"smtp_server": "mail.example.com",
"smtp_helo": "example.com",
"smtp_email": "[email protected]",
"smtp_port": "587",
"message_format": "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}."
}
]
},
"id": 1
}
响应:
使用自定义数量值创建新的脚本媒体类型 尝试次数以及尝试次数之间的间隔。
请求:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "1",
"name": "Push notifications",
"exec_path": "push-notification.sh",
"maxattempts": "5",
"attempt_interval": "11s",
"parameters": [
{
"sortorder": "0",
"value": "{ALERT.SENDTO}"
},
{
"sortorder": "1",
"value": "{ALERT.SUBJECT}"
},
{
"sortorder": "2",
"value": "{ALERT.MESSAGE}"
}
]
},
"id": 1
}
响应:
创建新的 Webhook 媒介类型。
请求:
{
"jsonrpc": "2.0",
"method": "mediatype.create",
"params": {
"type": "4",
"name": "Webhook",
"script": "var Webhook = {\r\n token: null,\r\n to: null,\r\n subject: null,\r\n message: null,\r\n\r\n sendMessage: function() {\r\n // some logic\r\n }\r\n}",
"parameters": [
{
"name": "Message",
"value": "{ALERT.MESSAGE}"
},
{
"name": "Subject",
"value": "{ALERT.SUBJECT}"
},
{
"name": "To",
"value": "{ALERT.SENDTO}"
},
{
"name": "Token",
"value": "<Token>"
}
]
},
"id": 1
}
响应:
CMediaType::create() in ui/include/classes/api/services/CMediaType.php。