事件网格将事件筛选到订阅中的所有 Azure 函数



我正在尝试筛选事件网格中的事件,使其仅在订阅中的 Azure 函数更改(例如配置更改、代码更新或创建新/删除新函数(时触发。

我使用的PowerShell脚本如下:

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "https://myendpoint-function.azurewebsites.net"
$subscriptionId = "abcde-34df-4493-9477-notrealid980"
$eventSubscriptionName = "FunctionConfigChanges"
# Select the Azure subscription you want to subscribe to. You need this command only if the 
# current subscription is not the one you wish to subscribe to.
Set-AzContext -Subscription $subscriptionId
$includedEventTypes = "Microsoft.Resources.ResourceActionSuccess", "Microsoft.Resources.ResourceDeleteSuccess", "Microsoft.Resources.ResourceWriteSuccess"
$AdvancedFilters = @{operator="StringContains"; key="Subject"; Values=@("providers/Microsoft.Web/sites")}
New-AzEventGridSubscription -Endpoint $myEndpoint -EventSubscriptionName $eventSubscriptionName -IncludedEventType $includedEventTypes -AdvancedFilter $AdvancedFilters

这将过滤到所有功能和网站(选中$AdvancedFilters(。有没有办法让事件仅筛选到 Azure 函数? 欢迎在 Azure CLI、门户、Powershell 或 .net sdk 中使用任何类型的解决方案帮助。

根据您的要求,可以使用以下属性,请注意,操作名称和操作位于数据对象中:

  1. 创建函数

    "eventType":"Microsoft.Resources.ResourceWriteSuccess"
    "operationName":"Microsoft.Web/sites/functions/write"
    
  2. 删除功能

    "eventType":"Microsoft.Resources.ResourceDeleteSuccess"   
    "operationName":"Microsoft.Web/sites/functions/delete"
    
  3. 代码已更新(运行.csx 文件(:

    "eventType":"Microsoft.Resources.ResourceWriteSuccess"
    "operationName":"Microsoft.Web/sites/hostruntime/vfs/run.csx/write"
    
  4. 配置已更改

    "eventType":"Microsoft.Resources.ResourceWriteSuccess"
    "operationName":"Microsoft.Web/sites/config/write"
    

    请注意,订阅主题应用服务(目前在预览版中(时,我们可以筛选以下内容 性能:

    "eventType":"Microsoft.Web.AppUpdated"
    "action":"ChangedAppSettings
    

订阅者可以从主题属性中找到函数应用(应用服务(和特定函数的名称。

以下示例演示如何根据上述要求设置筛选属性:

"filter": {
"subjectBeginsWith": "",
"subjectEndsWith": "",
"includedEventTypes": [
"Microsoft.Resources.ResourceWriteSuccess",
"Microsoft.Resources.ResourceDeleteSuccess"
],
"advancedFilters": [
{
"values": [
"Microsoft.Web/sites/functions/write",
"Microsoft.Web/sites/functions/delete",
"Microsoft.Web/sites/hostruntime/vfs/run.csx/write",
"Microsoft.Web/sites/config/write"
],
"operatorType": "StringIn",
"key": "Data.operationName"
}
]

}

最新更新