{monitor} fix dynamic metric alert creation with a single scope (#16225)

* fix dynamic metric alert creation with a single scope

* fix style issues
This commit is contained in:
kai ru 2020-12-21 14:36:20 +08:00 коммит произвёл GitHub
Родитель 57a0b81012
Коммит 7430c74576
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 2733 добавлений и 3553 удалений

Двоичные данные
.ionide/symbolCache.db Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=too-many-locals
from azure.cli.command_modules.monitor.util import get_operator_map, get_aggregation_map
from knack.log import get_logger
@ -16,7 +17,8 @@ def create_metric_alert(client, resource_group_name, rule_name, scopes, conditio
auto_mitigate=None, target_resource_type=None, target_resource_region=None):
from azure.mgmt.monitor.models import (MetricAlertResource,
MetricAlertSingleResourceMultipleMetricCriteria,
MetricAlertMultipleResourceMultipleMetricCriteria)
MetricAlertMultipleResourceMultipleMetricCriteria,
MetricCriteria)
from azure.cli.core import CLIError
# generate names for the conditions
for i, cond in enumerate(condition):
@ -28,7 +30,7 @@ def create_metric_alert(client, resource_group_name, rule_name, scopes, conditio
raise CLIError('--target-resource-type and --target-resource-region must be provided.')
criteria = MetricAlertMultipleResourceMultipleMetricCriteria(all_of=condition)
else:
if len(scopes) == 1:
if len(scopes) == 1 and isinstance(condition, MetricCriteria):
criteria = MetricAlertSingleResourceMultipleMetricCriteria(all_of=condition)
else:
criteria = MetricAlertMultipleResourceMultipleMetricCriteria(all_of=condition)

Просмотреть файл

@ -0,0 +1,777 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-resource/10.3.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001?api-version=2020-06-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001","name":"cli_test_dynamic_metric_alert000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2020-12-10T07:15:58Z"},"properties":{"provisioningState":"Succeeded"}}'
headers:
cache-control:
- no-cache
content-length:
- '428'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:16:02 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.22.0
method: GET
uri: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json
response:
body:
string: "{\n \"$schema\": \"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json\",\n
\ \"contentVersion\": \"1.0.0.0\",\n \"parameters\": {},\n \"variables\":
{},\n \"resources\": [],\n \"outputs\": {\n \"aliases\": {\n \"type\":
\"object\",\n \"value\": {\n \"Linux\": {\n \"CentOS\":
{\n \"publisher\": \"OpenLogic\",\n \"offer\": \"CentOS\",\n
\ \"sku\": \"7.5\",\n \"version\": \"latest\"\n },\n
\ \"CoreOS\": {\n \"publisher\": \"CoreOS\",\n \"offer\":
\"CoreOS\",\n \"sku\": \"Stable\",\n \"version\": \"latest\"\n
\ },\n \"Debian\": {\n \"publisher\": \"Debian\",\n
\ \"offer\": \"debian-10\",\n \"sku\": \"10\",\n \"version\":
\"latest\"\n },\n \"openSUSE-Leap\": {\n \"publisher\":
\"SUSE\",\n \"offer\": \"openSUSE-Leap\",\n \"sku\":
\"42.3\",\n \"version\": \"latest\"\n },\n \"RHEL\":
{\n \"publisher\": \"RedHat\",\n \"offer\": \"RHEL\",\n
\ \"sku\": \"7-LVM\",\n \"version\": \"latest\"\n },\n
\ \"SLES\": {\n \"publisher\": \"SUSE\",\n \"offer\":
\"SLES\",\n \"sku\": \"15\",\n \"version\": \"latest\"\n
\ },\n \"UbuntuLTS\": {\n \"publisher\": \"Canonical\",\n
\ \"offer\": \"UbuntuServer\",\n \"sku\": \"18.04-LTS\",\n
\ \"version\": \"latest\"\n }\n },\n \"Windows\":
{\n \"Win2019Datacenter\": {\n \"publisher\": \"MicrosoftWindowsServer\",\n
\ \"offer\": \"WindowsServer\",\n \"sku\": \"2019-Datacenter\",\n
\ \"version\": \"latest\"\n },\n \"Win2016Datacenter\":
{\n \"publisher\": \"MicrosoftWindowsServer\",\n \"offer\":
\"WindowsServer\",\n \"sku\": \"2016-Datacenter\",\n \"version\":
\"latest\"\n },\n \"Win2012R2Datacenter\": {\n \"publisher\":
\"MicrosoftWindowsServer\",\n \"offer\": \"WindowsServer\",\n \"sku\":
\"2012-R2-Datacenter\",\n \"version\": \"latest\"\n },\n
\ \"Win2012Datacenter\": {\n \"publisher\": \"MicrosoftWindowsServer\",\n
\ \"offer\": \"WindowsServer\",\n \"sku\": \"2012-Datacenter\",\n
\ \"version\": \"latest\"\n },\n \"Win2008R2SP1\":
{\n \"publisher\": \"MicrosoftWindowsServer\",\n \"offer\":
\"WindowsServer\",\n \"sku\": \"2008-R2-SP1\",\n \"version\":
\"latest\"\n }\n }\n }\n }\n }\n}\n"
headers:
accept-ranges:
- bytes
access-control-allow-origin:
- '*'
cache-control:
- max-age=300
connection:
- keep-alive
content-length:
- '2501'
content-security-policy:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type:
- text/plain; charset=utf-8
date:
- Thu, 10 Dec 2020 07:16:03 GMT
etag:
- W/"540044b4084c3c314537f1baa1770f248628b2bc9ba0328f1004c33862e049da"
expires:
- Thu, 10 Dec 2020 07:21:03 GMT
source-age:
- '158'
strict-transport-security:
- max-age=31536000
vary:
- Authorization,Accept-Encoding
via:
- 1.1 varnish (Varnish/6.0), 1.1 varnish
x-cache:
- HIT, HIT
x-cache-hits:
- 1, 1
x-content-type-options:
- nosniff
x-fastly-request-id:
- 4f4696c2d2a1d6b44bc1b25c9f1b9a4dc85c2b79
x-frame-options:
- deny
x-github-request-id:
- EEFC:4EB0:19B54:1DF68:5FD1CAA6
x-served-by:
- cache-sin18039-SIN
x-timer:
- S1607584564.603276,VS0,VE1
x-xss-protection:
- 1; mode=block
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-network/13.0.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks?api-version=2018-01-01
response:
body:
string: '{"value":[]}'
headers:
cache-control:
- no-cache
content-length:
- '12'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:16:03 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: '{"properties": {"template": {"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0", "parameters": {"adminPassword": {"type": "securestring",
"metadata": {"description": "Secure adminPassword"}}}, "variables": {}, "resources":
[{"name": "clitest-vm000002VNET", "type": "Microsoft.Network/virtualNetworks",
"location": "westus", "apiVersion": "2015-06-15", "dependsOn": [], "tags": {"MabUsed":
"Yes", "Owner": "sisi", "Purpose": "CLITest", "DeleteBy": "12-2099", "AutoShutdown":
"No"}, "properties": {"addressSpace": {"addressPrefixes": ["10.0.0.0/16"]},
"subnets": [{"name": "clitest-vm000002Subnet", "properties": {"addressPrefix":
"10.0.0.0/24"}}]}}, {"type": "Microsoft.Network/networkSecurityGroups", "name":
"clitest-vm000002NSG", "apiVersion": "2015-06-15", "location": "westus", "tags":
{"MabUsed": "Yes", "Owner": "sisi", "Purpose": "CLITest", "DeleteBy": "12-2099",
"AutoShutdown": "No"}, "dependsOn": []}, {"apiVersion": "2018-01-01", "type":
"Microsoft.Network/publicIPAddresses", "name": "clitest-vm000002PublicIP", "location":
"westus", "tags": {"MabUsed": "Yes", "Owner": "sisi", "Purpose": "CLITest",
"DeleteBy": "12-2099", "AutoShutdown": "No"}, "dependsOn": [], "properties":
{"publicIPAllocationMethod": null}}, {"apiVersion": "2015-06-15", "type": "Microsoft.Network/networkInterfaces",
"name": "clitest-vm000002VMNic", "location": "westus", "tags": {"MabUsed": "Yes",
"Owner": "sisi", "Purpose": "CLITest", "DeleteBy": "12-2099", "AutoShutdown":
"No"}, "dependsOn": ["Microsoft.Network/virtualNetworks/clitest-vm000002VNET",
"Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG", "Microsoft.Network/publicIpAddresses/clitest-vm000002PublicIP"],
"properties": {"ipConfigurations": [{"name": "ipconfigclitest-vm000002", "properties":
{"privateIPAllocationMethod": "Dynamic", "subnet": {"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks/clitest-vm000002VNET/subnets/clitest-vm000002Subnet"},
"publicIPAddress": {"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP"}}}],
"networkSecurityGroup": {"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG"}}},
{"apiVersion": "2020-06-01", "type": "Microsoft.Compute/virtualMachines", "name":
"clitest-vm000002", "location": "westus", "tags": {"MabUsed": "Yes", "Owner":
"sisi", "Purpose": "CLITest", "DeleteBy": "12-2099", "AutoShutdown": "No"},
"dependsOn": ["Microsoft.Network/networkInterfaces/clitest-vm000002VMNic"],
"properties": {"hardwareProfile": {"vmSize": "Standard_DS1_v2"}, "networkProfile":
{"networkInterfaces": [{"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic"}]},
"storageProfile": {"osDisk": {"createOption": "fromImage", "name": null, "caching":
"ReadWrite", "managedDisk": {"storageAccountType": null}}, "imageReference":
{"publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2012-R2-Datacenter",
"version": "latest"}}, "osProfile": {"computerName": "clitest-vm000002", "adminUsername":
"clitest-vm000002", "adminPassword": "[parameters(''adminPassword'')]"}}}],
"outputs": {}}, "parameters": {"adminPassword": {"value": "%j^VYw9Q3Z@Cu$*h"}},
"mode": "Incremental"}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
Content-Length:
- '3772'
Content-Type:
- application/json; charset=utf-8
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-resource/10.3.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/mock-deployment?api-version=2020-06-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/vm_deploy_roJcy0mI6vQQqjXv8xxFe1sami9nE3WH","name":"vm_deploy_roJcy0mI6vQQqjXv8xxFe1sami9nE3WH","type":"Microsoft.Resources/deployments","properties":{"templateHash":"3884962447141476065","parameters":{"adminPassword":{"type":"SecureString"}},"mode":"Incremental","provisioningState":"Accepted","timestamp":"2020-12-10T07:16:08.9969121Z","duration":"PT2.7830653S","correlationId":"39064945-b460-4434-bac2-ce695af332df","providers":[{"namespace":"Microsoft.Network","resourceTypes":[{"resourceType":"virtualNetworks","locations":["westus"]},{"resourceType":"networkSecurityGroups","locations":["westus"]},{"resourceType":"publicIPAddresses","locations":["westus"]},{"resourceType":"networkInterfaces","locations":["westus"]}]},{"namespace":"Microsoft.Compute","resourceTypes":[{"resourceType":"virtualMachines","locations":["westus"]}]}],"dependencies":[{"dependsOn":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks/clitest-vm000002VNET","resourceType":"Microsoft.Network/virtualNetworks","resourceName":"clitest-vm000002VNET"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG","resourceType":"Microsoft.Network/networkSecurityGroups","resourceName":"clitest-vm000002NSG"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP","resourceType":"Microsoft.Network/publicIPAddresses","resourceName":"clitest-vm000002PublicIP"}],"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic","resourceType":"Microsoft.Network/networkInterfaces","resourceName":"clitest-vm000002VMNic"},{"dependsOn":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic","resourceType":"Microsoft.Network/networkInterfaces","resourceName":"clitest-vm000002VMNic"}],"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002","resourceType":"Microsoft.Compute/virtualMachines","resourceName":"clitest-vm000002"}]}}'
headers:
azure-asyncoperation:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/vm_deploy_roJcy0mI6vQQqjXv8xxFe1sami9nE3WH/operationStatuses/08585940223192637832?api-version=2020-06-01
cache-control:
- no-cache
content-length:
- '2925'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:16:10 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1196'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-resource/10.3.0 Azure-SDK-For-Python AZURECLI/2.16.0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/mock-deployment/operationStatuses/08585940223192637832?api-version=2020-06-01
response:
body:
string: '{"status":"Running"}'
headers:
cache-control:
- no-cache
content-length:
- '20'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:16:40 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-resource/10.3.0 Azure-SDK-For-Python AZURECLI/2.16.0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/mock-deployment/operationStatuses/08585940223192637832?api-version=2020-06-01
response:
body:
string: '{"status":"Succeeded"}'
headers:
cache-control:
- no-cache
content-length:
- '22'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:11 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-resource/10.3.0 Azure-SDK-For-Python AZURECLI/2.16.0
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/mock-deployment?api-version=2020-06-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Resources/deployments/vm_deploy_roJcy0mI6vQQqjXv8xxFe1sami9nE3WH","name":"vm_deploy_roJcy0mI6vQQqjXv8xxFe1sami9nE3WH","type":"Microsoft.Resources/deployments","properties":{"templateHash":"3884962447141476065","parameters":{"adminPassword":{"type":"SecureString"}},"mode":"Incremental","provisioningState":"Succeeded","timestamp":"2020-12-10T07:17:09.2062082Z","duration":"PT1M2.9923614S","correlationId":"39064945-b460-4434-bac2-ce695af332df","providers":[{"namespace":"Microsoft.Network","resourceTypes":[{"resourceType":"virtualNetworks","locations":["westus"]},{"resourceType":"networkSecurityGroups","locations":["westus"]},{"resourceType":"publicIPAddresses","locations":["westus"]},{"resourceType":"networkInterfaces","locations":["westus"]}]},{"namespace":"Microsoft.Compute","resourceTypes":[{"resourceType":"virtualMachines","locations":["westus"]}]}],"dependencies":[{"dependsOn":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks/clitest-vm000002VNET","resourceType":"Microsoft.Network/virtualNetworks","resourceName":"clitest-vm000002VNET"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG","resourceType":"Microsoft.Network/networkSecurityGroups","resourceName":"clitest-vm000002NSG"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP","resourceType":"Microsoft.Network/publicIPAddresses","resourceName":"clitest-vm000002PublicIP"}],"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic","resourceType":"Microsoft.Network/networkInterfaces","resourceName":"clitest-vm000002VMNic"},{"dependsOn":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic","resourceType":"Microsoft.Network/networkInterfaces","resourceName":"clitest-vm000002VMNic"}],"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002","resourceType":"Microsoft.Compute/virtualMachines","resourceName":"clitest-vm000002"}],"outputs":{},"outputResources":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks/clitest-vm000002VNET"}]}}'
headers:
cache-control:
- no-cache
content-length:
- '4051'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:11 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- AZURECLI/2.16.0 azsdk-python-azure-mgmt-compute/18.0.0 Python/3.8.6 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002?$expand=instanceView&api-version=2020-06-01
response:
body:
string: "{\r\n \"name\": \"clitest-vm000002\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002\",\r\n
\ \"type\": \"Microsoft.Compute/virtualMachines\",\r\n \"location\": \"westus\",\r\n
\ \"tags\": {\r\n \"MabUsed\": \"Yes\",\r\n \"Owner\": \"sisi\",\r\n
\ \"Purpose\": \"CLITest\",\r\n \"DeleteBy\": \"12-2099\",\r\n \"AutoShutdown\":
\"No\"\r\n },\r\n \"properties\": {\r\n \"vmId\": \"f84b134b-f814-4594-b8e6-8bcfbba88017\",\r\n
\ \"hardwareProfile\": {\r\n \"vmSize\": \"Standard_DS1_v2\"\r\n },\r\n
\ \"storageProfile\": {\r\n \"imageReference\": {\r\n \"publisher\":
\"MicrosoftWindowsServer\",\r\n \"offer\": \"WindowsServer\",\r\n \"sku\":
\"2012-R2-Datacenter\",\r\n \"version\": \"latest\",\r\n \"exactVersion\":
\"9600.19873.2011052019\"\r\n },\r\n \"osDisk\": {\r\n \"osType\":
\"Windows\",\r\n \"name\": \"clitest-vm000002_disk1_aea6339a5b6c4c8582179513443f4e4d\",\r\n
\ \"createOption\": \"FromImage\",\r\n \"caching\": \"ReadWrite\",\r\n
\ \"managedDisk\": {\r\n \"storageAccountType\": \"Premium_LRS\",\r\n
\ \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/disks/clitest-vm000002_disk1_aea6339a5b6c4c8582179513443f4e4d\"\r\n
\ },\r\n \"diskSizeGB\": 127\r\n },\r\n \"dataDisks\":
[]\r\n },\r\n \"osProfile\": {\r\n \"computerName\": \"clitest-vm000002\",\r\n
\ \"adminUsername\": \"clitest-vm000002\",\r\n \"windowsConfiguration\":
{\r\n \"provisionVMAgent\": true,\r\n \"enableAutomaticUpdates\":
true,\r\n \"patchSettings\": {\r\n \"patchMode\": \"AutomaticByOS\"\r\n
\ }\r\n },\r\n \"secrets\": [],\r\n \"allowExtensionOperations\":
true,\r\n \"requireGuestProvisionSignal\": true\r\n },\r\n \"networkProfile\":
{\"networkInterfaces\":[{\"id\":\"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic\"}]},\r\n
\ \"provisioningState\": \"Succeeded\",\r\n \"instanceView\": {\r\n \"vmAgent\":
{\r\n \"vmAgentVersion\": \"Unknown\",\r\n \"statuses\": [\r\n
\ {\r\n \"code\": \"ProvisioningState/Unavailable\",\r\n
\ \"level\": \"Warning\",\r\n \"displayStatus\": \"Not
Ready\",\r\n \"message\": \"VM status blob is found but not yet
populated.\",\r\n \"time\": \"2020-12-10T07:17:13+00:00\"\r\n }\r\n
\ ]\r\n },\r\n \"disks\": [\r\n {\r\n \"name\":
\"clitest-vm000002_disk1_aea6339a5b6c4c8582179513443f4e4d\",\r\n \"statuses\":
[\r\n {\r\n \"code\": \"ProvisioningState/succeeded\",\r\n
\ \"level\": \"Info\",\r\n \"displayStatus\": \"Provisioning
succeeded\",\r\n \"time\": \"2020-12-10T07:16:46.0360381+00:00\"\r\n
\ }\r\n ]\r\n }\r\n ],\r\n \"hyperVGeneration\":
\"V1\",\r\n \"statuses\": [\r\n {\r\n \"code\": \"ProvisioningState/succeeded\",\r\n
\ \"level\": \"Info\",\r\n \"displayStatus\": \"Provisioning
succeeded\",\r\n \"time\": \"2020-12-10T07:17:07.7400214+00:00\"\r\n
\ },\r\n {\r\n \"code\": \"PowerState/running\",\r\n
\ \"level\": \"Info\",\r\n \"displayStatus\": \"VM running\"\r\n
\ }\r\n ]\r\n }\r\n }\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '3412'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:12 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-resource:
- Microsoft.Compute/LowCostGet3Min;3993,Microsoft.Compute/LowCostGet30Min;31950
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-network/13.0.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic?api-version=2018-01-01
response:
body:
string: "{\r\n \"name\": \"clitest-vm000002VMNic\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic\",\r\n
\ \"etag\": \"W/\\\"42971777-cb0c-4ffe-a7af-56349ac8d189\\\"\",\r\n \"location\":
\"westus\",\r\n \"tags\": {\r\n \"MabUsed\": \"Yes\",\r\n \"Owner\":
\"sisi\",\r\n \"Purpose\": \"CLITest\",\r\n \"DeleteBy\": \"12-2099\",\r\n
\ \"AutoShutdown\": \"No\"\r\n },\r\n \"properties\": {\r\n \"provisioningState\":
\"Succeeded\",\r\n \"resourceGuid\": \"3f347bf7-43ad-432c-901c-9ff347933e79\",\r\n
\ \"ipConfigurations\": [\r\n {\r\n \"name\": \"ipconfigclitest-vm000002\",\r\n
\ \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic/ipConfigurations/ipconfigclitest-vm000002\",\r\n
\ \"etag\": \"W/\\\"42971777-cb0c-4ffe-a7af-56349ac8d189\\\"\",\r\n
\ \"type\": \"Microsoft.Network/networkInterfaces/ipConfigurations\",\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Succeeded\",\r\n
\ \"privateIPAddress\": \"10.0.0.4\",\r\n \"privateIPAllocationMethod\":
\"Dynamic\",\r\n \"publicIPAddress\": {\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP\"\r\n
\ },\r\n \"subnet\": {\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/virtualNetworks/clitest-vm000002VNET/subnets/clitest-vm000002Subnet\"\r\n
\ },\r\n \"primary\": true,\r\n \"privateIPAddressVersion\":
\"IPv4\"\r\n }\r\n }\r\n ],\r\n \"dnsSettings\": {\r\n \"dnsServers\":
[],\r\n \"appliedDnsServers\": [],\r\n \"internalDomainNameSuffix\":
\"l4iqkvuwhgdefjuhby4l4ja30h.dx.internal.cloudapp.net\"\r\n },\r\n \"macAddress\":
\"00-0D-3A-59-73-B8\",\r\n \"enableAcceleratedNetworking\": false,\r\n
\ \"enableIPForwarding\": false,\r\n \"networkSecurityGroup\": {\r\n
\ \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkSecurityGroups/clitest-vm000002NSG\"\r\n
\ },\r\n \"primary\": true,\r\n \"virtualMachine\": {\r\n \"id\":
\"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002\"\r\n
\ }\r\n },\r\n \"type\": \"Microsoft.Network/networkInterfaces\"\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '2818'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:13 GMT
etag:
- W/"42971777-cb0c-4ffe-a7af-56349ac8d189"
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- ca41b5a9-328f-4e58-971a-2416b23a371c
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- vm create
Connection:
- keep-alive
ParameterSetName:
- -n -g --image --admin-username --admin-password --tags --nsg-rule
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-network/13.0.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP?api-version=2018-01-01
response:
body:
string: "{\r\n \"name\": \"clitest-vm000002PublicIP\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/publicIPAddresses/clitest-vm000002PublicIP\",\r\n
\ \"etag\": \"W/\\\"99fc0772-2e65-4ec4-af26-ee13f78bb50b\\\"\",\r\n \"location\":
\"westus\",\r\n \"tags\": {\r\n \"MabUsed\": \"Yes\",\r\n \"Owner\":
\"sisi\",\r\n \"Purpose\": \"CLITest\",\r\n \"DeleteBy\": \"12-2099\",\r\n
\ \"AutoShutdown\": \"No\"\r\n },\r\n \"properties\": {\r\n \"provisioningState\":
\"Succeeded\",\r\n \"resourceGuid\": \"b8c40dd3-21a3-407d-87cd-06da883eb690\",\r\n
\ \"ipAddress\": \"104.40.26.62\",\r\n \"publicIPAddressVersion\": \"IPv4\",\r\n
\ \"publicIPAllocationMethod\": \"Dynamic\",\r\n \"idleTimeoutInMinutes\":
4,\r\n \"ipTags\": [],\r\n \"ipConfiguration\": {\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Network/networkInterfaces/clitest-vm000002VMNic/ipConfigurations/ipconfigclitest-vm000002\"\r\n
\ }\r\n },\r\n \"type\": \"Microsoft.Network/publicIPAddresses\",\r\n
\ \"sku\": {\r\n \"name\": \"Basic\"\r\n }\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '1174'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:13 GMT
etag:
- W/"99fc0772-2e65-4ec4-af26-ee13f78bb50b"
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- a4ab1b47-aeff-48f8-8553-4e516532ec24
status:
code: 200
message: OK
- request:
body: '{"location": "global", "properties": {"groupShortName": "ag1", "enabled":
true, "emailReceivers": [], "smsReceivers": [], "webhookReceivers": [], "itsmReceivers":
[], "azureAppPushReceivers": [], "automationRunbookReceivers": [], "voiceReceivers":
[], "logicAppReceivers": [], "azureFunctionReceivers": [], "armRoleReceivers":
[]}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- monitor action-group create
Connection:
- keep-alive
Content-Length:
- '331'
Content-Type:
- application/json; charset=utf-8
ParameterSetName:
- -g -n
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-monitor/0.11.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/microsoft.insights/actionGroups/ag1?api-version=2019-06-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/microsoft.insights/actionGroups/ag1","type":"Microsoft.Insights/ActionGroups","name":"ag1","location":"Global","kind":null,"tags":null,"properties":{"groupShortName":"ag1","enabled":true,"emailReceivers":[],"smsReceivers":[],"webhookReceivers":[],"itsmReceivers":[],"azureAppPushReceivers":[],"automationRunbookReceivers":[],"voiceReceivers":[],"logicAppReceivers":[],"azureFunctionReceivers":[],"armRoleReceivers":[]},"identity":null}'
headers:
cache-control:
- no-cache
content-length:
- '595'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:21 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-IIS/10.0
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1197'
status:
code: 201
message: Created
- request:
body: '{"location": "global", "properties": {"description": "High CPU", "severity":
2, "enabled": true, "scopes": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002"],
"evaluationFrequency": "PT1M", "windowSize": "PT5M", "targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "global", "criteria": {"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [{"name": "cond0", "metricName": "Percentage CPU", "timeAggregation":
"Average", "dimensions": [], "criterionType": "DynamicThresholdCriterion", "operator":
"GreaterThan", "alertSensitivity": "Low", "failingPeriods": {"numberOfEvaluationPeriods":
4.0, "minFailingPeriodsToAlert": 2.0}, "ignoreDataBefore": "2020-11-01T16:00:00.000Z"}]},
"actions": [{"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/microsoft.insights/actionGroups/ag1"}]}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- monitor metrics alert create
Connection:
- keep-alive
Content-Length:
- '1124'
Content-Type:
- application/json; charset=utf-8
ParameterSetName:
- -g -n --scopes --action --condition --description
User-Agent:
- python/3.8.6 (Windows-10-10.0.19041-SP0) msrest/0.6.18 msrest_azure/0.6.3
azure-mgmt-monitor/0.11.0 Azure-SDK-For-Python AZURECLI/2.16.0
accept-language:
- en-US
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Insights/metricAlerts/alert1?api-version=2018-03-01
response:
body:
string: "{\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Insights/metricAlerts/alert1\",\r\n
\ \"name\": \"alert1\",\r\n \"type\": \"Microsoft.Insights/metricAlerts\",\r\n
\ \"location\": \"global\",\r\n \"properties\": {\r\n \"description\":
\"High CPU\",\r\n \"severity\": 2,\r\n \"enabled\": true,\r\n \"scopes\":
[\r\n \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/Microsoft.Compute/virtualMachines/clitest-vm000002\"\r\n
\ ],\r\n \"evaluationFrequency\": \"PT1M\",\r\n \"windowSize\": \"PT5M\",\r\n
\ \"criteria\": {\r\n \"allOf\": [\r\n {\r\n \"alertSensitivity\":
\"Low\",\r\n \"failingPeriods\": {\r\n \"numberOfEvaluationPeriods\":
4,\r\n \"minFailingPeriodsToAlert\": 2\r\n },\r\n \"ignoreDataBefore\":
\"2020-11-01T16:00:00.000Z\",\r\n \"name\": \"cond0\",\r\n \"metricNamespace\":
\"Microsoft.Compute/virtualMachines\",\r\n \"metricName\": \"Percentage
CPU\",\r\n \"operator\": \"GreaterThan\",\r\n \"timeAggregation\":
\"Average\",\r\n \"criterionType\": \"DynamicThresholdCriterion\"\r\n
\ }\r\n ],\r\n \"odata.type\": \"Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria\"\r\n
\ },\r\n \"targetResourceType\": \"Microsoft.Compute/virtualMachines\",\r\n
\ \"targetResourceRegion\": \"global\",\r\n \"actions\": [\r\n {\r\n
\ \"actionGroupId\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dynamic_metric_alert000001/providers/microsoft.insights/actionGroups/ag1\"\r\n
\ }\r\n ]\r\n }\r\n}"
headers:
api-supported-versions:
- 1.0, 2.0, 2017-09-01-preview, 2018-03-01
cache-control:
- no-cache
content-length:
- '1727'
content-type:
- application/json; charset=utf-8
date:
- Thu, 10 Dec 2020 07:17:36 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-IIS/10.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-aspnet-version:
- 4.0.30319
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-resource-requests:
- '299'
x-powered-by:
- ASP.NET
status:
code: 200
message: OK
version: 1

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -265,6 +265,42 @@ class MonitorTests(ScenarioTest):
self.check('length(scopes)', 2),
])
@ResourceGroupPreparer(name_prefix='cli_test_dynamic_metric_alert')
@VMPreparer(parameter_name='vm1')
def test_dynamic_metric_alert_basic(self, resource_group, vm1):
from azure.mgmt.core.tools import resource_id
self.kwargs.update({
'alert': 'alert1',
'plan': 'plan1',
'app': self.create_random_name('app', 15),
'ag1': 'ag1',
'webhooks': '{{test=banoodle}}',
'sub': self.get_subscription_id(),
'vm_id': resource_id(
resource_group=resource_group,
subscription=self.get_subscription_id(),
name=vm1,
namespace='Microsoft.Compute',
type='virtualMachines'),
})
self.cmd('monitor action-group create -g {rg} -n {ag1}')
self.cmd(
'monitor metrics alert create -g {rg} -n {alert} --scopes {vm_id} --action {ag1} --condition "avg Percentage CPU > dynamic low 2 of 4 since 2020-11-01T16:00:00.000Z" --description "High CPU"',
checks=[
self.check('description', 'High CPU'),
self.check('severity', 2),
self.check('autoMitigate', None),
self.check('windowSize', '0:05:00'),
self.check('evaluationFrequency', '0:01:00'),
self.check('length(scopes)', 1),
self.check('criteria.allOf[0].alertSensitivity', 'Low'),
self.check('criteria.allOf[0].criterionType', 'DynamicThresholdCriterion'),
self.check('criteria.allOf[0].failingPeriods.minFailingPeriodsToAlert', 2.0),
self.check('criteria.allOf[0].failingPeriods.numberOfEvaluationPeriods', 4.0),
self.check('criteria.allOf[0].operator', 'GreaterThan'),
self.check('criteria.allOf[0].ignoreDataBefore', '2020-11-01T16:00:00+00:00')
])
@ResourceGroupPreparer(name_prefix='cli_test_dynamic_metric_alert_v2')
@VMPreparer(parameter_name='vm1')
@VMPreparer(parameter_name='vm2')