azure - 由于“actionGroupId”,Azure 应用洞察(带有新的警报指标)部署失败
问题描述
我正在使用新的度量规则创建应用程序洞察力。我之前使用的是经典警报,并且在 2019 年 9 月 1 日之前工作正常。我想采用新警报,所以我在下面修改我的手臂模板:
{
"$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
}
}
}
我收到错误-
“代码”:“BadRequest”,“消息”:“Arm 资源 /subscriptions/xxxx/resourceGroups/abc-def-ghi-jkl/providers/Microsoft.Insights/actionGroups/abc 无效。”
我的资源组已经存在,我正在使用 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
提前感谢您的帮助/建议。
解决方案
后来我才明白,首先需要添加操作组,然后才能将其链接到其他资源。所以我添加了另一个资源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@stackoverflow.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"
}
}
}
推荐阅读
- python-3.x - 如何从地理数据中获取城市
- docusignapi - Docusign 请求授权码相关查询
- laravel - 如何过滤laravel中的特定记录?
- javascript - 规范化后如何保留键索引对象的项目顺序(来自服务器)?
- css - 如何使用 React 组件避免 z-index 错误
- caching - 有没有办法在 NativeScript Angular 应用程序中禁用 WebView(iOS 和 Andriod)中的所有缓存?
- autodesk-forge - Autodesk forge viewer.js 从 6.6 更新到 7.1 findPropertyDbPath 返回 null
- reactjs - 在 React 中分离 axios api
- arrays - one-hot 编码问题
- python - 解决“从数据帧复制切片”的问题