Skip to content

Commit 483d8dd

Browse files
Merge pull request #261516 from davidsmatlak/ds-fix-arg-starter-samples
Fixes ARG monitor alerts samples
2 parents 2794885 + 7bd5a65 commit 483d8dd

File tree

2 files changed

+95
-28
lines changed

2 files changed

+95
-28
lines changed

articles/governance/resource-graph/first-query-dotnet.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ ms.author: davidsmatlak
88
---
99
# Quickstart: Run your first Resource Graph query using .NET
1010

11-
> [!NOTE]
12-
> Special thanks to [Glenn Block](https://github.com/glennblock) for contributing
13-
> the code used in this quickstart.
14-
1511
The first step to using Azure Resource Graph is to check that the required NuGet packages are installed. This quickstart walks you through the process of adding the packages to your .NET application.
1612

1713
At the end of this process, you'll have added the packages to your .NET application and run your first Resource Graph query.
@@ -51,12 +47,12 @@ required packages.
5147
using Azure.ResourceManager;
5248
using Azure.ResourceManager.ResourceGraph;
5349
using Azure.ResourceManager.ResourceGraph.Models;
54-
50+
5551
string strTenant = args[0];
5652
string strClientId = args[1];
5753
string strClientSecret = args[2];
5854
string strQuery = args[3];
59-
55+
6056
var client = new ArmClient(
6157
new ClientSecretCredential(strTenant, strClientId, strClientSecret));
6258
var tenant = client.GetTenants().First();

articles/governance/resource-graph/samples/starter.md

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ Search-AzGraph -Query "Resources | where type contains 'storage' | distinct type
371371

372372
## <a name="list-subnets"></a>List all Azure virtual network subnets
373373

374-
This query returns a list of Azure virtual networks (VNets) including subnet names and address prefixes. Thanks to [Saul Dolgin](https://github.com/sdolgin) for the contribution.
374+
This query returns a list of Azure virtual networks (VNets) including subnet names and address prefixes.
375375

376376
```kusto
377377
Resources
@@ -659,42 +659,113 @@ Search-AzGraph -Query "Resources | where type =~ 'microsoft.network/networksecur
659659

660660
## List Azure Monitor alerts ordered by severity
661661

662+
This query uses the `alertsmanagementresources` table to return Azure Monitor alerts ordered by severity.
663+
662664
```kusto
663-
alertsmanagementresources
664-
| where type =~ 'microsoft.alertsmanagement/alerts'
665-
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
666-
| project Severity = tostring(properties.essentials.severity)
665+
alertsmanagementresources
666+
| where type =~ 'microsoft.alertsmanagement/alerts'
667+
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
668+
| project Severity = tostring(properties.essentials.severity)
667669
| summarize AlertsCount = count() by Severity
668-
669670
```
671+
672+
# [Azure CLI](#tab/azure-cli)
673+
674+
```azurecli-interactive
675+
az graph query -q "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity) | summarize AlertsCount = count() by Severity"
676+
```
677+
678+
# [Azure PowerShell](#tab/azure-powershell)
679+
680+
```azurepowershell-interactive
681+
Search-AzGraph -Query "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity) | summarize AlertsCount = count() by Severity"
682+
```
683+
684+
# [Portal](#tab/azure-portal)
685+
686+
:::image type="icon" source="../media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
687+
688+
- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity" target="_blank">portal.azure.com</a>
689+
- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity" target="_blank">portal.azure.us</a>
690+
- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity" target="_blank">portal.azure.cn</a>
691+
692+
---
693+
670694
## List Azure Monitor alerts ordered by severity and alert state
671695

696+
This query uses the `alertsmanagementresources` table to return Azure Monitor alerts ordered by severity and alert state.
697+
672698
```kusto
673699
alertsmanagementresources
674-
| where type =~ 'microsoft.alertsmanagement/alerts' 
675-
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
676-
| project Severity = tostring(properties.essentials.severity),
677-
AlertState= tostring(properties.essentials.alertState)
700+
| where type =~ 'microsoft.alertsmanagement/alerts'
701+
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
702+
| project Severity = tostring(properties.essentials.severity), AlertState = tostring(properties.essentials.alertState)
678703
| summarize AlertsCount = count() by Severity, AlertState
679704
```
680705

681-
## List Azure Monitor alerts ordered by severity, monitor service, and target resource type
706+
# [Azure CLI](#tab/azure-cli)
707+
708+
```azurecli-interactive
709+
az graph query -q "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity), AlertState = tostring(properties.essentials.alertState) | summarize AlertsCount = count() by Severity, AlertState"
710+
```
711+
712+
# [Azure PowerShell](#tab/azure-powershell)
713+
714+
```azurepowershell-interactive
715+
Search-AzGraph -Query "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity), AlertState = tostring(properties.essentials.alertState) | summarize AlertsCount = count() by Severity, AlertState"
716+
```
717+
718+
# [Portal](#tab/azure-portal)
719+
720+
:::image type="icon" source="../media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
721+
722+
- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%20AlertState%20%3D%20tostring%28properties.essentials.alertState%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20AlertState" target="_blank">portal.azure.com</a>
723+
- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%20AlertState%20%3D%20tostring%28properties.essentials.alertState%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20AlertState" target="_blank">portal.azure.us</a>
724+
- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%20AlertState%20%3D%20tostring%28properties.essentials.alertState%29%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20AlertState" target="_blank">portal.azure.cn</a>
725+
726+
---
727+
728+
## List Azure Monitor alerts ordered by severity, monitor service, and target resource type
729+
730+
This query uses the `alertsmanagementresources` table to return Azure Monitor alerts ordered by severity, monitor service, and target resource type.
682731

683732
```kusto
684-
alertsmanagementresources
685-
| where type =~ 'microsoft.alertsmanagement/alerts'
686-
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
687-
| project Severity = tostring(properties.essentials.severity),
688-
MonitorCondition = tostring(properties.essentials.monitorCondition),
689-
ObjectState = tostring(properties.essentials.alertState),
690-
MonitorService = tostring(properties.essentials.monitorService),
691-
AlertRuleId = tostring(properties.essentials.alertRule),
692-
SignalType = tostring(properties.essentials.signalType),
693-
TargetResource = tostring(properties.essentials.targetResourceName),
694-
TargetResourceType = tostring(properties.essentials.targetResourceName), id
733+
alertsmanagementresources
734+
| where type =~ 'microsoft.alertsmanagement/alerts'
735+
| where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now()
736+
| project Severity = tostring(properties.essentials.severity),
737+
MonitorCondition = tostring(properties.essentials.monitorCondition),
738+
ObjectState = tostring(properties.essentials.alertState),
739+
MonitorService = tostring(properties.essentials.monitorService),
740+
AlertRuleId = tostring(properties.essentials.alertRule),
741+
SignalType = tostring(properties.essentials.signalType),
742+
TargetResource = tostring(properties.essentials.targetResourceName),
743+
TargetResourceType = tostring(properties.essentials.targetResourceName), id
695744
| summarize AlertsCount = count() by Severity, MonitorService , TargetResourceType
696745
```
697746

747+
# [Azure CLI](#tab/azure-cli)
748+
749+
```azurecli-interactive
750+
az graph query -q "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity), MonitorCondition = tostring(properties.essentials.monitorCondition), ObjectState = tostring(properties.essentials.alertState), MonitorService = tostring(properties.essentials.monitorService), AlertRuleId = tostring(properties.essentials.alertRule), SignalType = tostring(properties.essentials.signalType), TargetResource = tostring(properties.essentials.targetResourceName), TargetResourceType = tostring(properties.essentials.targetResourceName), id | summarize AlertsCount = count() by Severity, MonitorService , TargetResourceType"
751+
```
752+
753+
# [Azure PowerShell](#tab/azure-powershell)
754+
755+
```azurepowershell-interactive
756+
Search-AzGraph -Query "alertsmanagementresources | where type =~ 'microsoft.alertsmanagement/alerts' | where todatetime(properties.essentials.startDateTime) >= ago(2h) and todatetime(properties.essentials.startDateTime) < now() | project Severity = tostring(properties.essentials.severity), MonitorCondition = tostring(properties.essentials.monitorCondition), ObjectState = tostring(properties.essentials.alertState), MonitorService = tostring(properties.essentials.monitorService), AlertRuleId = tostring(properties.essentials.alertRule), SignalType = tostring(properties.essentials.signalType), TargetResource = tostring(properties.essentials.targetResourceName), TargetResourceType = tostring(properties.essentials.targetResourceName), id | summarize AlertsCount = count() by Severity, MonitorService , TargetResourceType"
757+
```
758+
759+
# [Portal](#tab/azure-portal)
760+
761+
:::image type="icon" source="../media/resource-graph-small.png"::: Try this query in Azure Resource Graph Explorer:
762+
763+
- Azure portal: <a href="https://portal.azure.com/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%0D%0AMonitorCondition%20%3D%20tostring%28properties.essentials.monitorCondition%29%2C%0D%0AObjectState%20%3D%20tostring%28properties.essentials.alertState%29%2C%0D%0AMonitorService%20%3D%20tostring%28properties.essentials.monitorService%29%2C%0D%0AAlertRuleId%20%3D%20tostring%28properties.essentials.alertRule%29%2C%0D%0ASignalType%20%3D%20tostring%28properties.essentials.signalType%29%2C%0D%0ATargetResource%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%0D%0ATargetResourceType%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%20id%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20MonitorService%20%2C%20TargetResourceType" target="_blank">portal.azure.com</a>
764+
- Azure Government portal: <a href="https://portal.azure.us/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%0D%0AMonitorCondition%20%3D%20tostring%28properties.essentials.monitorCondition%29%2C%0D%0AObjectState%20%3D%20tostring%28properties.essentials.alertState%29%2C%0D%0AMonitorService%20%3D%20tostring%28properties.essentials.monitorService%29%2C%0D%0AAlertRuleId%20%3D%20tostring%28properties.essentials.alertRule%29%2C%0D%0ASignalType%20%3D%20tostring%28properties.essentials.signalType%29%2C%0D%0ATargetResource%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%0D%0ATargetResourceType%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%20id%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20MonitorService%20%2C%20TargetResourceType" target="_blank">portal.azure.us</a>
765+
- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/?feature.customportal=false#blade/HubsExtension/ArgQueryBlade/query/alertsmanagementresources%0D%0A%7C%20where%20type%20%3D~%20%27microsoft.alertsmanagement%2Falerts%27%0D%0A%7C%20where%20todatetime%28properties.essentials.startDateTime%29%20%3E%3D%20ago%282h%29%20and%20todatetime%28properties.essentials.startDateTime%29%20%3C%20now%28%29%0D%0A%7C%20project%20Severity%20%3D%20tostring%28properties.essentials.severity%29%2C%0D%0AMonitorCondition%20%3D%20tostring%28properties.essentials.monitorCondition%29%2C%0D%0AObjectState%20%3D%20tostring%28properties.essentials.alertState%29%2C%0D%0AMonitorService%20%3D%20tostring%28properties.essentials.monitorService%29%2C%0D%0AAlertRuleId%20%3D%20tostring%28properties.essentials.alertRule%29%2C%0D%0ASignalType%20%3D%20tostring%28properties.essentials.signalType%29%2C%0D%0ATargetResource%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%0D%0ATargetResourceType%20%3D%20tostring%28properties.essentials.targetResourceName%29%2C%20id%0D%0A%7C%20summarize%20AlertsCount%20%3D%20count%28%29%20by%20Severity%2C%20MonitorService%20%2C%20TargetResourceType" target="_blank">portal.azure.cn</a>
766+
767+
---
768+
698769
## Next steps
699770

700771
- Learn more about the [query language](../concepts/query-language.md).

0 commit comments

Comments
 (0)