由于 'actionGroupId',Azure 应用见解(具有新的警报指标)部署失败
Azure App insights (with new alert metrics) deployment failing due to 'actionGroupId'
我正在使用新的指标规则创建应用程序见解。
我之前使用的是经典警报,并且在 2019 年 9 月 1 日之前工作正常。我想采用新警报,所以我正在修改下面的 arm 模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_location_shortname": {
"defaultValue": "",
"type": "string",
"maxLength": 3
},
"applicationinsights_project": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_environment": {
"defaultValue": "",
"type": "string",
"maxLength": 7
},
"applicationinsights_uniqueid": {
"defaultValue": "1",
"type": "string",
"maxLength": 1
},
"applicationinsights_componentKind": {
"type": "string",
"allowedValues": [
"web",
"ios",
"other",
"store",
"java",
"phone"
],
"defaultValue": "web",
"metadata": {
"description": "application insights component kind"
}
},
"applicationinsights_alertDescription": {
"type": "string",
"defaultValue": "This is a metric alert",
"metadata": {
"description": "Description of alert"
}
},
"applicationinsights_alertSeverity": {
"type": "int",
"defaultValue": 3,
"allowedValues": [
0,
1,
2,
3,
4
],
"metadata": {
"description": "Severity of alert {0,1,2,3,4}"
}
},
"applicationinsights_isEnabled": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Specifies whether the alert is enabled"
}
},
"applicationinsights_metricName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Name of the metric used in the comparison to activate the alert."
}
},
"applicationinsights_operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"Equals",
"NotEquals",
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
}
},
"applicationinsights_threshold": {
"type": "string",
"defaultValue": "0",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
},
"applicationinsights_timeAggregation": {
"type": "string",
"defaultValue": "Average",
"allowedValues": [
"Average",
"Minimum",
"Maximum",
"Total",
"Count"
],
"metadata": {
"description": "How the data that is collected should be combined over time."
}
},
"applicationinsights_windowSize": {
"type": "string",
"defaultValue": "PT5M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H",
"PT6H",
"PT12H",
"PT24H"
],
"metadata": {
"description": "Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format."
}
},
"evaluationFrequency": {
"type": "string",
"defaultValue": "PT1M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H"
],
"metadata": {
"description": "how often the metric alert is evaluated represented in ISO 8601 duration format"
}
},
"applicationinsights_instrumentation_key_output": {
"defaultValue": "ApplicationInsightsInstrumentationKey",
"type": "string"
},
"applicationinsights_actionGroupId": {
"type": "string",
"defaultValue": "test",
"metadata": {
"description": "The ID of the action group that is triggered when the alert is activated or deactivated"
}
}
},
"variables": {
"basename": "[concat(parameters('applicationinsights_platform'), '-', parameters('applicationinsights_project'), '-', parameters('applicationinsights_location_shortname'), '-', parameters('applicationinsights_environment'))]",
"alertRulesName": "[concat(variables('basename'), '-aaiar-', parameters('applicationinsights_uniqueid'))]",
"appInsightName": "[concat(variables('basename'), '-aaic-', parameters('applicationinsights_uniqueid'))]"
},
"resources": [
{
"name": "[variables('alertRulesName')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsightName')))]": "Resource"
},
"properties": {
"name": "[variables('alertRulesName')]",
"description": "Alert rule assigned to Application Insight component",
"severity": "[parameters('applicationinsights_alertSeverity')]",
"enabled": "[parameters('applicationinsights_isEnabled')]",
"scopes": ["[resourceId('microsoft.insights/components', variables('appInsightName'))]"],
"evaluationFrequency":"[parameters('evaluationFrequency')]",
"windowSize": "[parameters('applicationinsights_windowSize')]",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name" : "test01",
"metricName": "[parameters('applicationinsights_metricName')]",
"dimensions":[],
"operator": "[parameters('applicationinsights_operator')]",
"threshold" : "[parameters('applicationinsights_threshold')]",
"timeAggregation": "[parameters('applicationinsights_timeAggregation')]"
}
]
},
"actions": [
{
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_platform'))]"
}
]
},
"dependsOn": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]"
]
},
{
"name": "[variables('appInsightName')]",
"type": "microsoft.insights/components",
"apiVersion": "2015-05-01",
"location": "[resourceGroup().location]",
"tags": {},
"kind": "[parameters('applicationinsights_componentKind')]",
"properties": {
"ApplicationId": "[variables('appInsightName')]"
}}
],
"outputs": {
"secrets": {
"type": "object",
"value": {
"[parameters('applicationinsights_instrumentation_key_output')]": "[reference(concat('microsoft.insights/components/', variables('appInsightName'))).InstrumentationKey]"
}
}
}
}
我的参数文件是-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"value": "abc"
},
"applicationinsights_location_shortname": {
"value": "def"
},
"applicationinsights_project": {
"value": "ghi"
},
"applicationinsights_environment": {
"value": "ijk"
},
"applicationinsights_uniqueid": {
"value": "1"
},
"applicationinsights_componentKind": {
"value": "web"
},
"applicationinsights_metricName": {
"value": "availabilityResults/availabilityPercentage"
},
"applicationinsights_operator": {
"value": "GreaterThan"
},
"applicationinsights_threshold": {
"value": "80"
},
"applicationinsights_windowSize": {
"value": "PT5M"
},
"applicationinsights_timeAggregation": {
"value": "Average"
},
"applicationinsights_alertDescription": {
"value": "New metric alert created via template"
},
"applicationinsights_alertSeverity": {
"value": 3
},
"applicationinsights_isEnabled": {
"value": true
}
}
}
我遇到错误-
"Code": "BadRequest", "Message": "Arm resource
/subscriptions/xxxx/resourceGroups/abc-def-ghi-jkl/providers/Microsoft.Insights/actionGroups/abc
is invalid."
我的资源组已经存在,我正在使用 Az Cli(版本 2.0.64)和以下命令来创建资源-
az group deployment create --name 'test' --resource-group 'abc-def-ghi-jkl' --template-file azuredeploy.json --parameters azuredeploy.parameter.json --verbose --debug
但是,当我在模板中硬编码该部分时,会提供资源-
"actions": [
{
"actionGroupId": "/subscriptions/xxxxxxxx/resourceGroups/abc-def-ghi-jkl/providers/Microsoft.Insights/actionGroups/test0"
}
]
我不知道为什么在我对其进行参数化时会抛出错误。
我从这里参考了 ARM 模板 -
https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/2018-03-01/metricalerts
提前感谢您的help/suggestions。
您的 ARM 模板中似乎有错字。
您写道:
"actions": [
{
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_platform'))]"
}
但是查看您的参数,您可能打算使用 applicationinsights_actionGroupId
而不是 applicationinsights_platform
作为操作组名称。
像这样:
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_actionGroupId'))]"
作为建议,您还可以在 ARM 模板中创建操作组(see here for the documentation),然后使用 resourceId
参考设置操作组 ID:
"actionGroupId": "[resourceId('Microsoft.Insights/actionGroups',parameters('applicationinsights_actionGroupId'))]"
希望这对您有所帮助,
阿萨夫
后来才明白,需要先添加action group,然后才能链接到其他资源。所以我添加了另一个资源 actiongroup
然后我就能够毫无问题地创建应用程序洞察力。是的,您唯一需要注意的是 AG 简称不应超过 12 个字符。
这是ARM模板-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_location_shortname": {
"defaultValue": "",
"type": "string",
"maxLength": 3
},
"applicationinsights_project": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_environment": {
"defaultValue": "",
"type": "string",
"maxLength": 7
},
"applicationinsights_uniqueid": {
"defaultValue": "1",
"type": "string",
"maxLength": 1
},
"applicationinsights_componentKind": {
"type": "string",
"allowedValues": [
"web",
"ios",
"other",
"store",
"java",
"phone"
],
"defaultValue": "web",
"metadata": {
"description": "application insights component kind"
}
},
"applicationinsights_alertSeverity": {
"type": "int",
"defaultValue": 3,
"allowedValues": [
0,
1,
2,
3,
4
],
"metadata": {
"description": "Severity of alert {0,1,2,3,4}"
}
},
"applicationinsights_metricName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Name of the metric used in the comparison to activate the alert."
}
},
"applicationinsights_operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"Equals",
"NotEquals",
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
}
},
"applicationinsights_threshold": {
"type": "string",
"defaultValue": "0",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
},
"applicationinsights_timeAggregation": {
"type": "string",
"defaultValue": "Average",
"allowedValues": [
"Average",
"Minimum",
"Maximum",
"Total",
"Count"
],
"metadata": {
"description": "How the data that is collected should be combined over time."
}
},
"applicationinsights_windowSize": {
"type": "string",
"defaultValue": "PT5M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H",
"PT6H",
"PT12H",
"PT24H"
],
"metadata": {
"description": "Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format."
}
},
"evaluationFrequency": {
"type": "string",
"defaultValue": "PT1M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H"
],
"metadata": {
"description": "how often the metric alert is evaluated represented in ISO 8601 duration format"
}
},
"applicationinsights_instrumentation_key_output": {
"defaultValue": "ApplicationInsightsInstrumentationKey",
"type": "string"
},
"applicationinsights_actionGroupId": {
"type": "string",
"defaultValue": "test",
"metadata": {
"description": "The ID of the action group that is triggered when the alert is activated or deactivated"
}
},
"applicationinsights_recieverEmailId": {
"type": "string",
"defaultValue": "atf@whosebug.com",
"metadata": {
"description": "Email Address of Receiver"
}
},
"applicationinsights_webhookURI": {
"type": "string",
"defaultValue": "http://requestb.in/1bq62iu2",
"metadata": {
"description": "Webhook receiver service URI"
}
}
},
"variables": {
"basename": "[concat(parameters('applicationinsights_platform'), '-', parameters('applicationinsights_project'), '-', parameters('applicationinsights_location_shortname'), '-', parameters('applicationinsights_environment'))]",
"alertRulesName": "[concat(variables('basename'), '-aiar-', parameters('applicationinsights_uniqueid'))]",
"appInsightName": "[concat(variables('basename'), '-aic-', parameters('applicationinsights_uniqueid'))]",
"AGName": "[concat(parameters('applicationinsights_platform'), parameters('applicationinsights_project'), parameters('applicationinsights_location_shortname'), parameters('applicationinsights_environment'))]",
"AGId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'),'/providers/Microsoft.Insights/actionGroups/',variables('AGName'))]"
},
"resources": [
{
"type": "Microsoft.Insights/actionGroups",
"apiVersion": "2018-03-01",
"name": "[variables('AGName')]",
"location": "Global",
"properties": {
"groupShortName": "[variables('AGName')]",
"enabled": true,
"emailReceivers": [
{
"name": "EmailOfRecipient",
"emailAddress": "[parameters('applicationinsights_recieverEmailId')]"
}
],
"webhookReceivers": [
{
"name": "WebhookURI",
"serviceUri": "[parameters('applicationinsights_webhookURI')]"
}
]
}
},
{
"name": "[variables('alertRulesName')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsightName')))]": "Resource"
},
"properties": {
"name": "[variables('alertRulesName')]",
"description": "Alert rule assigned to Application Insight component",
"severity": "[parameters('applicationinsights_alertSeverity')]",
"enabled": true,
"scopes": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]"
],
"evaluationFrequency": "[parameters('evaluationFrequency')]",
"windowSize": "[parameters('applicationinsights_windowSize')]",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "[variables('AGName')]",
"metricName": "[parameters('applicationinsights_metricName')]",
"dimensions": [],
"operator": "[parameters('applicationinsights_operator')]",
"threshold": "[parameters('applicationinsights_threshold')]",
"timeAggregation": "[parameters('applicationinsights_timeAggregation')]"
}
]
},
"actions": [
{
"actionGroupId": "[variables('AGId')]"
}
]
},
"dependsOn": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]",
"[resourceId('microsoft.insights/actionGroups', variables('AGName'))]"
]
},
{
"name": "[variables('appInsightName')]",
"type": "microsoft.insights/components",
"apiVersion": "2015-05-01",
"location": "[resourceGroup().location]",
"tags": {},
"kind": "[parameters('applicationinsights_componentKind')]",
"properties": {
"ApplicationId": "[variables('appInsightName')]"
}
}
],
"outputs": {
"secrets": {
"type": "object",
"value": {
"[parameters('applicationinsights_instrumentation_key_output')]": "[reference(concat('microsoft.insights/components/', variables('appInsightName'))).InstrumentationKey]"
}
}
}
}
和我的参数文件-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"value": "foo"
},
"applicationinsights_location_shortname": {
"value": "eus"
},
"applicationinsights_project": {
"value": "bar"
},
"applicationinsights_environment": {
"value": "dev"
},
"applicationinsights_uniqueid": {
"value": "1"
},
"applicationinsights_componentKind": {
"value": "web"
},
"applicationinsights_metricName": {
"value": "requests/duration"
},
"applicationinsights_operator": {
"value": "GreaterThan"
},
"applicationinsights_threshold": {
"value": "10000"
},
"applicationinsights_windowSize": {
"value": "PT5M"
},
"applicationinsights_timeAggregation": {
"value": "Average"
},
"applicationinsights_alertSeverity": {
"value": 3
},
"applicationinsights_recieverEmailId": {
"value": "atf@stackoverfow.com"
},
"applicationinsights_webhookURI": {
"value": "https://requestb.in/1bq62iu2"
}
}
}
我正在使用新的指标规则创建应用程序见解。 我之前使用的是经典警报,并且在 2019 年 9 月 1 日之前工作正常。我想采用新警报,所以我正在修改下面的 arm 模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_location_shortname": {
"defaultValue": "",
"type": "string",
"maxLength": 3
},
"applicationinsights_project": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_environment": {
"defaultValue": "",
"type": "string",
"maxLength": 7
},
"applicationinsights_uniqueid": {
"defaultValue": "1",
"type": "string",
"maxLength": 1
},
"applicationinsights_componentKind": {
"type": "string",
"allowedValues": [
"web",
"ios",
"other",
"store",
"java",
"phone"
],
"defaultValue": "web",
"metadata": {
"description": "application insights component kind"
}
},
"applicationinsights_alertDescription": {
"type": "string",
"defaultValue": "This is a metric alert",
"metadata": {
"description": "Description of alert"
}
},
"applicationinsights_alertSeverity": {
"type": "int",
"defaultValue": 3,
"allowedValues": [
0,
1,
2,
3,
4
],
"metadata": {
"description": "Severity of alert {0,1,2,3,4}"
}
},
"applicationinsights_isEnabled": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Specifies whether the alert is enabled"
}
},
"applicationinsights_metricName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Name of the metric used in the comparison to activate the alert."
}
},
"applicationinsights_operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"Equals",
"NotEquals",
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
}
},
"applicationinsights_threshold": {
"type": "string",
"defaultValue": "0",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
},
"applicationinsights_timeAggregation": {
"type": "string",
"defaultValue": "Average",
"allowedValues": [
"Average",
"Minimum",
"Maximum",
"Total",
"Count"
],
"metadata": {
"description": "How the data that is collected should be combined over time."
}
},
"applicationinsights_windowSize": {
"type": "string",
"defaultValue": "PT5M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H",
"PT6H",
"PT12H",
"PT24H"
],
"metadata": {
"description": "Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format."
}
},
"evaluationFrequency": {
"type": "string",
"defaultValue": "PT1M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H"
],
"metadata": {
"description": "how often the metric alert is evaluated represented in ISO 8601 duration format"
}
},
"applicationinsights_instrumentation_key_output": {
"defaultValue": "ApplicationInsightsInstrumentationKey",
"type": "string"
},
"applicationinsights_actionGroupId": {
"type": "string",
"defaultValue": "test",
"metadata": {
"description": "The ID of the action group that is triggered when the alert is activated or deactivated"
}
}
},
"variables": {
"basename": "[concat(parameters('applicationinsights_platform'), '-', parameters('applicationinsights_project'), '-', parameters('applicationinsights_location_shortname'), '-', parameters('applicationinsights_environment'))]",
"alertRulesName": "[concat(variables('basename'), '-aaiar-', parameters('applicationinsights_uniqueid'))]",
"appInsightName": "[concat(variables('basename'), '-aaic-', parameters('applicationinsights_uniqueid'))]"
},
"resources": [
{
"name": "[variables('alertRulesName')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsightName')))]": "Resource"
},
"properties": {
"name": "[variables('alertRulesName')]",
"description": "Alert rule assigned to Application Insight component",
"severity": "[parameters('applicationinsights_alertSeverity')]",
"enabled": "[parameters('applicationinsights_isEnabled')]",
"scopes": ["[resourceId('microsoft.insights/components', variables('appInsightName'))]"],
"evaluationFrequency":"[parameters('evaluationFrequency')]",
"windowSize": "[parameters('applicationinsights_windowSize')]",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name" : "test01",
"metricName": "[parameters('applicationinsights_metricName')]",
"dimensions":[],
"operator": "[parameters('applicationinsights_operator')]",
"threshold" : "[parameters('applicationinsights_threshold')]",
"timeAggregation": "[parameters('applicationinsights_timeAggregation')]"
}
]
},
"actions": [
{
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_platform'))]"
}
]
},
"dependsOn": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]"
]
},
{
"name": "[variables('appInsightName')]",
"type": "microsoft.insights/components",
"apiVersion": "2015-05-01",
"location": "[resourceGroup().location]",
"tags": {},
"kind": "[parameters('applicationinsights_componentKind')]",
"properties": {
"ApplicationId": "[variables('appInsightName')]"
}}
],
"outputs": {
"secrets": {
"type": "object",
"value": {
"[parameters('applicationinsights_instrumentation_key_output')]": "[reference(concat('microsoft.insights/components/', variables('appInsightName'))).InstrumentationKey]"
}
}
}
}
我的参数文件是-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"value": "abc"
},
"applicationinsights_location_shortname": {
"value": "def"
},
"applicationinsights_project": {
"value": "ghi"
},
"applicationinsights_environment": {
"value": "ijk"
},
"applicationinsights_uniqueid": {
"value": "1"
},
"applicationinsights_componentKind": {
"value": "web"
},
"applicationinsights_metricName": {
"value": "availabilityResults/availabilityPercentage"
},
"applicationinsights_operator": {
"value": "GreaterThan"
},
"applicationinsights_threshold": {
"value": "80"
},
"applicationinsights_windowSize": {
"value": "PT5M"
},
"applicationinsights_timeAggregation": {
"value": "Average"
},
"applicationinsights_alertDescription": {
"value": "New metric alert created via template"
},
"applicationinsights_alertSeverity": {
"value": 3
},
"applicationinsights_isEnabled": {
"value": true
}
}
}
我遇到错误-
"Code": "BadRequest", "Message": "Arm resource /subscriptions/xxxx/resourceGroups/abc-def-ghi-jkl/providers/Microsoft.Insights/actionGroups/abc is invalid."
我的资源组已经存在,我正在使用 Az Cli(版本 2.0.64)和以下命令来创建资源-
az group deployment create --name 'test' --resource-group 'abc-def-ghi-jkl' --template-file azuredeploy.json --parameters azuredeploy.parameter.json --verbose --debug
但是,当我在模板中硬编码该部分时,会提供资源-
"actions": [
{
"actionGroupId": "/subscriptions/xxxxxxxx/resourceGroups/abc-def-ghi-jkl/providers/Microsoft.Insights/actionGroups/test0"
}
]
我不知道为什么在我对其进行参数化时会抛出错误。 我从这里参考了 ARM 模板 - https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/2018-03-01/metricalerts
提前感谢您的help/suggestions。
您的 ARM 模板中似乎有错字。 您写道:
"actions": [
{
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_platform'))]"
}
但是查看您的参数,您可能打算使用 applicationinsights_actionGroupId
而不是 applicationinsights_platform
作为操作组名称。
像这样:
"actionGroupId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'), '/providers/Microsoft.Insights/actionGroups/',parameters('applicationinsights_actionGroupId'))]"
作为建议,您还可以在 ARM 模板中创建操作组(see here for the documentation),然后使用 resourceId
参考设置操作组 ID:
"actionGroupId": "[resourceId('Microsoft.Insights/actionGroups',parameters('applicationinsights_actionGroupId'))]"
希望这对您有所帮助,
阿萨夫
后来才明白,需要先添加action group,然后才能链接到其他资源。所以我添加了另一个资源 actiongroup
然后我就能够毫无问题地创建应用程序洞察力。是的,您唯一需要注意的是 AG 简称不应超过 12 个字符。
这是ARM模板-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_location_shortname": {
"defaultValue": "",
"type": "string",
"maxLength": 3
},
"applicationinsights_project": {
"defaultValue": "",
"type": "string",
"maxLength": 6
},
"applicationinsights_environment": {
"defaultValue": "",
"type": "string",
"maxLength": 7
},
"applicationinsights_uniqueid": {
"defaultValue": "1",
"type": "string",
"maxLength": 1
},
"applicationinsights_componentKind": {
"type": "string",
"allowedValues": [
"web",
"ios",
"other",
"store",
"java",
"phone"
],
"defaultValue": "web",
"metadata": {
"description": "application insights component kind"
}
},
"applicationinsights_alertSeverity": {
"type": "int",
"defaultValue": 3,
"allowedValues": [
0,
1,
2,
3,
4
],
"metadata": {
"description": "Severity of alert {0,1,2,3,4}"
}
},
"applicationinsights_metricName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Name of the metric used in the comparison to activate the alert."
}
},
"applicationinsights_operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"Equals",
"NotEquals",
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
}
},
"applicationinsights_threshold": {
"type": "string",
"defaultValue": "0",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
},
"applicationinsights_timeAggregation": {
"type": "string",
"defaultValue": "Average",
"allowedValues": [
"Average",
"Minimum",
"Maximum",
"Total",
"Count"
],
"metadata": {
"description": "How the data that is collected should be combined over time."
}
},
"applicationinsights_windowSize": {
"type": "string",
"defaultValue": "PT5M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H",
"PT6H",
"PT12H",
"PT24H"
],
"metadata": {
"description": "Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format."
}
},
"evaluationFrequency": {
"type": "string",
"defaultValue": "PT1M",
"allowedValues": [
"PT1M",
"PT5M",
"PT15M",
"PT30M",
"PT1H"
],
"metadata": {
"description": "how often the metric alert is evaluated represented in ISO 8601 duration format"
}
},
"applicationinsights_instrumentation_key_output": {
"defaultValue": "ApplicationInsightsInstrumentationKey",
"type": "string"
},
"applicationinsights_actionGroupId": {
"type": "string",
"defaultValue": "test",
"metadata": {
"description": "The ID of the action group that is triggered when the alert is activated or deactivated"
}
},
"applicationinsights_recieverEmailId": {
"type": "string",
"defaultValue": "atf@whosebug.com",
"metadata": {
"description": "Email Address of Receiver"
}
},
"applicationinsights_webhookURI": {
"type": "string",
"defaultValue": "http://requestb.in/1bq62iu2",
"metadata": {
"description": "Webhook receiver service URI"
}
}
},
"variables": {
"basename": "[concat(parameters('applicationinsights_platform'), '-', parameters('applicationinsights_project'), '-', parameters('applicationinsights_location_shortname'), '-', parameters('applicationinsights_environment'))]",
"alertRulesName": "[concat(variables('basename'), '-aiar-', parameters('applicationinsights_uniqueid'))]",
"appInsightName": "[concat(variables('basename'), '-aic-', parameters('applicationinsights_uniqueid'))]",
"AGName": "[concat(parameters('applicationinsights_platform'), parameters('applicationinsights_project'), parameters('applicationinsights_location_shortname'), parameters('applicationinsights_environment'))]",
"AGId": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('basename'),'/providers/Microsoft.Insights/actionGroups/',variables('AGName'))]"
},
"resources": [
{
"type": "Microsoft.Insights/actionGroups",
"apiVersion": "2018-03-01",
"name": "[variables('AGName')]",
"location": "Global",
"properties": {
"groupShortName": "[variables('AGName')]",
"enabled": true,
"emailReceivers": [
{
"name": "EmailOfRecipient",
"emailAddress": "[parameters('applicationinsights_recieverEmailId')]"
}
],
"webhookReceivers": [
{
"name": "WebhookURI",
"serviceUri": "[parameters('applicationinsights_webhookURI')]"
}
]
}
},
{
"name": "[variables('alertRulesName')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsightName')))]": "Resource"
},
"properties": {
"name": "[variables('alertRulesName')]",
"description": "Alert rule assigned to Application Insight component",
"severity": "[parameters('applicationinsights_alertSeverity')]",
"enabled": true,
"scopes": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]"
],
"evaluationFrequency": "[parameters('evaluationFrequency')]",
"windowSize": "[parameters('applicationinsights_windowSize')]",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "[variables('AGName')]",
"metricName": "[parameters('applicationinsights_metricName')]",
"dimensions": [],
"operator": "[parameters('applicationinsights_operator')]",
"threshold": "[parameters('applicationinsights_threshold')]",
"timeAggregation": "[parameters('applicationinsights_timeAggregation')]"
}
]
},
"actions": [
{
"actionGroupId": "[variables('AGId')]"
}
]
},
"dependsOn": [
"[resourceId('microsoft.insights/components', variables('appInsightName'))]",
"[resourceId('microsoft.insights/actionGroups', variables('AGName'))]"
]
},
{
"name": "[variables('appInsightName')]",
"type": "microsoft.insights/components",
"apiVersion": "2015-05-01",
"location": "[resourceGroup().location]",
"tags": {},
"kind": "[parameters('applicationinsights_componentKind')]",
"properties": {
"ApplicationId": "[variables('appInsightName')]"
}
}
],
"outputs": {
"secrets": {
"type": "object",
"value": {
"[parameters('applicationinsights_instrumentation_key_output')]": "[reference(concat('microsoft.insights/components/', variables('appInsightName'))).InstrumentationKey]"
}
}
}
}
和我的参数文件-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"applicationinsights_platform": {
"value": "foo"
},
"applicationinsights_location_shortname": {
"value": "eus"
},
"applicationinsights_project": {
"value": "bar"
},
"applicationinsights_environment": {
"value": "dev"
},
"applicationinsights_uniqueid": {
"value": "1"
},
"applicationinsights_componentKind": {
"value": "web"
},
"applicationinsights_metricName": {
"value": "requests/duration"
},
"applicationinsights_operator": {
"value": "GreaterThan"
},
"applicationinsights_threshold": {
"value": "10000"
},
"applicationinsights_windowSize": {
"value": "PT5M"
},
"applicationinsights_timeAggregation": {
"value": "Average"
},
"applicationinsights_alertSeverity": {
"value": 3
},
"applicationinsights_recieverEmailId": {
"value": "atf@stackoverfow.com"
},
"applicationinsights_webhookURI": {
"value": "https://requestb.in/1bq62iu2"
}
}
}