配置自定义警报来监视播发路由Configure custom alerts to monitor advertised routes

可以根据本文的要求,使用 Azure 自动化和逻辑应用来持续监视从 ExpressRoute 网关播发到本地网络的路由数量。This article helps you use Azure Automation and Logic Apps to constantly monitor the number of routes advertised from the ExpressRoute gateway to on-premises networks. 可以通过监视来避免达到 200 个路由的限制Monitoring can help prevent hitting the 200 routes limit.

Azure 自动化 允许你自动执行存储在 runbook中的自定义 PowerShell 脚本。Azure Automation allows you to automate execution of custom PowerShell script stored in a runbook. 使用本文中的配置时,可以通过 runbook 中包含的 PowerShell 脚本来查询一个或多个 ExpressRoute 网关。When using the configuration in this article, the runbook contains a PowerShell script that queries one or more ExpressRoute gateways. 它收集的数据集包含资源组、ExpressRoute 网关名称以及在本地播发的网络前缀数量。It collects a dataset containing the resource group, ExpressRoute gateway name, and number of network prefixes advertised on-premises.

Azure 逻辑应用 会计划一个可调用 Azure 自动化 runbook 的自定义工作流。Azure Logic Apps schedules a custom workflow that calls the Azure Automation runbook. runbook 的执行使用作业来完成。The execution of the runbook is done using a job. 在数据收集操作运行后,Azure 逻辑应用工作流会对数据进行分类,并会根据高于或低于某个预定义阈值的网络前缀数的匹配条件向目标电子邮件地址发送消息。After data collection runs, the Azure Logic Apps workflow classifies the data and, based on match criteria on number of network prefixes above or below a predefine threshold, sends information to a destination email address.

工作流Workflow

自定义警报的设置基于三个主要步骤:Setting up a custom alert is based on three main steps:

  1. 使用“运行方式”帐户和权限创建自动化帐户。Create an Automation Account with a "Run As" account and permissions.

  2. 创建并配置 runbook。Create and configure runbooks.

  3. 如果数目大于阈值(例如 160),则创建一个逻辑应用来触发自动化帐户并发送警报电子邮件。Create a logic app that will fire the Automation Account and send an alerts e-mail if the number is greater than a threshold (for example, 160).

准备工作Before you begin

在开始配置之前,请验证是否符合以下条件:Verify that you have met the following criteria before beginning your configuration:

  • 你的部署中至少有一个 ExpressRoute 网关。You have at least one ExpressRoute gateway in your deployment.

  • 你对 Azure 自动化中的运行方式帐户有一个基本的了解。You have a basic understanding of Run As accounts in Azure Automation.

  • 你熟悉 Azure 逻辑应用You are familiar with Azure Logic Apps.

  • 你熟悉如何使用 Azure PowerShell。You are familiar with using Azure PowerShell. 需要使用 Azure PowerShell 在 ExpressRoute 网关上收集网络前缀。Azure PowerShell is required to collect the network prefixes in ExpressRoute gateway. 有关一般 Azure PowerShell 的详细信息,请参阅 Azure PowerShell 文档For more information about Azure PowerShell in general, see the Azure PowerShell documentation.

说明和限制Notes and limitations

  • 本文中讨论的自定义警报是一个加载项,可实现更好的操作和控制。The custom alert discussed in this article is an add-on to achieve better operation and control. 它不能替代 ExpressRoute 中的原生警报。It is not a replacement for the native alerts in ExpressRoute.
  • ExpressRoute 网关的数据收集操作在后台运行。Data collection for ExpressRoute gateways runs in the background. 运行时间可能会超出预期。Runtime can be longer than expected. 若要避免作业队列,必须正确设置工作流重复周期。To avoid job queuing, the workflow recurrence must be set up properly.
  • 通过脚本或 ARM 模板进行的部署可能比自定义警报触发器更快。Deployments by scripts or ARM templates could happen faster than the custom alarm trigger. 这可能会导致 ExpressRoute 网关中的网络前缀数量增长为超过 200 个路由的限制。This could result in increasing in number of network prefixes in ExpressRoute gateway above the limit of 200 routes.

创建和配置帐户Create and configure accounts

