使用事件网格,是否可以在Azure中创建/删除资源时触发逻辑应用?

cgvd09ve  于 2023-01-31  发布在  其他
关注(0)|答案(1)|浏览(113)

我想知道,如果使用事件网格,有可能有一个逻辑应用程序触发时,任何资源部署在Azure订阅。
使用情形为:

  • 有人在特定Azure订阅上创建/删除资源
  • 它在事件网格中发送事件(不确定吗?)
  • 当此类事件发生时,逻辑应用程序将被触发,此逻辑应用程序将在团队通道中发送通知。

这里的目标是有一个简单的和基本的直升机的看法是什么发生在这艘潜艇上。
出于测试目的,我创建了一个逻辑应用程序,并添加了一个“When a resource event occurrence”触发器,该触发器具有Microsoft.Resources.ResourceGroups和以下事件类型:

Microsoft.Resources.ResourceActionSuccess  
Microsoft.Resources.ResourceDeleteSuccess  
Microsoft.Resources.ResourceWriteSuccess

我不确定我是不是在探索。
然后,我部署了一个存储帐户,但即使在实际部署资源之前“查看”部署,我也会收到通知。
一旦部署,我也有随机通知(即使不使用存储帐户,我猜是某种后台活动?)

wrrgggsh

wrrgggsh1#

根据本正式文件:
资源事件是为发送到management.azure.com的PUT、PATCH、POST和DELETE操作创建的。GET操作不创建事件。
因此,你会收到多个触发器。对于最少的触发器,你可以添加部署过滤器。下面是我使用的流程。

下面是我的逻辑应用程序的完整JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Body": "<p>@{triggerBody()?['subject']} has been created</p>",
                        "Importance": "Normal",
                        "Subject": "xxx",
                        "To": "xxx"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_resource_event_occurs": {
                "conditions": [],
                "inputs": {
                    "body": {
                        "properties": {
                            "destination": {
                                "endpointType": "webhook",
                                "properties": {
                                    "endpointUrl": "@{listCallbackUrl()}"
                                }
                            },
                            "filter": {
                                "includedEventTypes": [
                                    "Microsoft.Resources.ResourceDeleteSuccess",
                                    "Microsoft.Resources.ResourceActionSuccess"
                                ],
                                "subjectBeginsWith": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Resources/deployments"
                            },
                            "topic": "/subscriptions/xxx/resourceGroups/xxx"
                        }
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureeventgrid']['connectionId']"
                        }
                    },
                    "path": "/subscriptions/@{encodeURIComponent('b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f')}/providers/@{encodeURIComponent('Microsoft.Resources.ResourceGroups')}/resource/eventSubscriptions",
                    "queries": {
                        "x-ms-api-version": "2017-09-15-preview"
                    }
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnectionWebhook"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureeventgrid": {
                    "connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/azureeventgrid",
                    "connectionName": "azureeventgrid",
                    "id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/azureeventgrid"
                },
                "office365": {
                    "connectionId": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastus/managedApis/office365"
                }
            }
        }
    }
}

结果:

相关问题