azure - 使用 powershell 在 Azure 中创建自动化操作组
问题描述
我想使用此命令 Set-AzActionGroup 来操作标准自动化 Runbook 重新启动 VM,但周围似乎没有任何示例。要在 Set-AzActionGroup 中执行此操作,我需要引用 VM、自动化帐户以及一些称为服务 uri 和 webhook 资源 ID(我认为是指运行手册)的东西。有没有人有一个完整的例子?我有一个 azure 自动化帐户,但需要一个 webhook。
解决方案
只需尝试使用下面的 PowerShell 来创建一个带有重启 VM AutomationRunbookReceiver 的操作组:
$automationAccountResourceGroup = ""
$automationAccountName = ""
$webhookName = "Webhook20210316"
$receiverEmail = ""
$actionGroupName = ""
#create automationRunbookReceivers
$webhook = New-AzAutomationWebhook -Name $webhookName -IsEnabled $true -ExpiryTime "10/2/2030" -RunbookName "RestartAzureVmInResponseToVmAlertGlobalRunbook" -ResourceGroup $automationAccountResourceGroup -AutomationAccountName $automationAccountName -Force
$serviceURI = $webhook.WebhookURI
$automationAccountID = (Get-AzResource -ResourceGroup $automationAccountResourceGroup -name $automationAccountName).ResourceId
$WebhookResourceID = $automationAccountID + "/webhooks/" + $webhook.name
$AutomationRunbookReceiver = New-AzActionGroupReceiver -Name 'restartVM' -RunbookName 'Restart VM' -AutomationAccountId $automationAccountID.ToLower() -IsGlobalRunbook -AutomationRunbookServiceUri $serviceURI -WebhookResourceId $WebhookResourceID
#create email receivers
$EmailReceiver = New-AzActionGroupReceiver -Name $receiverEmail -EmailReceiver -EmailAddress $receiverEmail
Set-AzActionGroup -ResourceGroupName $automationAccountResourceGroup -Name $actionGroupName -ShortName $actionGroupName -Receiver $EmailReceiver,$AutomationRunbookReceiver
我还根据一些规则在我这边对其进行了测试,并且它可以作为例外工作:
推荐阅读
- python-3.x - Python3 代码帮助无法向用户显示总数
- javascript - (Chart.js)如何将最小值(如果可以的话,最大值)设置为特定数字?
- javascript - 在 GoLang 或 Javascript 中读取 Arrow Feather 文件
- python-3.x - 如何从 python 的循环列表中替换 xml 元素?
- python - 从客户端向 TCP 套接字服务器发送消息
- sql - SQL Server 2019 开发者版安装错误
- c++ - MAC audioUnit AudioComponentInstanceDispose 崩溃
- python - 如何使用 Python 中的函数在两个列表之间进行过滤?
- git - 无法将 SSH 公钥添加到另一个 GitHub 帐户并能够使用它?
- nginx - 在从上游读取响应标头时,公共 IP 更改 504 ERROR Gateway Time-out - *3 upstream timed out (110: Connection timed out) 后,