在 Azure 门户中创建自动化帐户时,会自动创建运行方式帐户。When you create an Automation account in the Azure portal, a Run As account is automatically created. 此帐户执行以下操作:This account takes following actions:

  • 使用自签名证书创建 Azure Active Directory (Azure AD) 应用程序。Creates an Azure Active Directory (Azure AD) application with a self-signed certificate. 运行方式帐户本身具有默认情况下需要每年续订的证书。The Run As account itself has a certificate that needs to be renewed by default every year.

  • 在 Azure AD 中为应用程序创建服务主体帐户。Creates a service principal account for the application in Azure AD.

  • 在使用的 Azure 订阅上为帐户本身分配参与者角色 (Azure RBAC)。Assigns itself the Contributor role (Azure RBAC) on the Azure Subscription in use. 此角色使用 runbook 管理 Azure 资源管理器资源。This role manages Azure Resource Manager resources using runbooks.

若要创建自动化帐户,你需要具有特权和权限。In order to create an Automation account, you need privileges and permissions. 有关信息,请参阅创建自动化帐户所需的权限For information, see Permissions required to create an Automation account.

1.创建自动化帐户1. Create an automation account

使用运行方式权限创建自动化帐户。Create an Automation account with run-as permissions. 有关说明,请参阅创建 Azure 自动化帐户For instructions, see Create an Azure Automation account.

添加自动化帐户

2.为运行方式帐户分配角色2. Assign the Run As account a role

默认情况下,将为 运行方式 帐户所使用的服务主体分配 参与者 角色。By default, the Contributor role is assigned to the service principal that is used by your Run As account. 你可以保留分配给服务主体的默认角色,也可以通过分配内置角色(例如,读取者)或自定义角色来限制权限。You can keep the default role assigned to the service principal, or you can restrict permissions by assigning a built-in role (for example, Reader) or a custom role.

请使用以下步骤来确定分配给运行方式帐户所使用的服务主体的角色:Use the following steps to determine the role assign to the service principal that is used by your Run As account:

  1. 导航到自动化帐户。Navigate to your Automation account. 导航到“帐户设置”,然后选择“运行方式帐户”。 Navigate to Account Settings, then select Run as accounts.

  2. 选择“角色”,以查看正在使用的角色定义。Select Roles to view the role definition that is being used.

    分配角色

创建并配置 runbookCreate and configure runbooks

1.安装模块1. Install modules

若要在 Azure 自动化 runbook 中运行 PowerShell cmdlet,需要安装几个其他的 Azure PowerShell Az 模块。In order to run PowerShell cmdlets in Azure Automation runbooks, you need to install a few additional Azure PowerShell Az modules. 使用以下步骤安装模块:Use the following steps to install the modules:

  1. 打开你的 Azure 自动化帐户并导航到“模块”。Open your Azure Automation Account and navigate to Modules.

    导航到模块

  2. 搜索库并导入以下模块:Az.AccountsAz.NetworkAz.AutomationAz.ProfileSearch the Gallery and import the following modules: Az.Accounts, Az.Network, Az.Automation, and Az.Profile.

    搜索并导入模块

2.创建 runbook2. Create a runbook

  1. 若要创建 PowerShell runbook,请导航到你的自动化帐户。To create your PowerShell runbook, navigate to your Automation Account. 在“流程自动化”下选择“Runbook”磁贴,然后选择“创建 runbook”。Under Process Automation, select the Runbooks tile, and then select Create a runbook.

    创建 runbook。

  2. 选择“创建”以创建 runbook。Select Create to create the runbook.

    选择“创建”。

  3. 选择新创建的 runbook,然后选择“编辑”。Select the newly created runbook, then select Edit.

    编辑 Runbook

  4. 在“编辑”中,粘贴 PowerShell 脚本。In Edit, paste the PowerShell script. 可以修改示例脚本并使用它来监视一个或多个资源组中的 ExpressRoute 网关。The Example script can be modified and used to monitor ExpressRoute gateways in one or more resource groups.

    在示例脚本中,请注意以下设置:In the example script, notice the following settings:

    • 数组 $rgList 包含带 ExpressRoute 网关的资源组的列表。The array $rgList contains the list of resource groups with ExpressRoute gateways. 你可以自定义基于列表的 ExpressRoute 网关。You can customize the list-based ExpressRoute gateways.
    • 变量 $thresholdNumRoutes 定义从 ExpressRoute 网关播发到本地网络的网络前缀数的阈值。The variable $thresholdNumRoutes define the threshold on the number of network prefixes advertised from an ExpressRoute gateway to the on-premises networks.

