클래식 경고 규칙 마이그레이션을 위한 논리 앱 및 Runbook 준비

참고

이전에 발표한 것처럼 Azure Monitor의 클래식 경고는 퍼블릭 클라우드 사용자에 대해 사용 중지되었지만 2021년 5월 31일까지는 제한적으로 사용할 수 있습니다. 21Vianet에서 운영하는 Azure Government 클라우드 및 Microsoft Azure에 대한 클래식 경고는 2024년 2월 29일에 사용 중지됩니다.

기존 경고 규칙을 새 경고 규칙으로 자발적으로 마이그레이션하기로 선택한 경우 두 시스템 간에 몇 가지 차이점이 있습니다. 이 문서에서는 이러한 차이점과 변경에 대비하는 방법에 대해 설명합니다.

API 변경 내용

클래식 경고 규칙(microsoft.insights/alertrules)을 만들고 관리하는 API는 새 메트릭 경고(microsoft.insights/metricalerts)를 만들고 관리하는 API와 다릅니다. 지금 클래식 경고 규칙을 프로그래밍 방식으로 만들고 관리하는 경우 새 API와 함께 작동하도록 배포 스크립트를 업데이트합니다.

다음 표는 클래식 경고와 새 경고 모두에 대한 프로그래밍 방식 인터페이스에 대한 참조입니다.

배포 스크립트 형식 클래식 경고 새 메트릭 경고
REST API microsoft.insights/alertrules microsoft.insights/metricalerts
Azure CLI az monitor alert az monitor metrics alert
PowerShell 참조 참조
Azure Resource Manager 템플릿 클래식 경고의 경우 새 메트릭 경고의 경우

알림 페이로드 변경 내용

알림 페이로드 형식은 클래식 경고 규칙새 메트릭 경고 간에 약간 다릅니다. 웹후크, 논리 앱 또는 Runbook 작업이 포함된 클래식 경고 규칙이 있는 경우 새 페이로드 형식을 허용하도록 대상을 업데이트해야 합니다.

다음 표를 사용하여 웹후크 페이로드 필드를 클래식 형식에서 새 형식으로 매핑합니다.

알림 엔드포인트 형식 클래식 경고 새 메트릭 경고
경고가 활성화되었거나 해결되었나요? status data.status
경고에 대한 컨텍스트 정보 context data.context
경고가 활성화되거나 해결된 타임스탬프 context.timestamp data.context.timestamp
경고 규칙 ID context.id data.context.id
경고 규칙 이름 context.name data.context.name
경고 규칙에 대한 설명 context.description data.context.description
경고 규칙 조건 context.condition data.context.condition
메트릭 이름 context.condition.metricName data.context.condition.allOf[0].metricName
시간 집계(평가 기간 동안 메트릭이 집계되는 방식) context.condition.timeAggregation context.condition.timeAggregation
평가 기간 context.condition.windowSize data.context.condition.windowSize
연산자(집계된 메트릭 값을 임계값과 비교하는 방법) context.condition.operator data.context.condition.operator
임계값 context.condition.threshold data.context.condition.allOf[0].threshold
메트릭 값 context.condition.metricValue data.context.condition.allOf[0].metricValue
구독 ID context.subscriptionId data.context.subscriptionId
영향을 받는 리소스의 리소스 그룹 context.resourceGroup data.context.resourceGroup
영향을 받는 리소스의 이름 context.resourceName data.context.resourceName
영향을 받는 리소스의 형식 context.resourceType data.context.resourceType
영향을 받는 리소스의 리소스 ID context.resourceId data.context.resourceId
포털 리소스 요약 페이지에 대한 직접 링크입니다. context.portalLink data.context.portalLink
웹후크 또는 논리 앱에 전달할 사용자 지정 페이로드 필드 properties data.properties

페이로드는 보시다시피 비슷합니다. 다음 섹션에서는 다음을 제공합니다.

  • 새 형식에서 작동하도록 논리 앱을 수정하는 방법에 대한 세부 정보입니다.
  • 새 경고에 대한 알림 페이로드를 구문 분석하는 Runbook 예제입니다.

