我使用本教程创建了一个逻辑应用程序,只要资源发生更改,该应用程序就会通过我的gmail帐户向我的工作帐户发送电子邮件:
但是,由于某种原因,每当我更改虚拟机上的任何内容(例如停止/启动它)时,都不会发生任何事情。当我尝试手动运行触发器时,它失败并显示以下消息:
无法启动逻辑应用程序newLogicApp的运行。处理您的请求时出错。请稍后再试。
我所有的资源都在同一订阅下的同一资源组中。
资源组中没有任何应用服务计划。我不知道这是否是必需的,如果是,您该如何将该应用程序服务计划链接到逻辑应用程序本身。
这是逻辑应用程序的代码视图:
{
"$connections": {
"value": {
"azureeventgrid": {
"connectionId": "/subscriptions/7137186b-8ebc-4bc6-952f-55efcb96d2f5/resourceGroups/testRG/providers/Microsoft.Web/connections/azureeventgrid-2",
"connectionName": "azureeventgrid-2",
"id": "/subscriptions/7137186b-8ebc-4bc6-952f-55efcb96d2f5/providers/Microsoft.Web/locations/eastus/managedApis/azureeventgrid"
},
"gmail_1": {
"connectionId": "/subscriptions/7137186b-8ebc-4bc6-952f-55efcb96d2f5/resourceGroups/testRG/providers/Microsoft.Web/connections/gmail-1",
"connectionName": "gmail-1",
"id": "/subscriptions/7137186b-8ebc-4bc6-952f-55efcb96d2f5/providers/Microsoft.Web/locations/eastus/managedApis/gmail"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Condition": {
"actions": {
"Send_email": {
"inputs": {
"body": {
"Body": "Resource: @{triggerBody()?['topic']}\n\nEvent Type: @{triggerBody()?['eventType']}\n\nEvent ID: @{triggerBody()?['id']}\n\nTime: @{triggerBody()?['eventTime']}",
"Subject": "Resource updated: @{triggerBody()?['subject']}",
"To": "xxx@yyy.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['gmail_1']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": {
"and": [
{
"equals": [
"@triggerBody()?['data']['operationName']",
"Microsoft.Compute/virtualMachines/write"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_resource_event_occurs": {
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "@{listCallbackUrl()}"
}
},
"topic": "/subscriptions/7137186b-8ebc-4bc6-952f-55efcb96d2f5/resourceGroups/testRG"
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureeventgrid']['connectionId']"
}
},
"path": "/subscriptions/@{encodeURIComponent('7137186b-8ebc-4bc6-952f-55efcb96d2f5')}/providers/@{encodeURIComponent('Microsoft.Resources.ResourceGroups')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-09-15-preview"
}
},
"splitOn": "@triggerBody()",
"type": "ApiConnectionWebhook"
}
}
}
}
答案 0 :(得分:0)
根据我的理解,本教程仅帮助我们如何监视虚拟机的更改,但不能监视虚拟机的启动/停止。我在Azure门户上对其进行了测试,如果启动/停止VM,则不会触发逻辑应用程序。但是,当我调整VM的大小时,逻辑被成功触发。您可以自己再次测试。
顺便说一句,如果要在VM启动时收到通知,则可以使用其他解决方案。转到您的VM,然后单击“警报”->“新警报规则”。然后,您可以添加“启动虚拟机”条件(另一个可能对您有所帮助的条件是“创建或更新虚拟机”),并创建操作组以向您自己发送电子邮件。(如下面的屏幕截图所示)
更新:
似乎(从您的查看代码来看)您尚未在逻辑应用的触发器(当发生资源事件时)中添加“事件类型项”,您共享的教程提到了它,您可以再次浏览它或请参阅我在下面发布的屏幕截图。
Update2:
这是逻辑应用程序的代码:
{
"$connections": {
"value": {
"azureeventgrid": {
"connectionId": "/subscriptions/*********/resourceGroups/hurylogicVM/providers/Microsoft.Web/connections/azureeventgrid",
"connectionName": "azureeventgrid",
"id": "/subscriptions/*********/providers/Microsoft.Web/locations/eastasia/managedApis/azureeventgrid"
},
"office365": {
"connectionId": "/subscriptions/*********/resourceGroups/hurylogicVM/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/*********/providers/Microsoft.Web/locations/eastasia/managedApis/office365"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"If_a_virtual_machine_in_your_resource_group_has_changed": {
"actions": {
"Send_email_when_virtual_machine_updated": {
"inputs": {
"body": {
"Body": "Resource: @{triggerBody()?['topic']}\nEvent type: @{triggerBody()?['eventType']}\nEvent id: @{triggerBody()?['id']}\nEvent time: @{triggerBody()?['eventTime']}",
"Subject": "Resource updated:@{triggerBody()?['subject']}",
"To": "v-shuhsh@microsoft.com"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": {
"and": [
{
"equals": [
"@triggerBody()?['data']['operationName']",
"Microsoft.Compute/virtualMachines/write"
]
}
]
},
"runAfter": {},
"type": "If"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_resource_event_occurs": {
"inputs": {
"body": {
"properties": {
"destination": {
"endpointType": "webhook",
"properties": {
"endpointUrl": "@{listCallbackUrl()}"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Resources.ResourceActionSuccess",
"Microsoft.Resources.ResourceDeleteSuccess",
"Microsoft.Resources.ResourceWriteSuccess"
]
},
"topic": "/subscriptions/*********/resourceGroups/hurylogicVM"
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureeventgrid']['connectionId']"
}
},
"path": "/subscriptions/@{encodeURIComponent('*********')}/providers/@{encodeURIComponent('Microsoft.Resources.ResourceGroups')}/resource/eventSubscriptions",
"queries": {
"x-ms-api-version": "2017-09-15-preview"
}
},
"splitOn": "@triggerBody()",
"type": "ApiConnectionWebhook"
}
}
}
}
我的资源组的屏幕截图:
答案 1 :(得分:0)