ACS::Approve アクションは、タスクを承認するために使用されます。
説明
自動 O&M 中には、重要なリソースの削除や高コストのインスタンスの購入など、注意が必要な操作があります。これらの操作が自動的に実行されると、リソースの制御を失ったり、予算のしきい値を超えたりする可能性があります。ただし、これらの操作を自動化しない場合は、手動またはその他の自動化されていない方法で実行する必要があります。 ACS::Approve アクションは、自動実行と特別な注意が必要な操作のバランスを見つけるのに役立ちます。
ACS::Approve アクションがテンプレートで実行されると、CloudOps Orchestration サービス (OOS) 実行エンジンは後続の操作の実行を一時停止し、実行の状態を「待機中」に設定してから、管理者に通知を送信します。管理者として通知を受信した後、ビジネス要件に基づいて操作を承認するか拒否するかを決定できます。操作が承認されると、OOS 実行エンジンは後続の操作の実行を続けます。操作が拒否されると、OOS 実行エンジンは実行を停止し、実行の状態を「キャンセル済み」に設定します。
Webhook 構文
Webhook を設定して、DingTalk などのクライアントに通知を送信できます。
YAML 形式
Tasks:
- Name: approvalTask
Action: ACS::Approve
Properties:
AppendExecutionLink: 'true' # 実行リンクを追加するかどうかを指定します。有効な値:true および false。デフォルト値:true。
Approvers: ["user1", "user2", "user3"] # 承認者として機能する Resource Access Management (RAM) ユーザーの名前。
MinRequiredApprovals: 2 # タスクの承認に必要な承認者の最小数。
NotifyType: WebHook
WebHook:
URI: url # 必須。Webhook URL。例:https://oapi.dingtalk.com/robot/send?access_token=xxxxxx。
Headers: # オプション。HTTP リクエストのヘッダー。例:Content-Type。
Content-Type: 'application/json; charset=utf-8'
Content: # 必須。Webhook 通知の内容。Webhook の要件に基づいて値を設定します。DingTalk Webhook の内容については、https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1 を参照してください。
msgtype: text
text:
content: 'the approve notify to user' # 必須。承認通知の内容。
at: # DingTalk グループで @メンションされるユーザー。
atMobiles: # オプション。DingTalk グループで @メンションされるユーザー。DingTalk アカウントの作成に使用した携帯電話番号を使用してユーザーを指定します。
- 138albb1234
- 130albb1234
isAtAll: 'false' # オプション。DingTalk グループのすべてのユーザーを @メンションするかどうかを指定します。有効な値:true および false。デフォルト値:false。 JSON 形式 (詳細については、YAML 形式の属性の説明をご参照ください。)
{
"Tasks": [
{
"Name": "approvalTask",
"Action": "ACS::Approve",
"Properties": {
"AppendExecutionLink": "true",
"Approvers": [
"user1",
"user2",
"user3"
],
"MinRequiredApprovals": 2,
"NotifyType": "WebHook",
"WebHook": {
"URI": "url",
"Headers": {
"Content-Type": "application/json; charset=utf-8"
},
"Content": {
"msgtype": "text",
"text": {
"content": "the approve notify to user"
},
"at": {
"atMobiles": [
"138albb1234",
"130albb1234"
],
"isAtAll": "false"
}
}
}
}
}
]
}Webhook の例
次のテンプレートは、承認後に Elastic Compute Service (ECS) インスタンスを削除するために使用されます。
YAML 形式
---
FormatVersion: OOS-2019-06-01
Description:
en: Bulky restarts the ECS instances with Approval.
name-en: BulkyRebootInstancesWithApproval
Parameters:
targets:
Type: Json
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
rateControl:
Description:
en: Concurrency ratio of task execution.
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 100%
webHookUrl:
Description:
en: >-
The webHook url of dingtalk group assistant,
e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414.
zh-cn: >-
Type: String
atMobiles:
Description:
en: >-
The telephone numbers of member in dingtalk group assistant @, when
notify comes.
Type: List
Default:
- '1390000****'
atAll:
Description:
en: 'assistant @ all members in dingtalk group or not, when notify comes.'
Type: String
Default: 'false'
OOSAssumeRole:
Description:
en: The RAM role to be assumed by OOS.
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
Description:
en: Views the ECS instances.
Action: 'ACS::SelectTargets'
Properties:
ResourceType: 'ALIYUN::ECS::Instance'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
instanceNames:
Type: List
ValueSelector: 'Instances.Instance[].InstanceName'
- Name: approveRestart
Action: 'ACS::Approve'
Properties:
NotifyType: WebHook
WebHook:
URI: '{{webhookUrl}}'
Headers:
Content-Type: application/json
Content:
msgtype: text
text:
content: >-
Notify: please approve instances restart, instance names to
approve are {{getInstance.instanceNames}}, sent by
{{ACS::RegionId}} oos {{ACS::ExecutionId}}.
at:
atMobiles: '{{atMobiles}}'
isAtAll: '{{atAll}}'
- Name: rebootInstance
Action: 'ACS::ECS::RebootInstance'
Description:
en: Restarts the ECS instances.
Properties:
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'
Outputs:
instanceIds:
Type: List
Value: '{{ getInstance.instanceIds }}'JSON 形式
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Bulky restarts the ECS instances with Approval.",
"name-en": "BulkyRebootInstancesWithApproval",
},
"Parameters": {
"targets": {
"Type": "Json",
"AssociationProperty": "Targets",
"AssociationPropertyMetadata": {
"ResourceType": "ALIYUN::ECS::Instance"
}
},
"rateControl": {
"Description": {
"en": "Concurrency ratio of task execution.",
},
"Type": "Json",
"AssociationProperty": "RateControl",
"Default": {
"Mode": "Concurrency",
"MaxErrors": 0,
"Concurrency": "100%"
}
},
"webHookUrl": {
"Description": {
"en": "The webHook url of dingtalk group assistant, e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414.",
},
"Type": "String"
},
"atMobiles": {
"Description": {
"en": "The telephone numbers of member in dingtalk group assistant @, when notify comes.",
},
"Type": "List",
"Default": [
"1390000****"
]
},
"atAll": {
"Description": {
"en": "assistant @ all members in dingtalk group or not, when notify comes.",
},
"Type": "String",
"Default": "false"
},
"OOSAssumeRole": {
"Description": {
"en": "The RAM role to be assumed by OOS.",
},
"Type": "String",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "getInstance",
"Description": {
"en": "Views the ECS instances.",
},
"Action": "ACS::SelectTargets",
"Properties": {
"ResourceType": "ALIYUN::ECS::Instance",
"Filters": [
"{{ targets }}"
]
},
"Outputs": {
"instanceIds": {
"Type": "List",
"ValueSelector": "Instances.Instance[].InstanceId"
},
"instanceNames": {
"Type": "List",
"ValueSelector": "Instances.Instance[].InstanceName"
}
}
},
{
"Name": "approveRestart",
"Action": "ACS::Approve",
"Properties": {
"NotifyType": "WebHook",
"WebHook": {
"URI": "{{webhookUrl}}",
"Headers": {
"Content-Type": "application/json"
},
"Content": {
"msgtype": "text",
"text": {
"content": "Notify: please approve instances restart, instance names to approve are {{getInstance.instanceNames}}, sent by {{ACS::RegionId}} oos {{ACS::ExecutionId}}."
},
"at": {
"atMobiles": "{{atMobiles}}",
"isAtAll": "{{atAll}}"
}
}
}
}
},
{
"Name": "rebootInstance",
"Action": "ACS::ECS::RebootInstance",
"Description": {
"en": "Restarts the ECS instances.",
},
"Properties": {
"instanceId": "{{ ACS::TaskLoopItem }}"
},
"Loop": {
"RateControl": "{{ rateControl }}",
"Items": "{{ getInstance.instanceIds }}"
}
}
],
"Outputs": {
"instanceIds": {
"Type": "List",
"Value": "{{ getInstance.instanceIds }}"
}
}
}メール構文
YAML 形式
Tasks:
- Action: ACS::Approve
Name: ApproveByMail
Properties:
NotifyType: Mail
Mail:
Host: SMTPHostAddress # 簡易メール転送プロトコル (SMTP) サーバーアドレス。例:smtp.example1.com。
Port: SMTPPort # SMTP サーバーのポート番号。例:465。
Username: sender # 通知の送信に使用するメールアカウント。例:usr001@example1.com。
Password: senderPassword # メールアカウントのパスワードではなく、インターネットメッセージアクセスプロトコル (IMAP) または SMTP サービスの認証コード。
Subject: mailSubject # メール通知の件名。例:hello world。
Body: mailBody # メール通知の本文。例:hello world ! ! !。
From: senderAddress # 送信者のメールアドレス。例:usr001@example1.com。
To: # 受信者のメールアドレス。例:usr1234@example2.com,usr123@example2.com。
- usr123@example2.com
- usr1234@example2.comJSON 形式 (詳細については、YAML 形式の属性の説明をご参照ください。)
{
"Tasks": [
{
"Action": "ACS::Approve",
"Name": "ApproveByMail",
"Properties": {
"NotifyType": "Mail",
"Mail": {
"Host": "SMTPHostAddress",
"Port": "SMTPPort",
"Username": "sender",
"Password": "senderPassword",
"Subject": "mailSubject",
"Body": "mailBody",
"From": "senderAddress",
"To": [
"usr123@example2.com,usr1234@example2.com"
]
}
}
}
]
}