Query's met beleidsstatussen voor de resources onder de resourcegroep.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults?api-version=2019-10-01
Met optionele parameters:
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults?api-version=2019-10-01&$top={$top}&$orderby={$orderby}&$select={$select}&$from={$from}&$to={$to}&$filter={$filter}&$apply={$apply}&$skiptoken={$skiptoken}
URI-parameters
Name |
In |
Vereist |
Type |
Description |
policyStatesResource
|
path |
True
|
PolicyStatesResource
|
De virtuele resource onder Het resourcetype PolicyStates. In een bepaald tijdsbereik vertegenwoordigt 'latest' de meest recente beleidsstatus(s), terwijl 'standaard' alle beleidsstatussen vertegenwoordigt.
|
resourceGroupName
|
path |
True
|
string
|
Naam van resourcegroep.
|
subscriptionId
|
path |
True
|
string
|
Microsoft Azure-abonnements-id.
|
api-version
|
query |
True
|
string
|
Client-API-versie.
|
$apply
|
query |
|
string
|
OData past expressies toe voor aggregaties.
|
$filter
|
query |
|
string
|
OData-filterexpressie.
|
$from
|
query |
|
string
(date-time)
|
Met ISO 8601 opgemaakte tijdstempel wordt de begintijd van het interval opgegeven waarop een query moet worden uitgevoerd. Wanneer deze niet is opgegeven, gebruikt de service ($to - 1 dag).
|
$orderby
|
query |
|
string
|
Expressie ordenen met behulp van OData-notatie. Een of meer door komma's gescheiden kolomnamen met een optionele 'desc' (de standaardinstelling) of 'asc', bijvoorbeeld '$orderby=PolicyAssignmentId, ResourceId asc'.
|
$select
|
query |
|
string
|
Expressie selecteren met behulp van OData-notatie. Beperkt de kolommen voor elke record tot alleen de aangevraagde records, bijvoorbeeld '$select=PolicyAssignmentId, ResourceId'.
|
$skiptoken
|
query |
|
string
|
Skiptoken wordt alleen opgegeven als een eerder antwoord een gedeeltelijk resultaat heeft geretourneerd als onderdeel van het nextLink-element.
|
$to
|
query |
|
string
(date-time)
|
Met ISO 8601 opgemaakte tijdstempel wordt de eindtijd van het interval opgegeven waarop een query moet worden uitgevoerd. Wanneer deze niet is opgegeven, gebruikt de service de aanvraagtijd.
|
$top
|
query |
|
integer
(int32)
minimum: 0
|
Maximum aantal records dat moet worden geretourneerd.
|
Antwoorden
Beveiliging
azure_auth
Azure Active Directory OAuth2-stroom
Type:
oauth2
Stroom:
implicit
Autorisatie-URL:
https://login.microsoftonline.com/common/oauth2/authorize
Bereiken
Name |
Description |
user_impersonation
|
Uw gebruikersaccount imiteren
|
Voorbeelden
Query latest at resource group scope
Voorbeeldaanvraag
POST https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01
import com.azure.resourcemanager.policyinsights.models.PolicyStatesResource;
/**
* Samples for PolicyStates ListQueryResultsForResourceGroup.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/
* PolicyStates_QueryResourceGroupScope.json
*/
/**
* Sample code: Query latest at resource group scope.
*
* @param manager Entry point to PolicyInsightsManager.
*/
public static void
queryLatestAtResourceGroupScope(com.azure.resourcemanager.policyinsights.PolicyInsightsManager manager) {
manager.policyStates().listQueryResultsForResourceGroup(PolicyStatesResource.LATEST,
"fffedd8f-ffff-fffd-fffd-fffed2f84852", "myResourceGroup", null, null, null, null, null, null, null, null,
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.policyinsights import PolicyInsightsClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-policyinsights
# USAGE
python policy_states_query_resource_group_scope.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = PolicyInsightsClient(
credential=DefaultAzureCredential(),
subscription_id="fffedd8f-ffff-fffd-fffd-fffed2f84852",
)
response = client.policy_states.list_query_results_for_resource_group(
policy_states_resource="latest",
subscription_id="fffedd8f-ffff-fffd-fffd-fffed2f84852",
resource_group_name="myResourceGroup",
)
for item in response:
print(item)
# x-ms-original-file: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScope.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armpolicyinsights_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/policyinsights/armpolicyinsights"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/05a9cdab363b8ec824094ee73950c04594325172/specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScope.json
func ExamplePolicyStatesClient_NewListQueryResultsForResourceGroupPager_queryLatestAtResourceGroupScope() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armpolicyinsights.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
pager := clientFactory.NewPolicyStatesClient().NewListQueryResultsForResourceGroupPager(armpolicyinsights.PolicyStatesResourceLatest, "fffedd8f-ffff-fffd-fffd-fffed2f84852", "myResourceGroup", &armpolicyinsights.QueryOptions{Top: nil,
Filter: nil,
OrderBy: nil,
Select: nil,
From: nil,
To: nil,
Apply: nil,
SkipToken: nil,
Expand: nil,
}, nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
log.Fatalf("failed to advance page: %v", err)
}
for _, v := range page.Value {
// You could use page here. We use blank identifier for just demo purposes.
_ = v
}
// If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// page.PolicyStatesQueryResults = armpolicyinsights.PolicyStatesQueryResults{
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest"),
// ODataCount: to.Ptr[int32](2),
// Value: []*armpolicyinsights.PolicyState{
// {
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity"),
// ComplianceState: to.Ptr("NonCompliant"),
// IsCompliant: to.Ptr(false),
// ManagementGroupIDs: to.Ptr("mymg,fff988bf-fff1-ffff-fffb-fffcd011db47"),
// PolicyAssignmentID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentName: to.Ptr("3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentOwner: to.Ptr("tbd"),
// PolicyAssignmentParameters: to.Ptr("{}"),
// PolicyAssignmentScope: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// PolicyAssignmentVersion: to.Ptr("1.0.0"),
// PolicyDefinitionAction: to.Ptr("audit"),
// PolicyDefinitionCategory: to.Ptr("tbd"),
// PolicyDefinitionGroupNames: []*string{
// to.Ptr("myGroup")},
// PolicyDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1"),
// PolicyDefinitionName: to.Ptr("24813039-7534-408a-9842-eb99f45721b1"),
// PolicyDefinitionVersion: to.Ptr("1.0.0-preview"),
// PolicySetDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionVersion: to.Ptr("2.0.1"),
// ResourceGroup: to.Ptr("myResourceGroup"),
// ResourceID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1"),
// ResourceLocation: to.Ptr("eastus"),
// ResourceTags: to.Ptr("tbd"),
// ResourceType: to.Ptr("/Microsoft.Storage/storageAccounts"),
// SubscriptionID: to.Ptr("fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-10-09T18:42:42.000Z"); return t}()),
// },
// {
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity"),
// ComplianceState: to.Ptr("Compliant"),
// IsCompliant: to.Ptr(true),
// ManagementGroupIDs: to.Ptr("mymg,fff988bf-fff1-ffff-fffb-fffcd011db47"),
// PolicyAssignmentID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentName: to.Ptr("3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentOwner: to.Ptr("tbd"),
// PolicyAssignmentParameters: to.Ptr("{}"),
// PolicyAssignmentScope: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// PolicyAssignmentVersion: to.Ptr("1.0.0"),
// PolicyDefinitionAction: to.Ptr("audit"),
// PolicyDefinitionCategory: to.Ptr("tbd"),
// PolicyDefinitionGroupNames: []*string{
// to.Ptr("myGroup")},
// PolicyDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682"),
// PolicyDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e3682"),
// PolicyDefinitionVersion: to.Ptr("1.0.0-preview"),
// PolicySetDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionVersion: to.Ptr("2.0.1"),
// ResourceGroup: to.Ptr("myResourceGroup"),
// ResourceID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1"),
// ResourceLocation: to.Ptr("eastus"),
// ResourceTags: to.Ptr("tbd"),
// ResourceType: to.Ptr("/Microsoft.Storage/storageAccounts"),
// SubscriptionID: to.Ptr("fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-10-09T18:42:42.000Z"); return t}()),
// }},
// }
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { PolicyInsightsClient } = require("@azure/arm-policyinsights");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Queries policy states for the resources under the resource group.
*
* @summary Queries policy states for the resources under the resource group.
* x-ms-original-file: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScope.json
*/
async function queryLatestAtResourceGroupScope() {
const subscriptionId =
process.env["POLICYINSIGHTS_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const policyStatesResource = "latest";
const resourceGroupName = process.env["POLICYINSIGHTS_RESOURCE_GROUP"] || "myResourceGroup";
const credential = new DefaultAzureCredential();
const client = new PolicyInsightsClient(credential, subscriptionId);
const resArray = new Array();
for await (let item of client.policyStates.listQueryResultsForResourceGroup(
policyStatesResource,
subscriptionId,
resourceGroupName
)) {
resArray.push(item);
}
console.log(resArray);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.PolicyInsights.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.PolicyInsights;
// Generated from example definition: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScope.json
// this example is just showing the usage of "PolicyStates_ListQueryResultsForResourceGroup" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "fffedd8f-ffff-fffd-fffd-fffed2f84852";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// invoke the operation and iterate over the result
PolicyStateType policyStateType = PolicyStateType.Latest;
await foreach (PolicyState item in resourceGroupResource.GetPolicyStateQueryResultsAsync(policyStateType))
{
Console.WriteLine($"Succeeded: {item}");
}
Console.WriteLine("Succeeded");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"@odata.nextLink": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest",
"@odata.count": 2,
"value": [
{
"@odata.id": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
"timestamp": "2019-10-09T18:42:42Z",
"resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
"policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
"policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1",
"effectiveParameters": null,
"isCompliant": false,
"subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
"resourceType": "/Microsoft.Storage/storageAccounts",
"resourceLocation": "eastus",
"resourceGroup": "myResourceGroup",
"resourceTags": "tbd",
"policyAssignmentName": "3f3c4330183b4e218fe6fd29",
"policyAssignmentOwner": "tbd",
"policyAssignmentParameters": "{}",
"policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
"policyDefinitionName": "24813039-7534-408a-9842-eb99f45721b1",
"policyDefinitionAction": "audit",
"policyDefinitionCategory": "tbd",
"policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionOwner": null,
"policySetDefinitionCategory": null,
"policySetDefinitionParameters": null,
"managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
"policyDefinitionReferenceId": null,
"complianceState": "NonCompliant",
"policyDefinitionGroupNames": [
"myGroup"
],
"policyDefinitionVersion": "1.0.0-preview",
"policySetDefinitionVersion": "2.0.1",
"policyAssignmentVersion": "1.0.0"
},
{
"@odata.id": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
"timestamp": "2019-10-09T18:42:42Z",
"resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
"policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
"policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682",
"effectiveParameters": null,
"isCompliant": true,
"subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
"resourceType": "/Microsoft.Storage/storageAccounts",
"resourceLocation": "eastus",
"resourceGroup": "myResourceGroup",
"resourceTags": "tbd",
"policyAssignmentName": "3f3c4330183b4e218fe6fd29",
"policyAssignmentOwner": "tbd",
"policyAssignmentParameters": "{}",
"policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
"policyDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e3682",
"policyDefinitionAction": "audit",
"policyDefinitionCategory": "tbd",
"policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionOwner": null,
"policySetDefinitionCategory": null,
"policySetDefinitionParameters": null,
"managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
"policyDefinitionReferenceId": null,
"complianceState": "Compliant",
"policyDefinitionGroupNames": [
"myGroup"
],
"policyDefinitionVersion": "1.0.0-preview",
"policySetDefinitionVersion": "2.0.1",
"policyAssignmentVersion": "1.0.0"
}
]
}
Query latest at resource group scope with next link
Voorbeeldaanvraag
POST https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01&$skiptoken=WpmWfBSvPhkAK6QD
import com.azure.resourcemanager.policyinsights.models.PolicyStatesResource;
/**
* Samples for PolicyStates ListQueryResultsForResourceGroup.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/
* PolicyStates_QueryResourceGroupScopeNextLink.json
*/
/**
* Sample code: Query latest at resource group scope with next link.
*
* @param manager Entry point to PolicyInsightsManager.
*/
public static void queryLatestAtResourceGroupScopeWithNextLink(
com.azure.resourcemanager.policyinsights.PolicyInsightsManager manager) {
manager.policyStates().listQueryResultsForResourceGroup(PolicyStatesResource.LATEST,
"fffedd8f-ffff-fffd-fffd-fffed2f84852", "myResourceGroup", null, null, null, null, null, null, null,
"WpmWfBSvPhkAK6QD", com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.policyinsights import PolicyInsightsClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-policyinsights
# USAGE
python policy_states_query_resource_group_scope_next_link.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = PolicyInsightsClient(
credential=DefaultAzureCredential(),
subscription_id="fffedd8f-ffff-fffd-fffd-fffed2f84852",
)
response = client.policy_states.list_query_results_for_resource_group(
policy_states_resource="latest",
subscription_id="fffedd8f-ffff-fffd-fffd-fffed2f84852",
resource_group_name="myResourceGroup",
)
for item in response:
print(item)
# x-ms-original-file: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScopeNextLink.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armpolicyinsights_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/policyinsights/armpolicyinsights"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/05a9cdab363b8ec824094ee73950c04594325172/specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScopeNextLink.json
func ExamplePolicyStatesClient_NewListQueryResultsForResourceGroupPager_queryLatestAtResourceGroupScopeWithNextLink() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armpolicyinsights.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
pager := clientFactory.NewPolicyStatesClient().NewListQueryResultsForResourceGroupPager(armpolicyinsights.PolicyStatesResourceLatest, "fffedd8f-ffff-fffd-fffd-fffed2f84852", "myResourceGroup", &armpolicyinsights.QueryOptions{Top: nil,
Filter: nil,
OrderBy: nil,
Select: nil,
From: nil,
To: nil,
Apply: nil,
SkipToken: to.Ptr("WpmWfBSvPhkAK6QD"),
Expand: nil,
}, nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
log.Fatalf("failed to advance page: %v", err)
}
for _, v := range page.Value {
// You could use page here. We use blank identifier for just demo purposes.
_ = v
}
// If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// page.PolicyStatesQueryResults = armpolicyinsights.PolicyStatesQueryResults{
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest"),
// ODataCount: to.Ptr[int32](2),
// Value: []*armpolicyinsights.PolicyState{
// {
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity"),
// ComplianceState: to.Ptr("NonCompliant"),
// IsCompliant: to.Ptr(false),
// ManagementGroupIDs: to.Ptr("mymg,fff988bf-fff1-ffff-fffb-fffcd011db47"),
// PolicyAssignmentID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentName: to.Ptr("3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentOwner: to.Ptr("tbd"),
// PolicyAssignmentParameters: to.Ptr("{}"),
// PolicyAssignmentScope: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// PolicyDefinitionAction: to.Ptr("audit"),
// PolicyDefinitionCategory: to.Ptr("tbd"),
// PolicyDefinitionGroupNames: []*string{
// to.Ptr("myGroup")},
// PolicyDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1"),
// PolicyDefinitionName: to.Ptr("24813039-7534-408a-9842-eb99f45721b1"),
// PolicySetDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// ResourceGroup: to.Ptr("myResourceGroup"),
// ResourceID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1"),
// ResourceLocation: to.Ptr("eastus"),
// ResourceTags: to.Ptr("tbd"),
// ResourceType: to.Ptr("/Microsoft.Storage/storageAccounts"),
// SubscriptionID: to.Ptr("fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-10-09T18:42:42.000Z"); return t}()),
// },
// {
// ODataContext: to.Ptr("https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity"),
// ComplianceState: to.Ptr("Compliant"),
// IsCompliant: to.Ptr(true),
// ManagementGroupIDs: to.Ptr("mymg,fff988bf-fff1-ffff-fffb-fffcd011db47"),
// PolicyAssignmentID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentName: to.Ptr("3f3c4330183b4e218fe6fd29"),
// PolicyAssignmentOwner: to.Ptr("tbd"),
// PolicyAssignmentParameters: to.Ptr("{}"),
// PolicyAssignmentScope: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// PolicyDefinitionAction: to.Ptr("audit"),
// PolicyDefinitionCategory: to.Ptr("tbd"),
// PolicyDefinitionGroupNames: []*string{
// to.Ptr("myGroup")},
// PolicyDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682"),
// PolicyDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e3682"),
// PolicySetDefinitionID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// PolicySetDefinitionName: to.Ptr("3e3807c1-65c9-49e0-a406-82d8ae3e338c"),
// ResourceGroup: to.Ptr("myResourceGroup"),
// ResourceID: to.Ptr("/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1"),
// ResourceLocation: to.Ptr("eastus"),
// ResourceTags: to.Ptr("tbd"),
// ResourceType: to.Ptr("/Microsoft.Storage/storageAccounts"),
// SubscriptionID: to.Ptr("fffedd8f-ffff-fffd-fffd-fffed2f84852"),
// Timestamp: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-10-09T18:42:42.000Z"); return t}()),
// }},
// }
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { PolicyInsightsClient } = require("@azure/arm-policyinsights");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Queries policy states for the resources under the resource group.
*
* @summary Queries policy states for the resources under the resource group.
* x-ms-original-file: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScopeNextLink.json
*/
async function queryLatestAtResourceGroupScopeWithNextLink() {
const subscriptionId =
process.env["POLICYINSIGHTS_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const policyStatesResource = "latest";
const resourceGroupName = process.env["POLICYINSIGHTS_RESOURCE_GROUP"] || "myResourceGroup";
const skipToken = "WpmWfBSvPhkAK6QD";
const options = {
queryOptions: { skipToken: skipToken },
};
const credential = new DefaultAzureCredential();
const client = new PolicyInsightsClient(credential, subscriptionId);
const resArray = new Array();
for await (let item of client.policyStates.listQueryResultsForResourceGroup(
policyStatesResource,
subscriptionId,
resourceGroupName,
options
)) {
resArray.push(item);
}
console.log(resArray);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.PolicyInsights.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.PolicyInsights;
// Generated from example definition: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QueryResourceGroupScopeNextLink.json
// this example is just showing the usage of "PolicyStates_ListQueryResultsForResourceGroup" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "fffedd8f-ffff-fffd-fffd-fffed2f84852";
string resourceGroupName = "myResourceGroup";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// invoke the operation and iterate over the result
PolicyStateType policyStateType = PolicyStateType.Latest;
await foreach (PolicyState item in resourceGroupResource.GetPolicyStateQueryResultsAsync(policyStateType))
{
Console.WriteLine($"Succeeded: {item}");
}
Console.WriteLine("Succeeded");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Voorbeeldrespons
{
"@odata.nextLink": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest",
"@odata.count": 2,
"value": [
{
"@odata.id": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
"timestamp": "2019-10-09T18:42:42Z",
"resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
"policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
"policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1",
"effectiveParameters": null,
"isCompliant": false,
"subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
"resourceType": "/Microsoft.Storage/storageAccounts",
"resourceLocation": "eastus",
"resourceGroup": "myResourceGroup",
"resourceTags": "tbd",
"policyAssignmentName": "3f3c4330183b4e218fe6fd29",
"policyAssignmentOwner": "tbd",
"policyAssignmentParameters": "{}",
"policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
"policyDefinitionName": "24813039-7534-408a-9842-eb99f45721b1",
"policyDefinitionAction": "audit",
"policyDefinitionCategory": "tbd",
"policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionOwner": null,
"policySetDefinitionCategory": null,
"policySetDefinitionParameters": null,
"managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
"policyDefinitionReferenceId": null,
"complianceState": "NonCompliant",
"policyDefinitionGroupNames": [
"myGroup"
]
},
{
"@odata.id": null,
"@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
"timestamp": "2019-10-09T18:42:42Z",
"resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
"policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
"policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682",
"effectiveParameters": null,
"isCompliant": true,
"subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
"resourceType": "/Microsoft.Storage/storageAccounts",
"resourceLocation": "eastus",
"resourceGroup": "myResourceGroup",
"resourceTags": "tbd",
"policyAssignmentName": "3f3c4330183b4e218fe6fd29",
"policyAssignmentOwner": "tbd",
"policyAssignmentParameters": "{}",
"policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
"policyDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e3682",
"policyDefinitionAction": "audit",
"policyDefinitionCategory": "tbd",
"policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
"policySetDefinitionOwner": null,
"policySetDefinitionCategory": null,
"policySetDefinitionParameters": null,
"managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
"policyDefinitionReferenceId": null,
"complianceState": "Compliant",
"policyDefinitionGroupNames": [
"myGroup"
]
}
]
}
Definities
ComponentStateDetails
Object
Details van onderdeelstatus.
Name |
Type |
Description |
complianceState
|
string
|
Nalevingsstatus van onderdelen.
|
id
|
string
|
Onderdeel-id.
|
name
|
string
|
Onderdeelnaam.
|
timestamp
|
string
(date-time)
|
Tijdstempel voor evaluatie van onderdeelnaleving.
|
type
|
string
|
Onderdeeltype.
|
Error
Object
Foutdefinitie.
Name |
Type |
Description |
code
|
string
|
Servicespecifieke foutcode die fungeert als de substatus voor de HTTP-foutcode.
|
message
|
string
|
Beschrijving van de fout.
|
ExpressionEvaluationDetails
Object
Evaluatiedetails van beleidstaalexpressies.
Name |
Type |
Description |
expression
|
string
|
Expressie geëvalueerd.
|
expressionKind
|
string
|
Het type expressie dat is geëvalueerd.
|
expressionValue
|
object
|
Waarde van de expressie.
|
operator
|
string
|
Operator voor het vergelijken van de expressiewaarde en de doelwaarde.
|
path
|
string
|
Eigenschapspad als de expressie een veld of alias is.
|
result
|
string
|
Evaluatieresultaat.
|
targetValue
|
object
|
Doelwaarde die moet worden vergeleken met de expressiewaarde.
|
IfNotExistsEvaluationDetails
Object
Evaluatiedetails van het effect IfNotExists.
Name |
Type |
Description |
resourceId
|
string
|
Id van de laatst geëvalueerde resource voor IfNotExists-effect.
|
totalResources
|
integer
|
Het totale aantal resources waarop de bestaansvoorwaarde van toepassing is.
|
PolicyEvaluationDetails
Object
Details van beleidsevaluatie.
PolicyState
Object
Beleidsstatusrecord.
Name |
Type |
Description |
@odata.context
|
string
|
OData-contexttekenreeks; wordt gebruikt door OData-clients om typegegevens op te lossen op basis van metagegevens.
|
@odata.id
|
string
|
OData-entiteits-id; altijd ingesteld op null omdat records voor beleidsstatus geen entiteits-id hebben.
|
complianceState
|
string
|
Nalevingsstatus van de resource.
|
components
|
ComponentStateDetails[]
|
Nalevingsrecords voor onderdelenstatussen worden alleen ingevuld wanneer de URL $expand=component onderdelen bevat.
|
effectiveParameters
|
string
|
Effectieve parameters voor de beleidstoewijzing.
|
isCompliant
|
boolean
|
Vlag die aangeeft of de resource compatibel is met de beleidstoewijzing waarop deze is geëvalueerd. Deze eigenschap is afgeschaft; Gebruik in plaats daarvan ComplianceState.
|
managementGroupIds
|
string
|
Door komma's gescheiden lijst met beheergroep-id's, die de hiërarchie van de beheergroepen vertegenwoordigen waaronder de resource zich bevindt.
|
policyAssignmentId
|
string
|
Id van beleidstoewijzing.
|
policyAssignmentName
|
string
|
Naam van beleidstoewijzing.
|
policyAssignmentOwner
|
string
|
Eigenaar van beleidstoewijzing.
|
policyAssignmentParameters
|
string
|
Beleidstoewijzingsparameters.
|
policyAssignmentScope
|
string
|
Bereik van beleidstoewijzing.
|
policyAssignmentVersion
|
string
|
Versie van beleidstoewijzing geëvalueerd.
|
policyDefinitionAction
|
string
|
Actie voor beleidsdefinitie, bijvoorbeeld effect.
|
policyDefinitionCategory
|
string
|
Categorie beleidsdefinitie.
|
policyDefinitionGroupNames
|
string[]
|
Namen van beleidsdefinitiegroepen.
|
policyDefinitionId
|
string
|
Id van beleidsdefinitie.
|
policyDefinitionName
|
string
|
Naam van beleidsdefinitie.
|
policyDefinitionReferenceId
|
string
|
Referentie-id voor de beleidsdefinitie in de beleidsset, als de beleidstoewijzing voor een beleidsset is.
|
policyDefinitionVersion
|
string
|
Versie van beleidsdefinitie geëvalueerd.
|
policyEvaluationDetails
|
PolicyEvaluationDetails
|
Details van beleidsevaluatie.
|
policySetDefinitionCategory
|
string
|
Definitiecategorie van beleidsset, als de beleidstoewijzing voor een beleidsset is.
|
policySetDefinitionId
|
string
|
Definitie-id van beleidsset, als de beleidstoewijzing voor een beleidsset is.
|
policySetDefinitionName
|
string
|
Naam van beleidssetdefinitie, als de beleidstoewijzing voor een beleidsset is.
|
policySetDefinitionOwner
|
string
|
Eigenaar van beleidssetdefinitie, als de beleidstoewijzing voor een beleidsset is.
|
policySetDefinitionParameters
|
string
|
Definitieparameters voor beleidssets als de beleidstoewijzing voor een beleidsset is.
|
policySetDefinitionVersion
|
string
|
Geëvalueerde definitieversie van beleidsset.
|
resourceGroup
|
string
|
Naam van resourcegroep.
|
resourceId
|
string
|
Resource-id.
|
resourceLocation
|
string
|
Resourcelocatie.
|
resourceTags
|
string
|
Lijst met resourcetags.
|
resourceType
|
string
|
Resourcetype.
|
subscriptionId
|
string
|
Abonnements-id.
|
timestamp
|
string
(date-time)
|
Tijdstempel voor de beleidsstatusrecord.
|
PolicyStatesQueryResults
Object
Queryresultaten.
Name |
Type |
Description |
@odata.context
|
string
|
OData-contexttekenreeks; wordt gebruikt door OData-clients om typegegevens op te lossen op basis van metagegevens.
|
@odata.count
|
integer
(int32)
minimum: 0
|
Aantal OData-entiteiten; vertegenwoordigt het aantal geretourneerde beleidsstatusrecords.
|
@odata.nextLink
|
string
|
Odata next link; URL voor het ophalen van de volgende set resultaten.
|
value
|
PolicyState[]
|
Queryresultaten.
|
PolicyStatesResource
Inventarisatie
De virtuele resource onder Het resourcetype PolicyStates. In een bepaald tijdsbereik vertegenwoordigt 'latest' de meest recente beleidsstatus(s), terwijl 'standaard' alle beleidsstatussen vertegenwoordigt.
Waarde |
Description |
default
|
|
latest
|
|
QueryFailure
Object
Foutreactie.
Name |
Type |
Description |
error
|
Error
|
Foutdefinitie.
|