Resource Manager - JSON having multiple alerts fails - azure

I use below JSON to create AI alert, which works fine. However when I try to add add multiple alerts in this JSON file, it creates few alerts, sometimes one and other times two or three and finally returns provisioning state as Failed. It never creates all the alerts in the JSON (six).
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"AlertName": {
"type": "string"
},
"Location": {
"type": "string",
"defaultValue": "East US"
},
"ResourceGroup": {
"type": "string"
},
"ResourceName": {
"type": "string"
}
},
"resources": [{
"apiVersion": "2014-04-01",
"name": "[parameters('AlertName')]",
"type": "microsoft.insights/alertrules",
"location": "[parameters('Location')]",
"tags": {
"displayName": "AppInsightsAlert"
},
"properties": {
"name": "[concat('AppInsightsAlert ', parameters('AlertName'))]",
"description": "[concat('App Insights Alert ', parameters('AlertName'))]",
"isEnabled": true,
"condition": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[concat('/subscriptions/<subscription id>/resourcegroups/', parameters('ResourceGroup'), '/providers/microsoft.insights/components/', parameters('ResourceName'))]",
"metricName": "view.count"
},
"threshold": 1,
"windowSize": "PT5M"
},
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": true,
"customEmails": []
}
}
}]
}

Are you using PowerShell for deployment - if so, add the -debug switch to the New-AzureResourceGroup* command and sift through the output. The raw error from the platform is in there and it's usually pretty good. If that doesn't help, can you post the entire json template for the deployments that are failing?

Related

Combining 2 ARM templates ( Action Group and Budget Alert)

I am having a bit of an issue in combining two ARM templates. I want to create an Action Group and then subsequently create an Azure budget alert. I am able to do them individually but I want to create a single Arm template to achieve the task.
Works Fine -Here is the code to create Action Group (Getting the Option to select Resource Group or create one)
{
"type": "microsoft.insights/actionGroups",
"apiVersion": "2019-06-01",
"name": "OG",
"location": "Global",
"properties": {
"groupShortName": "OG",
"enabled": true,
"emailReceivers": [
{
"name": "[concat('Test','OG')]",
"emailAddress": "someemailID#xxx.com",
"useCommonAlertSchema": true
}
]
}
Works Fine - Here is the code to create Budget Alert (Getting the option to select Subscription)
"resources": [
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-01",
"name": "[parameters('budgetName')]",
"properties": {
"timePeriod": {
"startDate": "[parameters('startDate')]",
"endDate": "[parameters('endDate')]"
},
"timeGrain": "[parameters('timeGrain')]",
"amount": "[parameters('amount')]",
"category": "Cost",
"notifications": {
"NotificationForExceededBudget1": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('firstThreshold')]",
"contactEmails": "[parameters('contactEmails')]",
"contactGroups": "[parameters('contactGroups')]"
}
}
}
}
]
And here is the combined code that I have come up with - Not Getting the option to select Resource Group
Problem - While deploying the combined template I am not getting the option to select "Resource Group" I need to have "Resource Group" to create Action Group but not for Budget Alert.
How can I combine the two templates?
Not able to make it work
"resources": [
{
"type": "microsoft.insights/actionGroups",
"apiVersion": "2019-06-01",
"name": "OG",
"location": "Global",
"properties": {
"groupShortName": "OG",
"enabled": true,
"emailReceivers": [
{
"name": "[concat('Test','OG')]",
"emailAddress": "someemailID#xxx.com",
"useCommonAlertSchema": true
}
]
}
},
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-01",
"name": "[parameters('budgetName')]",
"dependsOn": [
"[resourceId('microsoft.insights/actionGroups','OG')]"
],
"properties": {
"timePeriod": {
"startDate": "[parameters('startDate')]",
"endDate": "[parameters('endDate')]"
},
"timeGrain": "[parameters('timeGrain')]",
"amount": "[parameters('amount')]",
"category": "Cost",
"notifications": {
"NotificationForExceededBudget1": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('firstThreshold')]",
"contactEmails": "[parameters('contactEmails')]",
"contactGroups": "[resourceId('microsoft.insights/actionGroups','OG')]"
}
}
}
}
]
Please nested the budget in a nest template and target it to subscription level (or management group level)
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-resource-group?tabs=azure-cli
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
your action group resource
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "nestedDeployment",
"location": "centralus",
"subscriptionId": "0000000-0000-0000-0000-000000000000",
"properties": {
"mode": "Incremental",
"template": {
your budget resource goes here
}
}
}
],
"outputs": {}
}

