azure - 断开 Azure VM 与 loganalytics 工作区的连接

标签 azure powershell virtual-machine azure-log-analytics

我正在寻找一种 powershell 方法来断开虚拟机与 OMS 工作区的连接。

我编写了一个 powershell 脚本来将虚拟机移动到其他订阅。所以我必须将此虚拟机从“源工作区”重新连接到“目标工作区”。

仅删除 OMS 扩展后,虚拟机在 Azure 门户“Log Analytics 工作区 > 工作区数据源 > 虚拟机”中显示为“未连接”。

这个 cmdlet 应该可以解决问题( the doc is not really clear ),但我总是收到相同的消息

remove-AzureRmOperationalInsightsDataSource -Workspace $OmsWkspceITS -Name CentosMove
Confirm
Are you sure you want to remove data source 'CentosMove' in workspace 'itsoms'?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Yes"): yes
WARNING: DataSource 'CentosMove' does not exist in workspace 'itsoms'.

(CentosMove 是我的虚拟机名称)。

我们的 ITSOMS 工作区已使用多年,拥有数百个虚拟机、许多解决方案、NSG 日志流分析......

$OmsWkspceITS


Name              : itsoms
ResourceGroupName : rg_its_exploit
ResourceId        : /subscriptions/blablabla/resourcegroups/blabla/providers/microsoft.operationalinsights/workspaces/itsoms
Location          : westeurope
Tags              :
Sku               : standalone
CustomerId        : xx
PortalUrl         : https://weu.mms.microsoft.com/Accou...
ProvisioningState : Succeeded

我可以使用此 cmdlet 获得的唯一数据源是像这样的数据源

Get-AzureRmOperationalInsightsDataSource -WorkspaceName $OmsWkspceITS.Name -ResourceGroupName $OmsWkspceITS.ResourceGroupName -Name DataSource_LinuxSyslog_syslog


Name              : DataSource_LinuxSyslog_syslog
ResourceGroupName : rg_its_exploit
WorkspaceName     : itsoms
ResourceId        : /subscriptions/xx/resourceGroups/rg_its_exploit/providers/Microsoft.OperationalInsights/workspaces/itsoms/datasources/DataSource_LinuxSyslog_syslog
Kind              : LinuxSyslog
Properties        : {"syslogName":"syslog".....}

我认为我可能没有看到正确的 cmdlet ...

感谢您的帮助:)

最佳答案

要满足您的要求,请使用 cmdlet Remove-AzureRmVMExtensionSet-AzureRmVMExtension

为了便于说明,请检查以下命令。

要断开 Linux VM 代理:

Remove-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘OmsAgentForLinux’

要断开 Windows VM 代理:

Remove-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘MicrosoftMonitoringAgent’

要将 Linux VM 代理连接到 Log Analytics 工作区:

$WorkspaceID = "xxxxxxxxxxxxxxxxxxxxxxxxx"
$WorkspaceKey = "xxxxxxxxxxxxxxxxxxxxxxxx"
Set-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘OmsAgentForLinux’ -Publisher ‘Microsoft.EnterpriseCloud.Monitoring’ -ExtensionType ‘OmsAgentForLinux’ -TypeHandlerVersion ‘1.0’ -Location 'LOCATION' -SettingString "{‘workspaceId’: ‘$WorkspaceID’}" -ProtectedSettingString "{‘workspaceKey’: ‘$WorkspaceKey’}"

要将 Windows VM 代理连接到 Log Analytics 工作区:

$WorkspaceID = "xxxxxxxxxxxxxxxxxxxxxxxxx"
$WorkspaceKey = "xxxxxxxxxxxxxxxxxxxxxxxx"
Set-AzureRmVMExtension -ResourceGroupName RESOURCEGROUPNAME -VMName VMNAME -Name ‘MicrosoftMonitoringAgent’ -Publisher ‘Microsoft.EnterpriseCloud.Monitoring’ -ExtensionType ‘MicrosoftMonitoringAgent’ -TypeHandlerVersion ‘1.0’ -Location 'LOCATION' -SettingString "{‘workspaceId’: ‘$WorkspaceID’}" -ProtectedSettingString "{‘workspaceKey’: ‘$WorkspaceKey’}"

希望这有帮助!干杯!! :)

关于azure - 断开 Azure VM 与 loganalytics 工作区的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54687709/

相关文章:

Docker + Virtual Box = VT-x 不可用 (VERR_VMX_NO_VMX)

Azure函数: How to run Linux Consumption Zip Deploy?

powershell - 使用强制选项在Powershell中创建应用程序池

azure - Terraform Azurerm - 输出公共(public)IP地址用作变量

powershell - 术语 'get-splogevent' 未被识别为 cmdlet 的名称

powershell - 捕获 Format-Table 的输出(将其显示在主机上,而不是标准输出上)的正确方法是什么?

localhost - 从 VirtualBox 虚拟机寻址本地主机

node.js - 在 docker build 中安装 npm

python - 使用 Azure AKS 群集的 Kubernetes Python 客户端填充 Pod CPU 限制

node.js - 如何在Azure函数中的Nodejs中读取.env文件变量