Last active
March 28, 2019 16:12
-
-
Save kevinhillinger/351ee7d6f2feedc6eeee3b0cb2261101 to your computer and use it in GitHub Desktop.
Adding Log Analytics VM Extension to VM Scale Set with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "[concat(variables('vmNodeType0Name'),'OMS')]", | |
"properties": { | |
"publisher": "Microsoft.EnterpriseCloud.Monitoring", | |
"type": "MicrosoftMonitoringAgent", | |
"typeHandlerVersion": "1.0", | |
"autoUpgradeMinorVersion": true, | |
"settings": { | |
"workspaceId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')), '2015-11-01-preview').customerId]" | |
}, | |
"protectedSettings": { | |
"workspaceKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')),'2015-11-01-preview').primarySharedKey]" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-health-extension | |
# DEPLOY AFTER SCALE SET | |
# scale set info | |
$scaleSetName = "<name of scale set>" | |
$scaleSetResourceGroup = "<name of resource group the vmss belongs to>" | |
$workspaceResourceGroupName = "<name of the resource group that the workspace is in" | |
# get the workspace and then id | |
$workspace = Get-AzOperationalInsightsWorkspace -ResourceGroupName $workspaceResourceGroupName | |
Write-Output $workspace | |
$sharedKeys = Get-AzOperationalInsightsWorkspaceSharedKeys -Name $workspace.Name -ResourceGroupName $workspace.ResourceGroupName | |
$workspaceId = $sharedKeys.PrimarySharedKey | |
# set the id and key to use as parameters for the deployment | |
$parameters = @{ | |
workspaceId = $workspace.CustomerId.ToString(); | |
workspaceKey = $workspaceId; | |
} | |
# Get information about the scale set | |
$vmss = Get-AzVmss -ResourceGroupName $scaleSetResourceGroup -VMScaleSetName $scaleSetName | |
Add-AzVmssExtension ` | |
-VirtualMachineScaleSet $vmss ` | |
-Name "Microsoft.EnterpriseCloud.Monitoring" ` | |
-Publisher "Microsoft.EnterpriseCloud.Monitoring" ` | |
-Type "MicrosoftMonitoringAgent" ` | |
-TypeHandlerVersion 1.0 ` | |
-AutoUpgradeMinorVersion $true ` | |
-Setting @{ "workspaceId" = $parameters.workspaceId } ` | |
-ProtectedSetting @{ "workspaceKey" = $parameters.workspaceKey } | |
# Update the scale set and apply the Custom Script Extension to the VM instances | |
Update-AzVmss ` | |
-ResourceGroupName $vmss.ResourceGroupName ` | |
-Name $vmss.Name ` | |
-VirtualMachineScaleSet $vmss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
az vmss extension set --name MicrosoftMonitoringAgent \ | |
--publisher Microsoft.EnterpriseCloud.Monitoring \ | |
--resource-group <nameOfResourceGroup> \ | |
--vmss-name <nameOfNodeType> \ | |
--settings "{'workspaceId':'<Log AnalyticsworkspaceId>'}" \ | |
--protected-settings "{'workspaceKey':'<Log AnalyticsworkspaceKey>'}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "myHealthExtension", | |
"properties": { | |
"publisher": " Microsoft.ManagedServices", | |
"type": "< ApplicationHealthWindows>", | |
"autoUpgradeMinorVersion": true, | |
"typeHandlerVersion": "1.0", | |
"settings": { | |
"protocol": "<protocol>", | |
"port": "<port>", | |
"requestPath": "</requestPath>" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment