ADX と ARG を含むログ検索アラート クエリのサンプル

ログ検索アラート ルールでは、Log Analytics クエリを使用してリソースを監視し、設定された頻度でログを評価します。 ログ検索アラート ルール クエリには、Azure Data エクスプローラー と Azure Resource Graph からのデータを含めることができます。

この記事では、Azure Data エクスプローラー と 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

}

次のステップ