Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Log Analytics with Solutions and Diagnostics Settings Sample #607

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
param location string {
default: resourceGroup().location
allowed: [
'australiacentral'
'australiaeast'
'australiasoutheast'
'brazilsouth'
'canadacentral'
'centralindia'
'centralus'
'eastasia'
'eastus'
'eastus2'
'francecentral'
'japaneast'
'koreacentral'
'northcentralus'
'northeurope'
'southafricanorth'
'southcentralus'
'southeastasia'
'switzerlandnorth'
'switzerlandwest'
'uksouth'
'ukwest'
'westcentralus'
'westeurope'
'westus'
'westus2'
]
}

param logAnalyticsWorkspaceName string = 'la-${uniqueString(resourceGroup().id)}'

var vmInsights = {
name: 'VMInsights(${logAnalyticsWorkspaceName})'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to have the parens () as part of the string here? In other words, the parens are going to be in the final calculated name and will show up in the resource names

Copy link
Contributor Author

@joshuawaddell joshuawaddell Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did intend to have the parens () as part of the string. In referencing the documentation on enabling Azure Monitor for VMs and Azure Monitor for Containers, that syntax is used. You can view the sample ARM Template at this link: https://docs.microsoft.com/en-us/azure/azure-monitor/insights/vminsights-enable-resource-manager

"apiVersion": "2015-11-01-preview", "type": "Microsoft.OperationsManagement/solutions", "location": "[parameters('WorkspaceLocation')]", "name": "[concat('VMInsights', '(', split(parameters('WorkspaceResourceId'),'/')[8], ')')]",

I tried using name: 'VMInsights-${logAnalyticsWorkspaceName}' as well as some other options, and the deployment errored out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Looks good to me then.

galleryName: 'VMInsights'
}
var containerInsights = {
name: 'ContainerInsights(${logAnalyticsWorkspaceName})'
galleryName: 'ContainerInsights'
}

var environmentName = 'Production'
var costCenterName = 'IT'

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-03-01-preview' = {
name: logAnalyticsWorkspaceName
location: location
tags: {
Environment: environmentName
CostCenter: costCenterName
}
properties: {
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
}
}

resource logAnalyticsWorkspaceDiagnostics 'Microsoft.OperationalInsights/workspaces/providers/diagnosticSettings@2017-05-01-preview' = {
name: '${logAnalyticsWorkspace.name}/Microsoft.Insights/diagnosticSettings'
properties: {
workspaceId: logAnalyticsWorkspace.id
logs: [
{
category: 'Audit'
enabled: true
retentionPolicy: {
days: 7
enabled: true
}
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
retentionPolicy: {
days: 7
enabled: true
}
}
]
}
}

resource solutionsVMInsights 'Microsoft.OperationsManagement/solutions@2015-11-01-preview' = {
name: '${vmInsights.name}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the string interpolation here. You can simply do:

name: vmInsights.name

Copy link
Contributor Author

@joshuawaddell joshuawaddell Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to name: vmInsights.name

location: location
dependsOn: [
logAnalyticsWorkspace
]
properties: {
workspaceResourceId: logAnalyticsWorkspace.id
}
plan: {
name: '${vmInsights}.Name'
alex-frankel marked this conversation as resolved.
Show resolved Hide resolved
publisher: 'Microsoft'
product: 'OMSGallery/${vmInsights.galleryName}'
promotionCode: ''
}
}

resource solutionsContainerInsights 'Microsoft.OperationsManagement/solutions@2015-11-01-preview' = {
name: '${containerInsights.name}'
location: location
dependsOn: [
logAnalyticsWorkspace
]
properties: {
workspaceResourceId: logAnalyticsWorkspace.id
}
plan: {
name: '${containerInsights}.Name'
alex-frankel marked this conversation as resolved.
Show resolved Hide resolved
publisher: 'Microsoft'
product: 'OMSGallery/${containerInsights.galleryName}'
promotionCode: ''
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"allowedValues": [
"australiacentral",
"australiaeast",
"australiasoutheast",
"brazilsouth",
"canadacentral",
"centralindia",
"centralus",
"eastasia",
"eastus",
"eastus2",
"francecentral",
"japaneast",
"koreacentral",
"northcentralus",
"northeurope",
"southafricanorth",
"southcentralus",
"southeastasia",
"switzerlandnorth",
"switzerlandwest",
"uksouth",
"ukwest",
"westcentralus",
"westeurope",
"westus",
"westus2"
]
},
"logAnalyticsWorkspaceName": {
"type": "string",
"defaultValue": "[format('la-{0}', uniqueString(resourceGroup().id))]"
}
},
"functions": [],
"variables": {
"vmInsights": {
"name": "[format('VMInsights({0})', parameters('logAnalyticsWorkspaceName'))]",
"galleryName": "VMInsights"
},
"containerInsights": {
"name": "[format('ContainerInsights({0})', parameters('logAnalyticsWorkspaceName'))]",
"galleryName": "ContainerInsights"
},
"environmentName": "Production",
"costCenterName": "IT"
},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-03-01-preview",
"name": "[parameters('logAnalyticsWorkspaceName')]",
"location": "[parameters('location')]",
"tags": {
"Environment": "[variables('environmentName')]",
"CostCenter": "[variables('costCenterName')]"
},
"properties": {
"retentionInDays": 30,
"features": {
"searchVersion": 1
},
"sku": {
"name": "PerGB2018"
}
}
},
{
"type": "Microsoft.OperationalInsights/workspaces/providers/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[format('{0}/Microsoft.Insights/diagnosticSettings', parameters('logAnalyticsWorkspaceName'))]",
"properties": {
"workspaceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]",
"logs": [
{
"category": "Audit",
"enabled": true,
"retentionPolicy": {
"days": 7,
"enabled": true
}
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true,
"retentionPolicy": {
"days": 7,
"enabled": true
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
]
},
{
"type": "Microsoft.OperationsManagement/solutions",
"apiVersion": "2015-11-01-preview",
"name": "[format('{0}', variables('vmInsights').name)]",
"location": "[parameters('location')]",
"properties": {
"workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
},
"plan": {
"name": "[format('{0}.Name', variables('vmInsights'))]",
"publisher": "Microsoft",
"product": "[format('OMSGallery/{0}', variables('vmInsights').galleryName)]",
"promotionCode": ""
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
]
},
{
"type": "Microsoft.OperationsManagement/solutions",
"apiVersion": "2015-11-01-preview",
"name": "[format('{0}', variables('containerInsights').name)]",
"location": "[parameters('location')]",
"properties": {
"workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
},
"plan": {
"name": "[format('{0}.Name', variables('containerInsights'))]",
"publisher": "Microsoft",
"product": "[format('OMSGallery/{0}', variables('containerInsights').galleryName)]",
"promotionCode": ""
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
]
}
],
"outputs": {}
}