You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Use the REST APIs to manage Azure Chaos Studio experiments
3
-
description: Run and manage a chaos experiment with Azure Chaos Studio by using REST APIs.
2
+
title: Use REST APIs to interact with Chaos Studio
3
+
description: Create, view, and manage Azure Chaos Studio experiments, targets, and capabilities with REST APIs.
4
4
services: chaos-studio
5
5
author: prasha-microsoft
6
6
ms.topic: article
@@ -10,139 +10,183 @@ ms.service: chaos-studio
10
10
ms.custom: ignite-fall-2021, devx-track-azurecli
11
11
---
12
12
13
-
# Use the Chaos Studio REST APIs to run and manage chaos experiments
13
+
# Use REST APIs to interact with Chaos Studio
14
14
15
-
> [!WARNING]
16
-
> Injecting faults can affect your application or service. Be careful not to disrupt customers.
15
+
If you're integrating Azure Chaos Studio into your CI/CD pipelines, or you simply prefer to use direct API calls to interact with your Azure resources, you can use Chaos Studio's REST API. For the full API reference, visit the [Azure Chaos Studio REST API reference](/rest/api/chaosstudio/). This page provides samples for using the REST API effectively, and is not intended as a comprehensive reference.
17
16
18
-
The Azure Chaos Studio REST API provides support for starting experiments programmatically. You can also use the Azure Resource Manager client and the Azure CLI to execute these commands from the console. The examples in this article are for the Azure CLI.
17
+
This article assumes you're using [Azure CLI](/cli/azure/install-azure-cli) to execute these commands, but you can adapt them to other standard REST clients.
19
18
20
-
> [!Warning]
21
-
> These APIs are still under development and subject to change.
22
-
23
-
## REST APIs
24
19
25
20
You can use the Chaos Studio REST APIs to:
26
-
* Start, stop, and manage experiments.
27
-
* View and manage targets.
28
-
* Query experiment status.
29
-
* Query and delete subscription configurations.
21
+
* Create, modify, and delete experiments
22
+
* View, start, and stop experiment executions
23
+
* View and manage targets
24
+
* Register and unregister your subscription with the Chaos Studio resource provider
25
+
* View available resource provider operations.
30
26
31
-
Use the `AZ CLI` utility to perform these actions from the command line.
27
+
Use the `az cli` utility to perform these actions from the command line.
32
28
33
29
> [!TIP]
34
-
> To get more verbose output with the AZ CLI, append `--verbose` to the end of each command. This variable returns more metadata when commands execute, including `x-ms-correlation-request-id`, which aids in debugging.
30
+
> To get more verbose output with Azure CLI, append `--verbose` to the end of each command. This variable returns more metadata when commands execute, including `x-ms-correlation-request-id`, which aids in debugging.
31
+
32
+
These examples have been reviewed with the generally available Chaos Studio API version `2023-11-01`.
35
33
36
-
### Chaos Studio provider commands
34
+
##Resource provider commands
37
35
38
-
This section lists the Chaos Studio provider commands.
36
+
This section lists the Chaos Studio provider commands, which help you understand the resource provider's status and available operations.
39
37
40
-
#### List details about the Microsoft.Chaos resource provider
38
+
### List details about the Microsoft.Chaos resource provider
39
+
40
+
This shows information such as available API versions for the Chaos resource provider and region availability. The most recent `api-version` required for this may differ from the `api-version` for Chaos resource provider operations.
41
41
42
42
```azurecli
43
-
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos?api-version={apiVersion}" --resource "https://management.azure.com"
43
+
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos?api-version={apiVersion}"
44
44
```
45
45
46
-
####List all the operations of the Microsoft.Chaos resource provider
46
+
### List all the operations of the Microsoft.Chaos resource provider
47
47
48
48
```azurecli
49
-
az rest --method get --url "https://management.azure.com/providers/Microsoft.Chaos/operations?api-version={apiVersion}" --resource "https://management.azure.com"
49
+
az rest --method get --url "https://management.azure.com/providers/Microsoft.Chaos/operations?api-version={apiVersion}"
50
50
```
51
51
52
-
#### List Chaos provider configurations
52
+
## Targets and capabilities
53
+
54
+
These operations help you see what [targets and capabilities](chaos-studio-targets-capabilities.md) are available, and add them to a target.
55
+
56
+
### List all target types available in a region
53
57
54
58
```azurecli
55
-
az rest --method get --url"https://management.azure.com/subscriptions/{subscriptionId}/providers/microsoft.chaos/chaosProviderConfigurations/?api-version={apiVersion}" --resource "https://management.azure.com" --verbose
59
+
az rest --method get --url"https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos/locations/{locationName}/targetTypes?api-version={apiVersion}"
56
60
```
57
61
58
-
#### Create Chaos provider configuration
62
+
###List all capabilities available for a target type
59
63
60
64
```azurecli
61
-
az rest --method put --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/microsoft.chaos/chaosProviderConfigurations/{chaosProviderType}?api-version={apiVersion}" --body @{providerSettings.json} --resource "https://management.azure.com"
65
+
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos/locations/{locationName}/targetTypes/{targetType}/capabilityTypes?api-version={apiVersion}"
62
66
```
63
67
64
-
### Chaos Studio target and agent commands
68
+
### Enable a resource as a target
65
69
66
-
This section lists the Chaos Studio target and agent commands.
70
+
To use a resource in an experiment, you need to enable it as a target.
67
71
68
-
#### List all the targets or agents under a subscription
72
+
```azurecli
73
+
az rest --method put --url "https://management.azure.com/{resourceId}/providers/Microsoft.Chaos/targets/{targetType}?api-version={apiVersion}" --body "{'properties':{}}"
74
+
```
75
+
76
+
### Enable capabilities for a target
77
+
78
+
Once a resource has been enabled as a target, you need to specify what capabilities (corresponding to faults) are allowed.
69
79
70
80
```azurecli
71
-
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos/chaosTargets/?api-version={apiVersion}" --url-parameter "chaosProviderType={chaosProviderType}" --resource "https://management.azure.com"
81
+
az rest --method put --url "https://management.azure.com/{resourceId}/providers/Microsoft.Chaos/targets/{targetType}/capabilities/{capabilityName}?api-version={apiVersion}" --body "{'properties':{}}"
72
82
```
73
83
74
-
### Chaos Studio experiment commands
84
+
### See what capabilities are enabled for a target
85
+
86
+
Once a target and capabilities have been enabled, you can view the enabled capabilities. This is useful for constructing your chaos experiment, since it includes the parameter schema for each fault.
87
+
88
+
```azurecli
89
+
az rest --method get --url "https://management.azure.com/{resourceId}/providers/Microsoft.Chaos/targets/{targetType}/capabilities?api-version={apiVersion}"
90
+
```
75
91
76
-
This section lists the Chaos Studio experiment commands.
92
+
## Experiments
77
93
78
-
#### List all the experiments in a resource group
94
+
These operations help you view, run, and manage experiments.
95
+
96
+
### List all the experiments in a resource group
79
97
80
98
```azurecli
81
-
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Chaos/chaosExperiments?api-version={apiVersion}" --resource "https://management.azure.com"
99
+
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Chaos/experiments?api-version={apiVersion}"
82
100
```
83
101
84
-
####Get an experiment's configuration details by name
102
+
### Get an experiment's configuration details by name
85
103
86
104
```azurecli
87
-
az rest --method get --url "https://management.azure.com/{experimentId}?api-version={apiVersion}" --resource "https://management.azure.com"
105
+
az rest --method get --url "https://management.azure.com/{experimentId}?api-version={apiVersion}"
88
106
```
89
107
90
-
####Create or update an experiment
108
+
### Create or update an experiment
91
109
92
110
```azurecli
93
-
az rest --method put --url "https://management.azure.com/{experimentId}?api-version={apiVersion}" --body @{experimentName.json} --resource "https://management.azure.com"
111
+
az rest --method put --url "https://management.azure.com/{experimentId}?api-version={apiVersion}" --body @{experimentName.json}
94
112
```
95
113
96
-
####Delete an experiment
114
+
### Delete an experiment
97
115
98
116
```azurecli
99
-
az rest --method delete --url "https://management.azure.com/{experimentId}?api-version={apiVersion}" --resource "https://management.azure.com" --verbose
117
+
az rest --method delete --url "https://management.azure.com/{experimentId}?api-version={apiVersion}"
100
118
```
101
119
102
-
####Start an experiment
120
+
### Start an experiment
103
121
104
122
```azurecli
105
123
az rest --method post --url "https://management.azure.com/{experimentId}/start?api-version={apiVersion}"
106
124
```
107
125
108
-
####Get past statuses of an experiment
126
+
### Get all executions of an experiment
109
127
110
128
```azurecli
111
-
az rest --method get --url "https://management.azure.com/{experimentId}/statuses?api-version={apiVersion}" --resource "https://management.azure.com"
129
+
az rest --method get --url "https://management.azure.com/{experimentId}/executions?api-version={apiVersion}"
112
130
```
113
131
114
-
#### Get the status of an experiment
132
+
### List the details of a specific experiment execution
133
+
134
+
If an experiment has failed, this can be used to find error messages and specific targets, branches, steps, or actions that failed.
115
135
116
136
```azurecli
117
-
az rest --method get --url "https://management.azure.com/{experimentId}/status?api-version={apiVersion}" --resource "https://management.azure.com"
137
+
az rest --method post --url "https://management.azure.com/{experimentId}/executions/{executionDetailsId}/getExecutionDetails?api-version={apiVersion}"
118
138
```
119
139
120
-
####Cancel (stop) an experiment
140
+
### Cancel (stop) an experiment
121
141
122
142
```azurecli
123
-
az rest --method get --url "https://management.azure.com/{experimentId}/cancel?api-version={apiVersion}" --resource "https://management.azure.com"
143
+
az rest --method post --url "https://management.azure.com/{experimentId}/cancel?api-version={apiVersion}"
124
144
```
125
145
126
-
#### List the details of the last two experiment executions
146
+
## Other helpful commands and tips
147
+
148
+
While these commands don't use the Chaos Studio API specifically, they can be helpful for using Chaos Studio effectively.
149
+
150
+
### View Chaos Studio resources with Azure Resource Graph
151
+
152
+
You can use the Azure Resource Graph [REST API](../governance/resource-graph/first-query-rest-api.md) to query resources associated with Chaos Studio, like targets and capabilities.
127
153
128
154
```azurecli
129
-
az rest --method get --url "https://management.azure.com/{experimentId}/executiondetails?api-version={apiVersion}" --resource "https://management.azure.com"
155
+
az rest --method post --url "https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01" --body "{'query':'chaosresources'}"
156
+
```
157
+
158
+
Alternatively, you can use Azure Resource Graph's `az cli`[extension](../governance/resource-graph/first-query-azurecli.md).
159
+
160
+
```azurecli-interactive
161
+
az graph query -q "chaosresources | summarize count() by type"
162
+
```
163
+
164
+
For example, if you want a summary of all the Chaos Studio targets active in your subscription by resource group, you can use:
165
+
166
+
```azurecli-interactive
167
+
az graph query -q "chaosresources | where type == 'microsoft.chaos/targets' | summarize count() by resourceGroup"
130
168
```
131
169
132
-
#### List the details of a specific experiment execution
170
+
### Filtering and querying
171
+
172
+
Like other Azure CLI commands, you can use the `--query` and `--filter` parameters with the Azure CLI `rest` commands. For example, to see a table of available capability types for a specific target type, use the following command:
133
173
134
174
```azurecli
135
-
az rest --method get --url "https://management.azure.com/{experimentId}/executiondetails/{executionDetailsId}?api-version={apiVersion}" --resource "https://management.azure.com"
175
+
az rest --method get --url "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Chaos/locations/{locationName}/targetTypes/{targetType}/capabilityTypes?api-version=2023-11-01" --output table --query 'value[].{name:name, faultType:properties.runtimeProperties.kind, urn:properties.urn}'
136
176
```
137
177
138
178
## Parameter definitions
139
179
140
-
| Parameter name | Definition | Lookup |
141
-
| --- | --- | --- |
142
-
| {apiVersion} | Version of the API to use when you execute the command provided | Can be found in the [API documentation](/rest/api/chaosstudio/)|
143
-
| {experimentId} | Azure Resource ID for the experiment | Can be found on the [Chaos Studio Experiment page](https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.chaos%2Fchaosexperiments)|
144
-
| {chaosProviderType} | Type or Name of Chaos Studio provider | Available providers can be found in the [List of current Provider Config Types](chaos-studio-fault-providers.md)|
145
-
| {experimentName.json} | JSON that contains the configuration of the chaos experiment | Generated by the user |
146
-
| {subscriptionId} | Subscription ID where the target resource is located | Can be found on the [Subscriptions page](https://portal.azure.com/#blade/Microsoft_Azure_Billing/SubscriptionsBlade)|
147
-
| {resourceGroupName} | Name of the resource group where the target resource is located | Can be found on the [Resource groups page](https://portal.azure.com/#blade/HubsExtension/BrowseResourceGroups)|
148
-
| {executionDetailsId} | Execution ID of an experiment execution | Can be found on the [Chaos Studio Experiment page](https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.chaos%2Fchaosexperiments)|
180
+
This section describes the parameters used throughout this document and how you can fill them in.
181
+
182
+
| Parameter name | Definition | Lookup | Example |
183
+
| --- | --- | --- | --- |
184
+
| {apiVersion} | Version of the API to use when you execute the command provided | Can be found in the [API documentation](/rest/api/chaosstudio/)|`2023-11-01`|
185
+
| {experimentId} | Azure Resource ID for the experiment | Can be found on the [Chaos Studio Experiment page](https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.chaos%2Fchaosexperiments) or with a [GET call](#list-all-the-experiments-in-a-resource-group) to the `/experiments` endpoint |`/subscriptions/6b052e15-03d3-4f17-b2e1-be7f07588291/resourceGroups/my-resource-group/providers/Microsoft.Chaos/experiments/my-chaos-experiment`|
186
+
| {experimentName.json} | JSON that contains the configuration of the chaos experiment | Generated by the user |`experiment.json` (See [a CLI tutorial](chaos-studio-tutorial-service-direct-cli.md) for a full example file) |
187
+
| {subscriptionId} | Subscription ID where the target resource is located | Find in the [Azure portal Subscriptions page](https://portal.azure.com/#blade/Microsoft_Azure_Billing/SubscriptionsBlade) or by running `az account list --output table`|`6b052e15-03d3-4f17-b2e1-be7f07588291`|
188
+
| {resourceGroupName} | Name of the resource group where the target resource is located | Find in the [Resource Groups page](https://portal.azure.com/#blade/HubsExtension/BrowseResourceGroups) or by running `az group list --output table`|`my-resource-group`|
189
+
| {executionDetailsId} | Execution ID of an experiment execution | Find in the [Chaos Studio Experiment page](https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.chaos%2Fchaosexperiments) or with a [GET call](#get-all-executions-of-an-experiment) to the `/executions` endpoint |`C69E7FCD-1548-47E5-9DDA-92A5DD60E610`|
190
+
| {targetType} | Type of target for the corresponding resource | Find in the [Fault providers list](chaos-studio-fault-providers.md) or a [GET call](#list-all-target-types-available-in-a-region) to the `/locations/{locationName}/targetTypes` endpoint |`Microsoft-VirtualMachine`|
191
+
| {capabilityName} | Name of an individual capability resource, extending a target resource | Find in the [fault reference documentation](chaos-studio-fault-library.md) or with a [GET call](#list-all-capabilities-available-for-a-target-type) to the `capabilityTypes` endpoint |`Shutdown-1.0`|
192
+
| {locationName} | Azure region for a resource or regional endpoint | Find all possible regions for your account with `az account list-locations --output table`|`eastus`|
0 commit comments