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

Event grid filter events to all Azure functions in subscription

我正在尝试过滤事件网格中的事件,以便仅当我的订阅中的 Azure 功能发生变化时才触发(比如配置更改、代码更新或新功能 created/deleted)。

我使用的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 中提供任何类型的解决方案帮助。

根据您的要求,可以使用以下属性,请注意 operationNameaction 在数据对象中:

  1. 创建函数:

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

    "eventType":"Microsoft.Resources.ResourceDeleteSuccess"   
    "operationName":"Microsoft.Web/sites/functions/delete"
    
  3. 代码已更新(run.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"
    

    请注意,订阅主题 App Service(目前处于预览阶段)我们可以过滤以下内容 属性:

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

订阅者可以从主题属性.

中找到功能应用(App Service)的名称和具体功能

以下示例显示了根据上述要求设置过滤属性:

"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"
  }
]

}