Azure ARM Deployment what is the hostingEnvironment?

I'm attempting to deploy to a new resource group containing an existing app service plan in Azure using an ARM script. If I run the deployment through the Azure Portal UI, it is successful. The issue happens when I try to download the template ARM script for the deployment and use that.
I'm attempting to create a Web app and associated application insights instance.
Here is my template.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string"
},
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"hostingEnvironment": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"serverFarmResourceGroup": {
"type": "string"
},
"alwaysOn": {
"type": "bool"
},
"currentStack": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2018-02-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"tags": {},
"dependsOn": [
"microsoft.insights/components/LicensingService-API"
],
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference('microsoft.insights/components/LicensingService-API', '2015-05-01').InstrumentationKey]"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "XDT_MicrosoftApplicationInsights_Mode",
"value": "default"
},
{
"name": "DiagnosticServices_EXTENSION_VERSION",
"value": "disabled"
},
{
"name": "APPINSIGHTS_PROFILERFEATURE_VERSION",
"value": "disabled"
},
{
"name": "APPINSIGHTS_SNAPSHOTFEATURE_VERSION",
"value": "disabled"
},
{
"name": "InstrumentationEngine_EXTENSION_VERSION",
"value": "disabled"
},
{
"name": "SnapshotDebugger_EXTENSION_VERSION",
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
"value": "disabled"
}
],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[parameters('currentStack')]"
}
],
"alwaysOn": "[parameters('alwaysOn')]"
},
"serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"hostingEnvironment": "[parameters('hostingEnvironment')]",
"clientAffinityEnabled": true
}
},
{
"apiVersion": "2015-05-01",
"name": "LicensingService-API",
"type": "microsoft.insights/components",
"location": "westus2",
"tags": {},
"properties": {
"ApplicationId": "[parameters('name')]",
"Request_Source": "IbizaWebAppExtensionCreate"
}
}
]
}
And my parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"value": "REMOVED"
},
"name": {
"value": "LicensingService-API"
},
"location": {
"value": "West US 2"
},
"hostingEnvironment": {
"value": ""
},
"hostingPlanName": {
"value": "LicensingServiceProductionAppServicePlan"
},
"serverFarmResourceGroup": {
"value": "LicensingServicePROD"
},
"alwaysOn": {
"value": true
},
"currentStack": {
"value": "dotnetcore"
}
}
}
There is one particular parameter that I'm having issues with. It is the "hostingEnvironment" parameter. I am unable to determine what should be placed in that field, as the default template provided by Azure leaves this blank. If I enter a value here (LicensingServiceProductionAppServicePlan for example), I get an error on the deployment of the web app that reads:
{
"Code": "NotFound",
"Message": "Cannot find Stamp with name LicensingServiceProductionAppServicePlan.",
"Target": null,
"Details": [
{
"Message": "Cannot find Stamp with name LicensingServiceProductionAppServicePlan."
},
{
"Code": "NotFound"
},
{
"ErrorEntity": {
"ExtendedCode": "51004",
"MessageTemplate": "Cannot find {0} with name {1}.",
"Parameters": [
"Stamp",
"LicensingServiceProductionAppServicePlan"
],
"Code": "NotFound",
"Message": "Cannot find Stamp with name LicensingServiceProductionAppServicePlan."
}
}
],
"Innererror": null
}
If I instead remove the parameter from both the template and the parameters files, as suggested in this answer, I get a BadRequest error that reads:
{
"error": {
"code": "InvalidTemplate",
"message": "Unable to process template language expressions for resource '/subscriptions/REMOVED/resourceGroups/LicensingServicePROD/providers/Microsoft.Web/serverfarms/LicensingServicePROD' at line '151' and column '9'. 'The template parameter 'hostingEnvironment' is not found. Please see https://aka.ms/arm-template/#parameters for usage details.'",
"additionalInfo": [
{
"type": "TemplateViolation",
"info": {
"lineNumber": 151,
"linePosition": 9,
"path": ""
}
}
]
}
}
Likely this is because I can see that the "hostingEnvironment" parameter is used in the template script.
So I'm left wondering why this works when done through the Azure UI but not from the script generated from the UI. My final question that I'm looking to solve is what is the value that should be provided for the "hostingEnvironment" parameter?
First hostingEnvironment is not required. It is required if you have an App Service Environment and you want to deploy the site on it.
You can leave it empty the value or remove it from the template.
See the details from the template reference site Web Site template reference
The solution is to make the following changes:
template.json:
"hostingEnvironment": {
"type": "string",
"defaultValue": ""
},
parameters.json
"hostingEnvironment": {
"value": ""
},