示例脚本Example script

  ################# Input parameters #################
# Resource Group Name where the ExR GWs resides in
$rgList= @('ASH-Cust10-02','ASH-Cust30')  
$thresholdNumRoutes = 160
###################################################

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process | Out-Null

Try {

   $conn = Get-AutomationConnection -Name 'AzureRunAsConnection'
   while(!($connectionResult) -And ($logonAttempt -le 5))
   {
        $LogonAttempt++
        # Logging in to Azure...
        $connectionResult =  Connect-AzAccount `
                               -ServicePrincipal `
                               -ApplicationId $conn.ApplicationId `
                               -Tenant $conn.TenantId `
                               -CertificateThumbprint $conn.CertificateThumbprint `
                               -Subscription $conn.SubscriptionId `
                               -Environment AzureCloud 
                               
        Start-Sleep -Seconds 10
    }
} Catch {
    if (!$conn)
    {
        $ErrorMessage = "Service principal not found."
        throw $ErrorMessage
    } 
    else
    {
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

# Get the name of the Azure subscription
$subscriptionName=(Get-AzSubscription -SubscriptionId $conn.SubscriptionId).Name

#write-Output "<br>$(Get-Date) - selection of the Azure subscription: $subscriptionName" 
Select-AzSubscription -SubscriptionId $conn.SubscriptionId | Out-Null


$GtwList = @()
$results= @()

foreach ($rgName in $rgList)
{
## Collect all the ExpressRoute gateways in a Resource Group
$GtwList=Get-AzVirtualNetworkGateway -ResourceGroupName $rgName 

## For each ExpressRoute gateway, get the IP addresses of the BGP peers and collect the number of routes advertised 
foreach ($gw in $GtwList) {
  
  $peers = Get-AzVirtualNetworkGatewayBGPPeerStatus -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName


 if ($peers[0].State -eq 'Connected') {
   $routes1=$null
   $routes1 = Get-AzVirtualNetworkGatewayAdvertisedRoute -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName -Peer $peers[0].Neighbor
 }
  if ($peers[1].State -eq 'Connected') {
  
   $routes2=$null
   $routes2 = Get-AzVirtualNetworkGatewayAdvertisedRoute -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName -Peer $peers[1].Neighbor
 }
 
  $sampleTime=(Get-Date).ToString("dd-MM-yyyy HH:mm:ss")
  if ($routes1.Count -eq $routes2.Count)
  {
     
     if ($routes1.Count -lt $thresholdNumRoutes){
       $status='OK'
       $alertMsg='number of routes below threshold'
     } 
     else {
       $status='ALERT'
       $alertMsg='number of routes above threshold'
     }
  } 
  else
  {
     $status='WARNING'
     $alertMsg='check ER Gateway'
  }
  
  $obj = [psCustomObject]@{
            resourceGroup =$rgName
            nameGtw  = $gw.Name
            peer1 = $peers[0].Neighbor
            peer2 = $peers[1].Neighbor
            numRoutesPeer1=  $routes1.Count
            numRoutesPeer2=  $routes2.Count
            time=$sampleTime
            status=$status
            alertMessage = $alertMsg
        }
  $results += $obj
} ### end foreach gateways in each resource group
} ### end foreach resource group
$jsonResults= ConvertTo-Json $results -Depth 100
Write-Output  $jsonResults
 

3.保存并发布 runbook3. Save and publish the runbook

  1. 选择“保存”以保存 runbook 的草稿副本。Select Save to save a draft copy of the runbook.

  2. 选择“发布”,将此 runbook 作为正式版 runbook 发布到自动化帐户中。Select Publish to publish the runbook as the official version of the runbook in the automation account.

    保存并发布 runbook。

当你运行 PowerShell 脚本时,系统会收集一个值列表:When you run the PowerShell script, a list of values is collected:

  • 资源组Resource group

  • ExpressRoute 网关名称ExpressRoute gateway name

  • 第一个 BGP 对等机 (peer1) 的 IP 地址IP address of the first BGP peer (peer1)

  • 第二个 BGP 对等机 (peer2) 的 IP 地址IP address of the second BGP peer (peer2)

  • 从 ExpressRoute 网关播发到第一个 BGP 对等机 (peer1) 的网络前缀数Number of network prefixes advertised from the ExpressRoute gateway to the first BGP peer (peer1)

  • 从 ExpressRoute 网关播发到第二个 BGP 对等机 (peer2) 的网络前缀数Number of network prefixes advertised from the ExpressRoute gateway to the second BGP peer (peer2)

  • TimestampTimestamp

  • 状态,分类为:Status, classified as:

    • “正常”(如果路由数小于阈值)'OK' if the number of routes is less than a threshold value
    • “警报”(如果路由数高于阈值)'ALERT' if the number of routes if above a threshold value
    • “警告”(如果播发到两个 BGP 对等机的网络前缀的数目不同)'WARNING' if the number of network prefixes advertised to the two BGP peer is different
  • 警报消息:对状态(正常、警报、警告)的详细说明Alert message, for a verbose description of the status (OK, ALERT, WARNING)

PowerShell 脚本会将收集的信息转换为 JSON 输出。The PowerShell script converts the collected information to a JSON output. runbook 使用 PowerShell cmdlet Write-Output 作为输出流,以便将信息传递到客户端。The runbook uses the PowerShell cmdlet Write-Output as Output stream to communicate information to the client.

4.验证 runbook4. Validate the runbook

创建 runbook 后,必须对其进行验证。Once the runbook is created, it must be validated. 请选择“启动”并检查不同作业流的输出和错误。Select Start and check the output and errors for the different job streams.

验证 runbook

创建并配置逻辑应用Create and configure a logic app

Azure 逻辑应用是集合和操作的所有流程的业务流程协调程序。Azure Logic Apps is the orchestrator of all process of collection and actions. 在以下各部分中,你将使用逻辑应用构建工作流。In the following sections, you build a workflow using a logic app.

工作流Workflow

在此工作流中,我们构建一个逻辑应用来定期监视 ExpressRoute 网关。In this workflow, you build a logic app that regularly monitors ExpressRoute gateways. 如果存在新项,逻辑应用会针对每个项发送电子邮件。If new items exist, the logic app sends an email for each item. 完成后,逻辑应用看起来大致与以下工作流类似:When you're done, your logic app looks like this workflow at a high level:

逻辑应用工作流

1.创建逻辑应用1. Create a logic app

在“逻辑应用设计器”中,使用“空白逻辑应用”模板创建逻辑应用。In Logic app designer, create a logic app using the Blank Logic App template. 有关步骤,请参阅创建逻辑应用For steps, see Create Logic Apps.

空白模板

2.添加触发器2. Add a trigger

每个逻辑应用都由触发器启动。Every logic app is started by a trigger. 触发器在发生特定事件时或特定条件得到满足时触发。A trigger fires when a specific event happens, or when a specific condition is met. 每当触发器触发时,Azure 逻辑应用引擎就会创建一个逻辑应用实例来启动并运行工作流。Each time the trigger fires, the Azure Logic Apps engine creates a logic app instance that starts and runs your workflow.

若要定期运行基于预定义时间计划的逻辑应用,请向工作流添加内置的“重复周期:计划”。To regularly run a logic app that is based on a predefine time schedule, add the built-in Recurrence: Schedule to your workflow. 在搜索框中键入“计划”。In the search box, type schedule. 选择“触发器”。Select Triggers. 从“触发器”列表中选择“重复周期计划”。From the Triggers list, select Recurrence Schedule.

重复周期:计划

在“重复周期计划”触发器中,可以设置时区以及重复执行该工作流时需遵循的重复周期。In the Recurrence Schedule trigger, you can set the time zone and a recurrence for repeating that workflow. 时间间隔和频率合在一起,即可定义逻辑应用的触发器的计划。Together, the interval and frequency define the schedule for your logic app's trigger. 若要确定合理的最小重复频率,请考虑以下因素:To establish a reasonable minimum recurrence frequency, consider the following factors:

  • 自动化 runbook 中的 PowerShell 脚本需要一定的时间才能完成。The PowerShell script in the Automation runbook takes time to complete. 运行时间取决于要监视的 ExpressRoute 网关数。The runtime depends on the number of ExpressRoute gateways to monitor. 重复频率太高会导致作业排队。A too short recurrence frequency will cause job queuing.

  • PowerShell 脚本作为作业在后台运行。The PowerShell script runs as a job in background. 它不会立即启动,而是在延迟一段时间(可变)后运行。It doesn’t start immediately; it runs after a variable delay.

  • 重复频率太高会在 Azure ExpressRoute 网关上生成不必要的负载。A too short recurrence frequency will generate unneeded load on your Azure ExpressRoute gateways.

在工作流配置结束时,可以通过多次运行工作流来检查重复频率的一致性,然后在“运行历史记录”中验证结果。At the end of the workflow configuration, you can check the consistency of the recurrence frequency by running the workflow a few times, and then verifying the outcome in the Runs history.

定期

3.创建作业3. Create a job

逻辑应用通过连接器访问其他应用、服务和平台。A logic app accesses other apps, services, and the platform though connectors. 在此工作流中,下一步是选择连接器以访问先前定义的 Azure 自动化帐户。The next step in this workflow is to select a connector to access the Azure Automation account that was defined earlier.

  1. 在“逻辑应用设计器”中,在“定期”下 选择“新建步骤”。In Logic Apps Designer, below Recurrence, select New step. 在“选择操作”和搜索框下,选择“全部” 。Under Choose an action and the the search box, select All.

  2. 在搜索框中键入“Azure 自动化”,然后进行搜索。In the search box, type Azure Automation and search. 选择“创建作业”。Select Create job. “创建作业”将用于触发先前创建的自动化 runbook。Create job will be used to fire the automation runbook that was created earlier.

    创建作业

  3. 使用一个服务主体登录。Sign in using a service principal. 可以使用现有的服务主体,也可以创建一个新的。You can use an existing service principal, or you can create a new one. 若要创建新的服务主体,请参阅如何使用门户创建可访问资源的 Azure AD 服务主体To create a new service principal, see How to use the portal to create an Azure AD service principal that can access resources. 选择“通过服务主体进行连接”。Select Connect with Service Principal.

    登录

  4. 键入一个 连接名称,然后添加你的 客户端 ID(应用程序 ID)、客户端机密租户 IDType a Connection Name, add your Client ID (Application ID), Client Secret, and your Tenant ID. 然后选择“创建”。Then, select Create.

    通过服务主体进行连接

  5. 在“创建作业”页上,服务主体应在承载自动化帐户的 资源组 上具有“读取者”角色,并在 自动化帐户 上具有“自动化作业操作员”角色。On the Create job page, the service principal should have the "Reader" role on the Resource Group hosting the automation account, and "Automation Job Operator" on the Automation Account. 此外,请验证是否已将“Runbook 名称”添加为新参数。Additionally, verify that you have added the Runbook Name as a new parameter.

    角色

4.获取作业输出4. Get the job output

  1. 选择“新建步骤”。Select New step. 搜索“Azure 自动化”。Search for "Azure Automation". 从“操作”列表中选择“获取作业输出”。 From the Actions list, select Get job output.

    获取作业输出

  2. 在“获取作业输出”页上,指定访问自动化帐户所需的信息。On the Get job output page, specify the required information to access to the automation account. 选择要使用的“订阅”、“资源组”和“自动化帐户”。Select the Subscription, Resource Group, and Automation Account that you want to use. 在“作业 ID”框内单击。Click inside the Job ID box. 当“动态内容”列表出现时,选择“作业 ID”。 When the Dynamic content list appears, select Job ID.

    作业 ID

5.分析 JSON5. Parse the JSON

“Azure 自动化的‘创建作业’操作”(前面的步骤)的输出中包含的信息会生成一个 JSON 对象。The information contained in the output from the 'Azure Automation Create job action' (previous steps) generates a JSON object. 逻辑应用的“分析 JSON”是一个内置操作,用于基于 JSON 内容中的属性及其值创建用户易记的令牌。Logic Apps Parse JSON is a built-in action to create user-friendly tokens from the properties and their values in JSON content. 然后,你可以在工作流中使用这些属性。You can then use those properties in your workflow.

  1. 添加操作。Add an action. 在“获取作业输出 -> 操作”下,选择“新建步骤”。 Under the Get job output ->action, select New step.

  2. 在“选择操作”搜索框中键入“分析 json”以搜索提供此操作的连接器。In the Choose an action search box, type "parse json" to search for connectors that offer this action. 在“操作”列表中,选择与要使用的数据操作相对应的“分析 JSON”操作。Under the Actions list, select the Parse JSON action for the data operations that you want to use.

    分析 JSON

  3. 在“内容”框中单击。Click inside the Content box. 当“动态内容”列表出现时,选择“内容”。When the Dynamic content list appears, select Content.

    内容

  4. 分析 JSON 需要一个架构。Parsing a JSON requires a schema. 可以使用自动化 runbook 的输出来生成架构。The schema can be generated using the output of the Automation runbook. 打开一个新的 Web 浏览器会话,运行自动化 runbook 并捕获输出。Open a new web browser session, run the Automation runbook and grab the output. 返回到“逻辑应用的分析 JSON 数据操作”操作。Return to the Logic Apps Parse JSON Data Operations action. 在页面底部,选择“使用示例有效负载生成架构”。At the bottom of the page, select Use sample payload to generate schema.

    使用示例有效负载生成架构

  5. 对于“输入或粘贴示例 JSON 有效负载”,请粘贴自动化 runbook 的输出,然后选择“完成”。For Enter or paste a sample JSON payload, paste the output of the Automation runbook and select Done.

    粘贴示例有效负载

  6. 架构是通过对 JSON 输入有效负载进行分析自动生成的。A schema is automatically generated by parsing the JSON input payload.

    生成架构

6.定义并初始化变量6. Define and initialize a variable

在工作流的此步骤中,我们创建一个通过电子邮件发送警报所需的条件。In this step of the workflow, we create a condition to send an alarm by email. 为了对电子邮件正文消息进行灵活的自定义格式设置,我们在工作流中引入了一个辅助变量。For a flexible, custom formatting of an email body message, an auxiliary variable is introduced in the workflow.

  1. 在“获取作业输出”操作下,选择“新建步骤”。 Under the Get job output action, select New step. 在搜索框中找到并选择“变量”。In the search box, find and select Variables.

    变量

  2. 在“操作”列表中,选择“初始化变量”操作。 From the Actions list, select the Initialize variable action.

    初始化变量

  3. 指定变量的名称。Specify the name of the variable. 对于“类型”,请选择“字符串” 。For Type, select String. 稍后将在工作流中分配变量的 The Value of the variable will be assigned later in the workflow.

    字符串

7.创建“For each”操作7. Create a "For each" action

分析 JSON 后,“分析 JSON 数据操作”操作会将内容存储在“正文”输出中。Once the JSON is parsed, the Parse JSON Data Operations action stores the content in the Body output. 为了处理输出,可以创建一个“For each”循环,对数组中的每一项重复执行一个或多个操作。To process the output, you can create a "For each" loop repeating one or more actions on each item in the array.

  1. 在“初始化变量”下,选择“添加操作”。Under Initialize variable, select Add an action. 在搜索框中键入“for each”作为筛选器。In the search box, type "for each" as your filter.

    控制

  2. 从“操作”列表中选择“For each - 控制”操作。From the Actions list, select the action For each - Control.

    For each - 控制

  3. 单击“从先前的步骤中选择一个输出”文本框。Click in the Select an output from previous steps text box. 当“动态内容”列表出现时,请选择“正文”,这是分析的 JSON 的输出。 When the Dynamic content list appears, select the Body, which is output from the parsed JSON.

    正文

  4. 对于 JSON 正文的每个元素,我们需要设置一个条件。For each element of JSON body, we want to set a condition. 从操作组中选择“控制”。From the action group, select Control.

    控制

  5. 在“操作”列表中选择“条件-控制”。 In the Actions list, select Condition-Control. 条件-控制是一个控制结构,可将工作流中的数据与特定值或字段进行比较。The Condition-Control is a control structure compares the data in your workflow against specific values or fields. 然后,可以指定不同的操作,这些操作是否运行取决于数据是否符合条件。You can then specify different actions that run based on whether or not, the data meets the condition.

    条件控制

  6. 在“条件”操作的根中,将逻辑操作更改为“或”。In the root of Condition action, change the logic operation to Or.

    Or

  7. 检查 ExpressRoute 网关播发到两个 BGP 对等机的网络前缀数的值。Check the value for the number of network prefixes an ExpressRoute gateway advertises to the two BGP peers. 路由数在“动态内容”中的“numRoutePeer1”和“numRoutePeer2”中提供。The number of routes is available in "numRoutePeer1" and "numRoutePeer2" in Dynamic content. 在“值”框中,键入“numRoutePeer1”的值。In the value box, type the value for numRoutePeer1.

    numRoutesPeer1

  8. 若要在条件中添加其他行,请选择“添加”->“添加行”。To add another row to your condition, choose Add -> Add row. 在第二个框中,从“动态内容”选择“numRoutePeer2”。In the second box, from Dynamic content, select numRoutePeer2.

    numRoutesPeer2

  9. 如果两个动态变量中的一个(numRoute1 或 numRoute2)大于阈值,则逻辑条件为 true。The logic condition is true when one of two dynamic variables, numRoute1 or numRoute2, is greater than the threshold. 在此示例中,阈值固定为 160(200 个路由这一最大值的 80%)。In this example, the threshold is fixed to 160 (80% of max value of 200 routes). 你可以更改阈值来适应你的需求。You can change the threshold value to fit your requirements. 为了保持一致性,此值应与 runbook PowerShell 脚本中使用的值相同。For consistency, the value should be the same value used in the runbook PowerShell script.

    逻辑条件

  10. 在“如果为 true”下,格式化并创建可通过电子邮件发送警报的操作。Under If true, format and create the actions to send the alert by email. 在“选择操作”**中,搜索并选择“变量”。In **Choose an action, search and select Variables.

    如果为 true

  11. 在“变量”中,选择“添加操作”。In Variables, select Add an action. 在“操作”列表中,选择“设置变量”。 In the Actions list, select Set variable.

    设置变量

  12. 在“名称”中,选择前面创建的名为 EmailBody 的变量。In Name, select the variable named EmailBody that you previously created. 对于“值”,请粘贴设置警报电子邮件格式所需的 HTML 脚本。For Value, paste the HTML script required to format the alert email. 使用“动态内容”来包括 JSON 正文的值。Use the Dynamic content to include the values of JSON body. 配置这些设置后,获得的结果就是:变量 Emailbody 包含 HTML 格式的与警报相关的所有信息。After configuring these settings, the result is that the variable Emailbody contains all the information related to the alert, in HTML format.

    设置变量

8.添加电子邮件连接器8. Add the Email connector

逻辑应用提供了许多电子邮件连接器。Logic Apps provides many email connectors. 在此示例中,我们将添加通过电子邮件发送警报所需的 Outlook 连接器。In this example, we add an Outlook connector to send the alert by email. 在“设置变量”下,选择“添加操作”。Under Set variable, select Add an action. 在“选择操作”中,在搜索框中键入“发送电子邮件”。In Choose an action, type "send email" in the search box.

  1. 选择“Office 365 Outlook”。Select Office 365 Outlook.

    发送电子邮件

  2. 在“操作”列表中选择“发送电子邮件(V2)”。 In the Actions list, select Send an email(V2).

    发送电子邮件(V2)

  3. 登录以创建到 Office 365 Outlook 的连接。Sign in to create a connection to Office 365 Outlook.

    登录

  4. 在“正文”字段中,单击“添加动态内容”。In the Body field, click Add dynamic content. 在“动态内容”面板中,添加“Emailbody”变量。From the Dynamic content panel, add the the variable Emailbody. 填写“主题”和“收件人”字段。 Fill out the Subject and To fields.

    正文

  5. “发送电子邮件(V2)”操作完成工作流设置。The Send an email (v2) action complete the workflow setup.

    发送电子邮件 v2

9.工作流验证9. Workflow validation

最后一步是工作流验证。The final step is the workflow validation. 在“逻辑应用概览”中,选择“运行触发器” 。In Logic Apps Overview, select Run Trigger. 选择“重复周期”。Select Recurrence. 可以在“运行历史记录”中监视和验证工作流。The workflow can be monitored and verified in the Runs history.

运行触发器

后续步骤Next steps

若要详细了解如何自定义工作流,请参阅 Azure 逻辑应用To learn more about how to customize the workflow, see Azure Logic Apps.