0

我一直在尝试学习 ARM,但我一直陷入同样的​​错误,我在网上找不到太多关于 ARM 的信息,所以我真的不明白自己做错了什么,有人可以在这里帮助我并告诉我我做错了什么以及如何解决?

这是我的错误

Template deployment returned the following errors:
11:05:16 - 11:05:15 - Resource Microsoft.Insights/alertRules 'cpu_percent' failed with message '{
11:05:16 -   "code": "TargetResourceNotFound",
11:05:16 -   "message": "Exception of type 'Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException' was thrown."
11:05:16 - Deploying template using PowerShell script failed.
11:05:16 - Tell us about your experience at https://go.microsoft.com/fwlink/?LinkId=691202
11:05:16 - }'
11:05:16 - 11:05:15 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
11:05:16 - 11:05:15 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
11:05:16 - 
11:05:16 -

这是我的代码

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sendToServiceOwners": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
            "description": "Specifies if alerts are sent to service owners"
      }
    },
    "windowSize": {
      "type": "string",
      "defaultValue": "00:05:00",
      "metadata": {
            "description": "Period of time to monitor for"
      }
    },
    "aggregation": {
      "type": "string",
      "defaultValue": "Average",
      "allowedValues": [
        "Average",
        "Last",
        "Maximum",
        "Minimum",
        "Total"
      ],
      "metadata": {
            "description": "The way collected data should be compared"  
      }
    },
    "threshold": {
      "type": "string",
      "defaultValue": "80",
      "metadata": {
            "description":  "The treshold value at which the alert will trigger"
      }
    },
    "operator": {
      "type": "string",
      "defaultValue": "GreaterThan",
      "allowedValues": [
        "GreaterThan",
        "GreaterThanOrEqual",
        "LessThan",
        "LessThanOrEqual"
      ],
      "metadata": {
            "description": "Different sorts of operators for comparing the value"
      }
    },
    "metricName": {
      "type": "string",
      "defaultValue": "cpu_percent",
      "metadata": {
            "description": "Name of the specific Metric"
      }
    },
    "resourceId": {
      "type": "string",
      "defaultValue": "[resourceId('Microsoft.Sql/servers', parameters('serverName'))]",
      "metadata": {
            "description": "Resource ID"
      }
    },
    "isEnabled": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
            "description": "Specifying if alert is enabled"
      }
    },
    "alertDescription": {
      "type": "string",
      "defaultValue": "Alert used for Checking CPU for 80% Spikes"
    },
    "alertName": {
      "type": "string",
      "defaultValue": "cpu_percent"
    },
    "ugentecdbtestName": {
      "type": "string",
      "minLength": 1
    },
    "serverNameAdminLogin": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "*********"
    },
    "serverNameAdminLoginPassword": {
      "defaultValue": ********,
      "minLength": 1,
      "type": "securestring"
    },
    "ugentecdbtestCollation": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "SQL_Latin1_General_CP1_CI_AS"
    },
    "ugentecdbtestEdition": {
      "type": "string",
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ]
    },
    "ugentecdbtestRequestedServiceObjectiveName": {
      "type": "string",
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "S0",
        "S1",
        "S2",
        "P1",
        "P2",
        "P3"
      ],
      "metadata": {
        "description": "Describes the performance level for Edition"
      }
    },
    "serverName": {
      "type": "string",
      "defaultValue": "ugentecserver"
    }
  },
  "variables": {
  },
  "resources": [
    {
      "name": "[parameters('serverName')]",
      "type": "Microsoft.Sql/servers",
      "location": "West Europe",
      "apiVersion": "2014-04-01-preview",
      "properties": {
        "administratorLogin": "[parameters('serverNameAdminLogin')]",
        "administratorLoginPassword": "[parameters('serverNameAdminLoginPassword')]",
        "version": "12.0"
      }
    },
    {
          "name": "[concat(parameters('serverName'), '/', parameters('ugentecdbtestName'))]",
          "type": "Microsoft.Sql/servers/databases",
          "location": "westeurope",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [ "[resourceId('Microsoft.Sql/servers', parameters('serverName'))]" ],
          "properties": {
            "collation": "[parameters('ugentecdbtestCollation')]",
            "edition": "[parameters('ugentecdbtestEdition')]",
            "maxSizeBytes": "1073741824",
            "requestedServiceObjectiveName": "[parameters('ugentecdbtestRequestedServiceObjectiveName')]"
          }
     },
    {
      "type": "Microsoft.Insights/alertRules",
      "name": "[parameters('alertName')]",
      "dependsOn": ["[resourceId('Microsoft.Sql/servers/databases', parameters('serverName'),parameters('ugentecdbtestName'))]"],
      "location": "West Europe",
      "apiVersion": "2016-03-01",
      "properties": {
        "name": "[parameters('alertName')]",
        "description": "[parameters('alertDescription')]",
        "isEnabled": "[parameters('isEnabled')]",
        "condition": {
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
          "dataSource": {
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
            "resourceUri": "[parameters('resourceId')]",
            "metricName": "[parameters('metricName')]",
            "operator": "[parameters('aggregation')]"
          },
          "threshold": "[parameters('threshold')]",
          "windowSize": "[parameters('windowSize')]",
          "timeAggregation": "[parameters('aggregation')]"
        },
        "actions": [
          {
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
            "sendToServiceOwners": "[parameters('sendToServiceOwners')]"
          }
        ]
      }
    }
   ],
  "outputs": {
    "testOutput": {
      "type": "string",
      "value": "test123"
    },
    "DbAdoConnString": {
      "type": "string",
      "value": "[concat('Server=tcp:',reference(parameters('serverName')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('ugentecdbtestName'),';Persist Security Info=False;User ID=',reference(parameters('serverName')).administratorLogin,';Password=',reference(parameters('serverName')).administratorLoginPassword,';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
    }

  }
    }
