動作適用于運維任務完成后需通知的場景。例如,在購買ECS實例后,可通過發送釘釘通知讓您實時了解賬單信息。
語法
支持Webhook和Mail兩種通知類型,定義方式如下。
Webhook
Tasks:
- Name: notifyTask
Action: ACS::Notify
Properties:
NotifyType: WebHook
AppendExecutionLink: 'false' # 是否附加執行詳情鏈接,可選項true和false。ACS::Notify動作默認為false。
WebHook:
URI: url # 必填,webhook地址,如https://oapi.dingtalk.com/robot/send?access_token=xxxxxx
Headers: # 可選,Http請求的Headers,如Content-Type
Content-Type: 'application/json; charset=utf-8'
Content: # 必填,根據具體的Webhook要求提供,如釘釘webhook要求如下:https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1
msgtype: text
text:
content: 'this is a dingtalk message with a parameter {{ p1 }}'
{
"Tasks": [
{
"Name": "notifyTask",
"Action": "ACS::Notify",
"Properties": {
"NotifyType": "WebHook",
"AppendExecutionLink": "false",
"WebHook": {
"URI": "url",
"Headers": {
"Content-Type": "application/json; charset=utf-8"
},
"Content": {
"msgtype": "text",
"text": {
"content": "this is a dingtalk message with a parameter {{ p1 }}"
}
}
}
}
}
]
}
Tasks:
- Action: ACS::Notify
Name: NotifyByMail
Properties:
NotifyType: Mail
Mail:
Host: SMTPHostAddress # SMTP 服務器主機地址如 smtp.example1.com
Port: SMTPPort # SMTP 服務器端口如 465
Username: sender # 代發送的郵箱用戶如 usr001@example1.com
Password: senderPassword # 代發送的郵箱密碼如 123456zxcv
Subject: mailSubject # 郵件主題如 hello world
Body: mailBody # 郵件正文如 hello world ?。。? From: senderAddress # 郵件來自如 usr001@example1.com
To: receiverAddresses # 收件人郵箱地址列表如 [usr1234@example2.com,usr123@example2.com]
{
"Tasks": [
{
"Action": "ACS::Notify",
"Name": "NotifyByMail",
"Properties": {
"NotifyType": "Mail",
"Mail": {
"Host": "SMTPHostAddress",
"Port": "SMTPPort",
"Username": "sender",
"Password": "senderPassword",
"Subject": "mailSubject",
"Body": "mailBody",
"From": "senderAddress",
"To": "receiverAddresses"
}
}
}
]
}
示例
---
FormatVersion: OOS-2019-06-01
Outputs:
InstanceIds:
Type: List
Value: ' {{ runInstances.InstanceIds }} '
Parameters:
ImageId:
Description: the image id for the new instances.
Type: String
InstanceType:
Description: the Instance Type for the new instances.
Type: String
OOSAssumeRole:
Default: OOSServiceRole
Description: oos assume this role to execution task
Type: String
SecurityGroupId:
Description: the security group id for the new instances.
Type: String
VSwitchId:
Description: the virtual switch id for the new instances.
Type: String
RamRole: '{{OOSAssumeRole}}'
Tasks:
- Action: ACS::ExecuteAPI
Description: 'run instances with specified parameters'
Name: runInstances
Outputs:
InstanceIds:
Type: List
ValueSelector: .InstanceIdSets.InstanceIdSet[]
Properties:
API: RunInstances
Parameters:
ImageId: '{{ ImageId }}'
InstanceType: '{{ InstanceType }}'
SecurityGroupId: '{{ SecurityGroupId }}'
VSwitchId: '{{ VSwitchId }}'
Service: ECS
- Action: ACS::Notify
Name: test_notify
Properties:
NotifyType: WebHook
WebHook:
Content:
msgtype: text
text:
content: test
Headers:
Content-Type: application/json
URI: https://oapi.dingtalk.com/robot/send?access_token=your_access_token
{
"FormatVersion": "OOS-2019-06-01",
"Outputs": {
"InstanceIds": {
"Type": "List"
"Value": " {{ runInstances.InstanceIds }} "
}
},
"Parameters": {
"ImageId": {
"Description": "the image id for the new instances.",
"Type": "String"
},
"InstanceType": {
"Description": "the Instance Type for the new instances.",
"Type": "String"
},
"SecurityGroupId": {
"Description": "the security group id for the new instances.",
"Type": "String"
},
"VSwitchId": {
"Description": "the virtual switch id for the new instances.",
"Type": "String"
},
"OOSAssumeRole": {
"Type": "String",
"Description": "oos assume this role to execution task",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{OOSAssumeRole}}",
"Tasks": [
{
"Action": "ACS::ExecuteAPI",
"Description": "run instances with specified parametersl",
"Name": "runInstances",
"Outputs": {
"InstanceIds": {
"Type": "List",
"ValueSelector": ".InstanceIdSets.InstanceIdSet[]"
}
},
"Properties": {
"API": "RunInstances",
"Parameters": {
"ImageId": "{{ ImageId }}",
"InstanceType": "{{ InstanceType }}",
"SecurityGroupId": "{{ SecurityGroupId }}",
"VSwitchId": "{{ VSwitchId }}"
},
"Service": "ECS"
}
},
{
"Name": "test_notify",
"Action": "ACS::Notify",
"Properties": {
"NotifyType": "WebHook",
"WebHook": {
"URI": "https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
"Headers": {
"Content-Type": "application/json"
},
"Content": {
"msgtype": "text",
"text": {
"content":"test"
}
}
}
}
}
]
}
文檔內容是否對您有幫助?