Can't see the alerts I created on Azure Portal

I am creating alerts inside Application Insights on the Azure Portal, but for some reason I am not able to see them. I know the alerts are working because I am getting the emails as expected.
Using the management API I am able to see the alerts:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/scheduledQueryRules/{scheduleQueryName}?api-version=2018-04-16
What could be preventing them from appearing on the portal? This is my ARM template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appInsightsName": {
"type": "string"
},
"alertEmail": {
"type": "string"
},
"utilityActionGroup": {
"type": "string"
},
"scheduleQueryName": {
"type": "string"
},
"monitoringUtilityAlertEnabled": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"apiVersion": "2014-04-01",
"name": "[parameters('appInsightsName')]",
"type": "Microsoft.Insights/components",
"location": "[resourceGroup().location]",
"properties": {
"applicationId": "[parameters('appInsightsName')]"
}
},
{
"type": "Microsoft.Insights/actionGroups",
"name": "[parameters('utilityActionGroup')]",
"apiVersion": "2018-03-01",
"location": "Global",
"properties": {
"groupShortName": "Utility",
"enabled": true,
"emailReceivers": [
{
"name": "AlertEmail",
"emailAddress": "[parameters('alertEmail')]"
}
]
},
"dependsOn": []
},
{
"type": "Microsoft.Insights/scheduledQueryRules",
"name": "[parameters('scheduleQueryName')]",
"apiVersion": "2018-04-16",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-link: ', resourceId('Microsoft.Insights/components', parameters('appInsightsName')))]": "Resource"
},
"scale": null,
"properties": {
"description": "Sends an alert when the utility stops sending a trace to app insights",
"enabled": "[parameters('monitoringUtilityAlertEnabled')]",
"source": {
"query": "traces\n| where message == \"Utility Service is alive\" | where timestamp >= ago(30m) ",
"authorizedResources": [],
"dataSourceId": "[resourceId('microsoft.insights/components', parameters('appInsightsName'))]",
"queryType": "ResultCount"
},
"schedule": {
"frequencyInMinutes": 5,
"timeWindowInMinutes": 5
},
"action": {
"odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction",
"severity": "2",
"aznsAction": {
"actionGroup": [ "[resourceId('microsoft.insights/actionGroups', parameters('utilityActionGroup'))]" ],
"emailSubject": "Monitoring Utility Stopped working"
},
"trigger": {
"thresholdOperator": "Equal",
"threshold": 0
}
}
},
"dependsOn": [
"[resourceId('microsoft.insights/components', parameters('appInsightsName'))]",
"[resourceId('microsoft.insights/actionGroups', parameters('utilityActionGroup'))]"
]
}
],
"outputs": { }
}
As per my test, I create the alert inside application insights via azure portal, and it can appear in the portal.
When check the alert in portal, please make sure that select the correct resource as the one you create alert.

