2017-02-07 28 views
0

Я пытался узнать ARM, но я все время застреваю на той же ошибке, и я не могу найти много в ARM в сети, поэтому я действительно не понимаю, что я делаю неправильно, может кто-то помочь мне здесь и сказать мне, что я делаю неправильно, и как это исправить?ARM template alertRules Ошибка: TargetResourceNotFound

Вот моя ошибка

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;')]" 
    } 

    } 
    } 

ответ

1

Если бы я догадываюсь, что происходит неправильно, то параметр 'RESOURCEID':

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

Измените это на:

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

, чтобы установить его на уровне сервера

+0

Этот ответ не совсем корректно, так как установить его на сервер БД уровень не будет работать – juvchan

+0

@juvchan thx для вашего комментария, обновил ответ. – Peter

0

Я исправил несколько вопросов, и сделал некоторые рефакторинга на основе исходного шаблона ARM в вышеуказанном вопросе и протестированные работы в развертывании шаблона Azure портала.

Примечание: Необходимо обновить значения необходимых Params, таких как serverNameAdminLogin и serverNameAdminLoginPassword т.д.

{ 
    "$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;')]" 
    } 
    } 
} 

enter image description here

enter image description here

 Смежные вопросы

  • Нет связанных вопросов^_^