Is it possible to get the OMS Log Analytics workpace name from the Workspace ID

2.3k Views Asked by At

I have an existing OMS Log Analytics Workspace. The Workspace ID is a guid. This is the only thing I am able to use due to an existing project. Using this guid I need to get hold of the Workspace Name example "myWorkspace" in the arm template. I am allowed to pass the guid as the parameter to the arm template. The Guid actually is a customerId property if I look in the Json and ResourceId maps to the Workspace Name which begins with /subscription/xx-xxx-xxx-xxx/......../myWorkspace.

I need to get hold of this Workspace Name (ResourceId) from guid (customerId). Please let me know if I can do this or not? Really struggling to get this working...

2

There are 2 best solutions below

0
John Gardner On

You can get it from ARG (Azure resource graph) pretty easily, but there's no way i know of to look it up IN an ARM template itself. you'd probably have to look up the id outside the template and pass it in as a parameter?

https://learn.microsoft.com/en-us/azure/governance/resource-graph/concepts/explore-resources

Resources 
| where type =~ "microsoft.operationalinsights/workspaces"
| where properties.customerId == "00000000-0000-0000-0000-00000000000"
| project id, name
0
Llazar On

I am not sure what you want to achieve but I have used multiple times the Log Analytics Workspace with azure ARM. An example is how to retrieve the workspace key and workspace Id to connect a vm with the workspace.

See the code bellow:

  {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(parameters('vmName'), '/OMSExtension')]",
        "apiVersion": "2018-06-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName') )]"
        ],
        "properties": {
            "publisher": "Microsoft.EnterpriseCloud.Monitoring",
            "type": "OmsAgentForLinux",
            "typeHandlerVersion": "1.7",
            "autoUpgradeMinorVersion": true,
            "settings": {
                "workspaceId": "[reference(resourceId(parameters('logAnalyticsRG'), 'Microsoft.OperationalInsights/workspaces/', parameters('logAnalyticsName')), '2015-03-20').customerId]"
            },
            "protectedSettings": {
                "workspaceKey": "[listKeys(resourceId(parameters('logAnalyticsRG'), 'Microsoft.OperationalInsights/workspaces/', parameters('logAnalyticsName')), '2015-03-20').primarySharedKey]"
            }
        }
    }

Everything depends from the scenario you, but this is the way how to retrieve the workspace id and key.