Tags Not Being Deployed to Server Farm with Azure ARM template

EDIT 11/15/2016: This was a bug in Azure which was fixed a couple of days ago.
Original post:
I'm trying to create several app services which depend on a server farm. I'm using an ARM template to deploy it. I'm using the same tags and tag format on every other resource in the template and they are getting created, but for some reason the tags on the server farm aren't. I can create the tags on the server farm through the Azure Portal and the Resource Explorer, but not through the ARM template.
Here's part of my resources section:
{
"comments": "",
"type": "Microsoft.Web/serverfarms",
"sku": {
"name": "S3",
"tier": "Standard",
"size": "S3",
"family": "S",
"capacity": 1
},
"tags": {
"tag1": "[parameters('tag1Value')]",
"tag2": "[parameters('tag2Value')]",
"tag3": "[parameters('tag3Value')]",
"tag4": "[parameters('tag4Value')]",
"tag5": "[parameters('tag4Value')]",
"tag6": "[parameters('tag6Value')]",
"tag7": "[parameters('tag7Value')]"
},
"name": "[variables('serverFarmName')]",
"apiVersion": "2015-08-01",
"location": "[parameters('location')]",
"properties": {
"name": "[variables('serverFarmName')]",
"numberOfWorkers": 1
},
"dependsOn": []
},
[...]
Any known issues with this? Do I have the tags in the wrong place?
Edit 8/8/2016:
Deploying just a server farm works correctly, but as soon as I add a site to that server farm the tags aren't deployed correctly. Here's what happens: Deployment starts, the server farm is created. Before the site is created I can rush into the Azure portal and see the tags created correctly on the server farm. As soon as the site is created I refresh, go back into the server farm, and the tags have disappeared.
It works fine on my side, you can try to leverage the Azure Resource Group project in Visual studio as mentioned at https://blogs.msdn.microsoft.com/kaevans/2015/11/22/creating-arm-templates-with-azure-resource-explorer/.
Here is my simple test template for your information:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"tag1Value": { "type": "string" },
"tag2Value": { "type": "string" },
"tag3Value": { "type": "string" },
"tag4Value": { "type": "string" },
"tag5Value": { "type": "string" },
"tag6Value": { "type": "string" },
"tag7Value": { "type": "string" },
"garysfName": {
"type": "string",
"minLength": 1
},
"garysfSKU": {
"type": "string",
"allowedValues": [
"Free",
"Shared",
"Basic",
"Standard"
],
"defaultValue": "Free"
},
"garysfWorkerSize": {
"type": "string",
"allowedValues": [
"0",
"1",
"2"
],
"defaultValue": "0"
}
},
"variables": {
},
"resources": [
{
"name": "[parameters('garysfName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2014-06-01",
"dependsOn": [ ],
"tags": {
"displayName": "garysf",
"tag1": "[parameters('tag1Value')]",
"tag2": "[parameters('tag2Value')]",
"tag3": "[parameters('tag3Value')]",
"tag4": "[parameters('tag4Value')]",
"tag5": "[parameters('tag4Value')]",
"tag6": "[parameters('tag6Value')]",
"tag7": "[parameters('tag7Value')]"
},
"properties": {
"name": "[parameters('garysfName')]",
"sku": "[parameters('garysfSKU')]",
"workerSize": "[parameters('garysfWorkerSize')]",
"numberOfWorkers": 1
}
},
{
"name": "[variables('garyarmwebappName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('garysfName'))]"
],
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('garysfName'))]": "Resource",
"displayName": "garyarmwebapp"
},
"properties": {
"name": "[variables('garyarmwebappName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', parameters('garysfName'))]"
}
}
],
"outputs": {
}
}
And the parameters JSON file:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"tag1Value": { "value": "tag11" },
"tag2Value": { "value": "tag22" },
"tag3Value": { "value": "tag33" },
"tag4Value": { "value": "tag44" },
"tag5Value": { "value": "tag55" },
"tag6Value": { "value": "tag66" },
"tag7Value": { "value": "tag77" },
"garysfName": {
"value": "garyserverfarms"
}
}
}
And you can refer to https://ms.portal.azure.com/?flight=1&flight.browsegrid2=true&flight.pov2=true&flight.resourcemenuperf=true#blade/HubsExtension/SubscriptionTagsListBlade to check the tag list on Azure portal.

