Query di avviso di ricerca log di esempio che includono ADX e ARG

Una regola di avviso di ricerca log monitora una risorsa usando una query di Log Analytics per valutare i log a una frequenza impostata. È possibile includere i dati di Azure Esplora dati e Azure Resource Graph nelle query delle regole di avviso di ricerca log.

Questo articolo fornisce esempi di query sulle regole di avviso di ricerca log che usano Azure Esplora dati e Azure Resource Graph. Per altre informazioni sulla creazione di una regola di avviso di ricerca log, vedere Creare una regola di avviso di ricerca log.

Query che controllano l'integrità della macchina virtuale

Questa query trova le macchine virtuali contrassegnate come critiche che non hanno avuto un heartbeat negli ultimi 2 minuti.

    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

Questa query trova le macchine virtuali contrassegnate come critiche che hanno avuto un heartbeat più di 24 ore fa, ma che non hanno avuto un heartbeat negli ultimi 2 minuti.

{
    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
}

Query che filtra le macchine virtuali che devono essere monitorate

   {
    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)) 
}

Query che trova le risorse con certificati che scadono entro 30 giorni

{
    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
}

Query che avvisa quando viene creata una nuova risorsa nella sottoscrizione

{
    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

}

Passaggi successivi