Skip to content

Commit e12dc73

Browse files
Merge pull request #269677 from davidsmatlak/ds-arg-alerts-samples-doc-20240320
Adds ARG alerts samples doc
2 parents a7c96a8 + 138fd1e commit e12dc73

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Azure Resource Graph alerts sample queries
3+
description: Sample queries that can be used to create alerts for your Azure resources using an Azure Resource Graph query and a Log Analytics workspace.
4+
ms.date: 03/20/2024
5+
ms.topic: sample
6+
---
7+
8+
# Azure Resource Graph alerts sample queries
9+
10+
This article includes sample queries that can be used to create alerts for Azure resources using Azure Resource Graph and a Log Analytics workspace. The samples must be run from a Log Analytics workspace.
11+
12+
For more information about alert queries, go to [Quickstart: Create alerts with Azure Resource Graph and Log Analytics](../alerts-query-quickstart.md).
13+
14+
> [!NOTE]
15+
> Azure Resource Graph alerts integration with Log Analytics is in public preview.
16+
17+
## Verify virtual machines health
18+
19+
This query finds virtual machines marked as critical that had a heartbeat more than 24 hours ago, but with no heartbeat in the last two minutes. Replace `11111111-1111-1111-1111-111111111111` with your Azure subscription ID.
20+
21+
```kusto
22+
arg("").Resources
23+
| where type == "microsoft.compute/virtualmachines"
24+
| where tags.BusinessCriticality =~ 'critical' and subscriptionId == '11111111-1111-1111-1111-111111111111'
25+
| join kind=leftouter (
26+
Heartbeat
27+
| where TimeGenerated > ago(24h)
28+
)
29+
on $left.name == $right.Resource
30+
| summarize LastCall = max(case(isnull(TimeGenerated), make_datetime(1970, 1, 1), TimeGenerated)) by name, id
31+
| extend SystemDown = case(LastCall < ago(2m), 1, 0)
32+
| where SystemDown == 1
33+
```
34+
35+
## Filter virtual machines to monitor
36+
37+
This query filters virtual machines that need to be monitored.
38+
39+
```kusto
40+
let RuleGroupTags = dynamic(['Linux']);
41+
Perf | where ObjectName == 'Processor' and CounterName == '% Idle Time' and (InstanceName in ('Total','total'))
42+
| extend CpuUtilisation = (100 - CounterValue)   
43+
| join kind=inner hint.remote=left (arg("").Resources
44+
| where type =~ 'Microsoft.Compute/virtualMachines'
45+
| project _ResourceId=tolower(id), tags
46+
)
47+
on _ResourceId
48+
| project-away _ResourceId1
49+
| where (tostring(tags.monitorRuleGroup) in (RuleGroupTags))
50+
```
51+
52+
## Find resources with certificates
53+
54+
This query finds resources with certificates that expire within 30 days.
55+
56+
```kusto
57+
arg("").Resources
58+
| where type == "microsoft.web/certificates"
59+
| extend ExpirationDate = todatetime(properties.expirationDate)
60+
| project ExpirationDate, name, resourceGroup, properties.expirationDate
61+
| where ExpirationDate < now() + 30d
62+
| order by ExpirationDate asc
63+
```
64+
65+
## Alerts when new resource created in subscription
66+
67+
This query alerts when a new resource is created in an Azure subscription.
68+
69+
```kusto
70+
arg("").resourcechanges
71+
| extend changeTime = todatetime(properties.changeAttributes.timestamp),
72+
changeType = tostring(properties.changeType),targetResourceType = tostring(properties.targetResourceType),
73+
changedBy = tostring(properties.changeAttributes.changedBy)
74+
| where changeType == "Create" and changeTime <ago(1h)
75+
| project changeTime, targetResourceType, changedBy
76+
```
77+
78+
## Next steps
79+
80+
For more information about the query language or how to explore resources, go to the following articles.
81+
82+
- [Understanding the Azure Resource Graph query language](../concepts/query-language.md)
83+
- [Explore your Azure resources with Resource Graph](../concepts/explore-resources.md)

articles/governance/resource-graph/toc.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@
5151
href: ./tutorials/logic-app-calling-arg.md
5252
- name: Samples
5353
items:
54-
- name: Language examples
55-
items:
56-
- name: Starter queries
57-
displayName: query language, data explorer, count, list, show
58-
href: ./samples/starter.md
59-
- name: Advanced queries
60-
displayName: query language, data explorer, list, regex
61-
href: ./samples/advanced.md
62-
- name: Index by category
54+
- name: Starter queries
55+
displayName: query language, data explorer, count, list, show, samples
56+
href: ./samples/starter.md
57+
- name: Advanced queries
58+
displayName: query language, data explorer, list, regex, samples
59+
href: ./samples/advanced.md
60+
- name: Sample queries by category
61+
displayName: samples, category
6362
href: ./samples/samples-by-category.md
64-
- name: Index by table
63+
- name: Sample queries by table
64+
displayName: samples, table
6565
href: ./samples/samples-by-table.md
66+
- name: Alerts samples
67+
displayName: samples, alerts
68+
href: ./samples/alerts-samples.md
6669
- name: Concepts
6770
items:
6871
- name: Understanding the query language

0 commit comments

Comments
 (0)