메트릭 경고 알림을 수신하도록 논리 앱 수정

클래식 경고와 함께 논리 앱을 사용하는 경우 논리 앱 코드를 수정하여 새 메트릭 경고 페이로드를 구문 분석해야 합니다. 다음 단계를 수행합니다.

  1. 새 논리 앱을 만듭니다.

  2. "Azure Monitor - 메트릭 경고 처리기" 템플릿을 사용합니다. 이 템플릿에는 적절한 스키마가 정의된 HTTP 요청 트리거가 있습니다.

    스크린샷은 빈 논리 앱 및 Azure Monitor – 메트릭 경고 처리기 두 개의 단추를 보여줍니다.

  3. 처리 논리를 호스팅하는 작업을 추가합니다.

메트릭 경고 알림을 받는 자동화 Runbook 사용

다음 예제에서는 Runbook에서 사용할 PowerShell 코드를 제공합니다. 이 코드는 클래식 메트릭 경고 규칙과 새 메트릭 경고 규칙 모두에 대한 페이로드를 구문 분석할 수 있습니다.

## Example PowerShell code to use in a runbook to handle parsing of both classic and new metric alerts.

[OutputType("PSAzureOperationResponse")]

param
(
    [Parameter (Mandatory=$false)]
    [object] $WebhookData
)

$ErrorActionPreference = "stop"

if ($WebhookData)
{
    # Get the data object from WebhookData.
    $WebhookBody = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)

    # Determine whether the alert triggering the runbook is a classic metric alert or a new metric alert (depends on the payload schema).
    $schemaId = $WebhookBody.schemaId
    Write-Verbose "schemaId: $schemaId" -Verbose
    if ($schemaId -eq "AzureMonitorMetricAlert") {

        # This is the new metric alert schema.
        $AlertContext = [object] ($WebhookBody.data).context
        $status = ($WebhookBody.data).status

        # Parse fields related to alert rule condition.
        $metricName = $AlertContext.condition.allOf[0].metricName
        $metricValue = $AlertContext.condition.allOf[0].metricValue
        $threshold = $AlertContext.condition.allOf[0].threshold
        $timeAggregation = $AlertContext.condition.allOf[0].timeAggregation
    }
    elseif ($schemaId -eq $null) {
        # This is the classic metric alert schema.
        $AlertContext = [object] $WebhookBody.context
        $status = $WebhookBody.status

        # Parse fields related to alert rule condition.
        $metricName = $AlertContext.condition.metricName
        $metricValue = $AlertContext.condition.metricValue
        $threshold = $AlertContext.condition.threshold
        $timeAggregation = $AlertContext.condition.timeAggregation
    }
    else {
        # The schema is neither a classic metric alert nor a new metric alert.
        Write-Error "The alert data schema - $schemaId - is not supported."
    }

    # Parse fields related to resource affected.
    $ResourceName = $AlertContext.resourceName
    $ResourceType = $AlertContext.resourceType
    $ResourceGroupName = $AlertContext.resourceGroupName
    $ResourceId = $AlertContext.resourceId
    $SubId = $AlertContext.subscriptionId

    ## Your logic to handle the alert here.
}
else {
    # Error
    Write-Error "This runbook is meant to be started from an Azure alert webhook only."
}

경고가 트리거될 때 가상 머신을 중지하는 Runbook의 전체 예제는 Azure Automation documenation을 참조하세요.

웹후크를 통한 파트너 통합

대부분의 클래식 경고와 통합되는 파트너는 이미 통합을 통해 새로운 메트릭 경고를 지원합니다. 이미 새 메트릭 경고와 함께 작동하는 알려진 통합은 다음과 같습니다.

여기에 나열되지 않은 파트너 통합을 사용하는 경우 공급자에게 새 메트릭 경고와 함께 작동하는지 확인합니다.

다음 단계