Azure Resource Manager alarm creation

I'm trying to use an Azure Resource Manager template to create an alert in Application Insights. The problem I'm having is what value I should put for resourceUri. I've tried a few different values, I'm not sure if it's supposed to be the resource I'm monitoring or something else. The documentation is most unhelpful. When I try with the value below it gives me a validation error.
It's also not clear how I actually associate the alert with the component. Is it supposed to be nested as a resource within the component? I have a dependsOn referencing the component but from what I understand that would just ensure the other resource gets created first.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2014-04-01",
"type": "Microsoft.Insights/components",
"name": "testmetrics",
"location": "Central US"
},
{
"apiVersion": "2014-04-01",
"type": "Microsoft.Insights/alertrules",
"name": "testAlert1",
"dependsOn": [
"[concat('Microsoft.Insights/components/', 'testmetrics')]"
],
"location": "Central US",
"properties": {
"description": "Test description",
"action": {
"customEmails": [ "me#somewhere.com" ]
},
"condition": {
"failedLocationCount": "1",
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"threshold": "0",
"dataSource": {
"metricName": "BackupFailed",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "/Microsoft.Web/sites/mytestsite"
},
"operator": "GreaterThan",
"windowSize": "1"
}
}
}
]
}
The resourceUrl should refer to the Application Insights service in following format:
"resourceUri": "[concat(resourceGroup().id, '/providers/Microsoft.Insights/components/', 'testmetrics')]"
A great way to figure out how to write these templates correctly (if you can't find a reference in the Github repository for ARM quickstart templates) is to create a resource group in the Azure portal, configure your system and then export to a JSON template (found in the "Setting" blade when you click your resource group).
I just created an example Application Insights resource with an alert and got the one below.
You can see how the dependency is nested and the correct syntax. Also note that location for Central US is provided as "centralus"
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertrules_analertname_name": {
"defaultValue": "analertname",
"type": "String"
},
"components_appinsightname_name": {
"defaultValue": "appinsightname",
"type": "String"
}
},
"variables": {},
"resources": [
{
"comments": "Generalized from resource: '/subscriptions/SOME-SUBSCRIPTIN-GUID/resourceGroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/alertrules/analertname'.",
"type": "microsoft.insights/alertrules",
"name": "[parameters('alertrules_analertname_name')]",
"apiVersion": "2014-04-01",
"location": "East US",
"tags": {
"hidden-link:/subscriptions/SOME-SUBSCRIPTIN-GUID/resourcegroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/components/appinsightname": "Resource"
},
"properties": {
"name": "[parameters('alertrules_analertname_name')]",
"description": "Some alert",
"isEnabled": true,
"condition": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsightname_name'))]",
"metricName": "availability.availabilityMetric.value"
},
"threshold": 1,
"windowSize": "PT5M"
},
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"customEmails": [
"someemail#example.com"
]
}
},
"dependsOn": [
"[resourceId('microsoft.insights/components', parameters('components_appinsightname_name'))]"
]
},
{
"comments": "Generalized from resource: '/subscriptions/SOME-SUBSCRIPTIN-GUID/resourceGroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/components/appinsightname'.",
"type": "microsoft.insights/components",
"kind": "web",
"name": "[parameters('components_appinsightname_name')]",
"apiVersion": "2014-04-01",
"location": "centralus",
"tags": {},
"properties": {
"ApplicationId": "[parameters('components_appinsightname_name')]"
},
"dependsOn": []
}
]
}
Hope this helps.

Resources