ADX 및 ARG를 포함하는 샘플 로그 검색 경고 쿼리

로그 검색 경고 규칙은 Log Analytics 쿼리를 사용하여 설정된 빈도로 로그를 평가하여 리소스를 모니터링합니다. 로그 검색 경고 규칙 쿼리에 Azure Data Explorer 및 Azure Resource Graph의 데이터를 포함할 수 있습니다.

이 문서에서는 Azure Data Explorer 및 Azure Resource Graph를 사용하는 로그 검색 경고 규칙 쿼리의 예를 제공합니다. 로그 검색 경고 규칙을 만드는 방법에 대한 자세한 내용은 로그 검색 경고 규칙 만들기를 참조 하세요.

가상 머신 상태를 검사 쿼리

이 쿼리는 지난 2분 동안 하트비트가 없는 위험으로 표시된 가상 머신을 찾습니다.

    arg("").Resources
    | where type == "microsoft.compute/virtualmachines"
    | summarize LastCall = max(case(isnull(TimeGenerated), make_datetime(1970, 1, 1), TimeGenerated)) by name, id
    | extend SystemDown = case(LastCall < ago(2m), 1, 0)
    | where SystemDown == 1

이 쿼리는 24시간 전에 하트비트가 있었지만 지난 2분 동안 하트비트가 없었던 중요한 것으로 표시된 가상 머신을 찾습니다.

{
    arg("").Resources
    | where type == "microsoft.compute/virtualmachines"
    | where tags.BusinessCriticality =~ 'critical' and subscriptionId == '123-456-123-456'
    | join kind=leftouter (
    Heartbeat
    | where TimeGenerated > ago(24h)
    )
    on $left.name == $right.Resource
    | summarize LastCall = max(case(isnull(TimeGenerated), make_datetime(1970, 1, 1), TimeGenerated)) by name, id
    | extend SystemDown = case(LastCall < ago(2m), 1, 0)
    | where SystemDown == 1
}

모니터링해야 하는 가상 머신을 필터링하는 쿼리

   {
    let RuleGroupTags = dynamic(['Linux']);
    Perf | where ObjectName == 'Processor' and CounterName == '% Idle Time' and (InstanceName in ('_Total,'total'))
    | extend CpuUtilisation = (100 - CounterValue)   
    | join kind=inner hint.remote=left (arg("").Resources
        | where type =~ 'Microsoft.Compute/virtualMachines'
    | project _ResourceId=tolower(id), tags) on _ResourceId
    | project-away _ResourceId1
    | where  (tostring(tags.monitorRuleGroup) in (RuleGroupTags)) 
}

30일 이내에 만료되는 인증서가 있는 리소스를 찾는 쿼리

{
    arg("").Resources
    | where type == "microsoft.web/certificates"
    | extend ExpirationDate = todatetime(properties.expirationDate)
    | project ExpirationDate, name, resourceGroup, properties.expirationDate
    | where ExpirationDate < now() + 30d
    | order by ExpirationDate asc
}

구독에서 새 리소스를 만들 때 경고하는 쿼리

{
    arg("").resourcechanges
    | extend changeTime = todatetime(properties.changeAttributes.timestamp), 
    changeType = tostring(properties.changeType),targetResourceType = tostring(properties.targetResourceType),
    changedBy = tostring(properties.changeAttributes.changedBy),
    createdResource = tostring(properties.targetResourceId)
    | where changeType == "Create" and changeTime <ago(1h)
    | project changeTime,createdResource,changedBy

}

다음 단계