4

2 回答 2

1

如果我猜出了什么问题,那就是参数'resourceId':

"resourceUri": "[parameters('resourceId')]",

将其更改为:

"resourceUri":  "[resourceId('Microsoft.Sql/servers', parameters('serverName'))]",

在服务器级别设置它

于 2017-02-07T12:45:09.357 回答
0

我已经修复了几个问题,并根据上述问题中的原始 ARM 模板进行了一些重构,并在 Azure 门户的模板部署中进行了测试。

注意:需要更新必要参数的值,例如serverNameAdminLoginserverNameAdminLoginPassword

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sendToServiceOwners": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Specifies if alerts are sent to service owners"
      }
    },
    "windowSize": {
      "type": "string",
      "defaultValue": "00:05:00",
      "metadata": {
        "description": "Period of time to monitor for"
      }
    },
    "aggregation": {
      "type": "string",
      "defaultValue": "Average",
      "allowedValues": [
        "Average",
        "Last",
        "Maximum",
        "Minimum",
        "Total"
      ],
      "metadata": {
        "description": "The way collected data should be compared"
      }
    },
    "threshold": {
      "type": "string",
      "defaultValue": "80",
      "metadata": {
        "description": "The treshold value at which the alert will trigger"
      }
    },
    "operator": {
      "type": "string",
      "defaultValue": "GreaterThan",
      "allowedValues": [
        "GreaterThan",
        "GreaterThanOrEqual",
        "LessThan",
        "LessThanOrEqual"
      ],
      "metadata": {
        "description": "Different sorts of operators for comparing the value"
      }
    },
    "metricName": {
      "type": "string",
      "defaultValue": "cpu_percent",
      "metadata": {
        "description": "Name of the specific Metric"
      }
    },
    "isEnabled": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Specifying if alert is enabled"
      }
    },
    "alertDescription": {
      "type": "string",
      "defaultValue": "Alert used for Checking CPU for 80% Spikes"
    },
    "alertName": {
      "type": "string",
      "defaultValue": "cpu_percent"
    },
    "ugentecdbtestName": {
      "type": "string",
      "minLength": 1
    },
    "serverNameAdminLogin": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "**********"
    },
    "serverNameAdminLoginPassword": {
      "defaultValue": "**********",
      "minLength": 1,
      "type": "securestring"
    },
    "ugentecdbtestCollation": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "SQL_Latin1_General_CP1_CI_AS"
    },
    "ugentecdbtestEdition": {
      "type": "string",
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ]
    },
    "ugentecdbtestRequestedServiceObjectiveName": {
      "type": "string",
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "S0",
        "S1",
        "S2",
        "P1",
        "P2",
        "P3"
      ],
      "metadata": {
        "description": "Describes the performance level for Edition"
      }
    },
    "serverName": {
      "type": "string",
      "defaultValue": "ugentecserver"
    }
  },
  "variables": {
  },
  "resources": [
    {
      "name": "[parameters('serverName')]",
      "type": "Microsoft.Sql/servers",
      "location": "West Europe",
      "apiVersion": "2014-04-01-preview",
      "properties": {
        "administratorLogin": "[parameters('serverNameAdminLogin')]",
        "administratorLoginPassword": "[parameters('serverNameAdminLoginPassword')]",
        "version": "12.0"
      },
      "resources": [
        {
          "name": "[parameters('ugentecdbtestName')]",
          "type": "databases",
          "location": "westeurope",
          "apiVersion": "2015-05-01-preview",
          "dependsOn": [ "[resourceId('Microsoft.Sql/servers', parameters('serverName'))]" ],
          "properties": {
            "collation": "[parameters('ugentecdbtestCollation')]",
            "edition": "[parameters('ugentecdbtestEdition')]",
            "maxSizeBytes": "1073741824",
            "requestedServiceObjectiveName": "[parameters('ugentecdbtestRequestedServiceObjectiveName')]"
          }
        }
      ]
    },
    {
      "type": "Microsoft.Insights/alertRules",
      "name": "[parameters('alertName')]",
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', parameters('serverName'))]",
        "[resourceId('Microsoft.Sql/servers/databases', parameters('serverName'),parameters('ugentecdbtestName'))]"
      ],
      "location": "West Europe",
      "apiVersion": "2016-03-01",
      "properties": {
        "name": "[parameters('alertName')]",
        "description": "[parameters('alertDescription')]",
        "isEnabled": "[parameters('isEnabled')]",
        "condition": {
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
          "dataSource": {
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
            "resourceUri": "[resourceId('Microsoft.Sql/servers/databases', parameters('serverName'),parameters('ugentecdbtestName'))]",
            "metricName": "[parameters('metricName')]",
            "operator": "[parameters('aggregation')]"
          },
          "threshold": "[parameters('threshold')]",
          "windowSize": "[parameters('windowSize')]",
          "timeAggregation": "[parameters('aggregation')]"
        },
        "actions": [
          {
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
            "sendToServiceOwners": "[parameters('sendToServiceOwners')]"
          }
        ]
      }
    }
  ],
  "outputs": {
    "DbAdoConnString": {
      "type": "string",
      "value": "[concat('Server=tcp:',reference(parameters('serverName')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('ugentecdbtestName'),';Persist Security Info=False;User ID=',reference(parameters('serverName')).administratorLogin,';Password=',reference(parameters('serverName')).administratorLoginPassword,';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
    }
  }
}

在此处输入图像描述

在此处输入图像描述

于 2017-02-07T14:32:25.393 回答