Param
Param

Reputation: 41

How to connect azure virtual machine with log analytics workspace using REST API or Nodejs SDK?

I want to make an automation process where every vm should connect with a log analytics workspace. So can anyone please help me, how do I connect a VM with log analytics workspace via REST API or Nodejs SDK ?

or

How do I enable virtual machine Insight through REST API or Nodejs SDK ?

enter image description here

Upvotes: 0

Views: 1329

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28224

How do I enable virtual machine Insight through REST API or Nodejs SDK ?

You can manage to do it with virtual Machine Extensions to enable the following agents.

  • Log Analytics agent. the VM extension for Windows and Linux.
  • Dependency agent. the VM extension for Windows and Linux.

Also, Before a Log Analytics workspace can be used with VM insights, it must have the VMInsights solution installed. Read Configuring VM insights.

enter image description here

For example, I click the green try it button in this REST API Virtual Machine Extensions - Create Or Update and provide my parameters and body to call this API.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/extensions/{vmExtensionName}?api-version=2020-12-01

The requests body like this for windows VM will be deployed in order.

Deploy MicrosoftMonitoringAgent

{
    "location": "<location>",
    "properties": {
        "publisher": "Microsoft.EnterpriseCloud.Monitoring",
        "type": "MicrosoftMonitoringAgent",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": "true",
        "settings": {
            "workspaceId": "<workspaceId>",
            "stopOnMultipleConnections": "true"
        },
        "protectedSettings": {
            "workspaceKey": "<workspaceKey>"
        }
                    }

}
        

Once the above extension is provisioned, you can deploy DependencyAgentWindows.

{
    "location": "<location>",
    "properties": {
        "publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
        "type": "DependencyAgentWindows",
        "typeHandlerVersion": "9.5",
        "autoUpgradeMinorVersion": "true",
        "settings": {
            "workspaceId": "<workspaceId>"
        },
        "protectedSettings": {
            "workspaceKey": "<workspaceKey>"
        }
                    }

}

enter image description here

Upvotes: 1

Related Questions