如何使用PowerShell安装和配置Microsoft监控代理以与OMS网关(代理)一起使用

时间:2019-09-19 21:37:02

标签: azure azure-devops azure-powershell azure-monitoring azure-template

如何使用Powershell安装和配置Microsoft监视代理(MMA)以与OMS网关一起使用? 没有一个自动化示例可以告诉您如何完成此操作以用于OMS网关。

我发现这是逐步手动进行操作的演练: http://azurepost.com/oms-gateway-ga-installation-configuration-walkthrough/

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/gateway

自动化:

这是用于ARM模板的, 但不支持OMS网关 Enabling the Microsoft Monitoring Agent in Windows JSON Templates

该版本用于Powershell,但不支持OMS网关 oms-windows.md

没有一个自动化示例可以告诉您如何与OMS网关配合使用。 实际上,从Property values的文档看来,这是不可能的。仅记录的属性是workspaceId和workspaceKey。没有列出OMS网关配置所需的其他属性(即代理,用户ID,密码)。

1 个答案:

答案 0 :(得分:0)

解决方案:通过ARM或PS部署和配置MMA以与OMS Gateway一起使用。 这些属性可用于ARM和PS。 PS通常在后台构建ARM模板。全套属性是:

文档扩展属性

  • workspaceId
  • workspaceKey

未公开的扩展程序属性

控制面板; Microsoft Monitoring Agent应用程序以确定这些值中的大多数含义。

  • enableAutomaticManagement :等同于“表:'Operations Manager',AD DS的自动更新管理组分配”

  • proxyUri :等同于“标签:'代理设置',代理服务器”

  • proxyUser :等同于“标签:'代理设置',用户名”
  • proxyPassword :#等同于“标签:'代理设置',密码”
  • azureRegionId :不确定,但是我认为这可能与Log Analytics位于不同区域有关。使用Get-AzureRMLocation,Location确定有效值

  • stopOnMultipleConnections

  • azureResourceId :???

通过Powershell部署:

Import-Module Az.Compute
Connect-AzAccount 
Set-AzContext -Subscription  $subscriptionId

$settings = @{ `
    "workspaceId" = $workspaceId; `
    "proxyUri" = $proxyUri; `
    "azureRegionId" = $azureRegionId `
}
$protectedSettings = @{"workspaceKey" = $workspaceKey}

$extensions = Get-AzVMExtension `
    -ResourceGroupName $resourceGroupName `
    -VMName $vmName 

#If extension was already installed and the ExtensionName is not 'MicrosoftMonitoringAgent',
#re-install will fail. Therefore, we need to remove extension before proceeding.
foreach($extension in $extensions)
{
    if ($extension.ExtensionType -eq "MicrosoftMonitoringAgent")
    {
        Remove-AzVMExtension `
            -ResourceGroupName $resourceGroupName `
            -VMName $vmName `
            -Name $extension.Name `
            -Confirm:$false `
            -Force:$true
    }

}

#install MMA Extension
$guid = New-Guid 
Set-AzVMExtension `
    -ResourceGroupName $resourceGroupName `
    -VMName $vmName `
    -ExtensionType "MicrosoftMonitoringAgent" `
    -ExtensionName "MicrosoftMonitoringAgent" `
    -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
    -TypeHandlerVersion 1.0 `
    -ForceRerun $guid `
    -Settings $settings `
    -ProtectedSettings $protectedSettings `
    -Location $azureRegionId 

通过ARM模板部署

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string"
    },
    "serverName": {
      "type": "string"
    },
    "workspaceId": {
      "type": "string",
      //from the blob's etag property; changes each time update occurs
      "defaultValue": "guid-guid-guid-guid",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Azure Log Analytics (OMS)', Add or Edit Popup"
      }
    },
    "proxyUri": {
      "type": "string",
      "defaultValue": "101.102.103.104:8080",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Proxy Settings', Proxy Server"
      }
    },
    "workspaceKey": {
      "type": "securestring",
      "defaultValue": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Azure Log Analytics (OMS)', Add or Edit Popup"
      }
    },

    "forceUpdateTag": {
      "defaultValue": "[newGuid()]",
      "type": "string",
      "metadata": {
        "description": "Forces extension to deploy every time."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2018-10-01",
      "name": "[concat(parameters('serverName'),'/MicrosoftMonitoringAgent')]",
      "location": "[parameters('location')]",
      "properties": {
        "publisher": "Microsoft.EnterpriseCloud.Monitoring",
        "type": "MicrosoftMonitoringAgent",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": "true",
        "forceUpdateTag": "[parameters('forceUpdateTag')]",
        "settings": {
          "workspaceId": "[parameters('workspaceId')]",
          "proxyUri": "[parameters('proxyUri')]",
          "azureRegionId": "[parameters('location')]"
        },
        "protectedSettings": {
          "workspaceKey": "[parameters('workspaceKey')]"
        }
      }
    }
  ]
}

(请告诉我我浪费了时间,并且在某处有“ Interogate Extension” powershell命令...) 我是怎么知道的?我使用门户来部署MMA扩展。我转到虚拟机,在以下位置找到了已安装的扩展名:      C:\ Packages \ Plugins \ Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent

我反编译了: Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.ExtensionShared.dll ,并查找确切的字符串: workspaceId workspaceKey 。我找到了以下类:MMAExtensionPublicSettings,MMAExtensionProtectedSettings。这些类包含有效的扩展属性。

using Newtonsoft.Json;
using System;
using System.Runtime.CompilerServices;

namespace Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMADataModels
{
    public class MMAExtensionPublicSettings
    {
        [JsonProperty(PropertyName = "azureRegionId")]
        public string AzureRegionId{ get; set; }

        [JsonProperty(PropertyName = "azureResourceId")]
        public string AzureResourceId { get; set; }

        [JsonProperty(PropertyName = "enableAutomaticManagement")]
        public bool EnableAutomaticManagement { get; set; }

        [JsonProperty(PropertyName = "proxyUri")]
        public string ProxyUri { get; set; }

        [JsonProperty(PropertyName = "proxyUser")]
        public string ProxyUser { get; set; }

        [JsonProperty(PropertyName = "stopOnMultipleConnections")]
        public bool StopOnMultipleConnections { get; set; }

        [JsonProperty(PropertyName = "workspaceId")]
        public string WorkspaceId { get; set; }
        public MMAExtensionPublicSettings()
        {
        }
    }
}

**-MMAExtensionProtectedSettings

using Newtonsoft.Json;
using System;
using System.Runtime.CompilerServices;    
namespace Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMADataModels
{
    public class MMAExtensionProtectedSettings
    {
        [JsonProperty(PropertyName="proxyPassword")]
        public string ProxyPassword
        {
            get;
            set;
        }

        [JsonProperty(PropertyName="workspaceKey")]
        public string WorkspaceKey
        {
            get;
            set;
        }

        public MMAExtensionProtectedSettings()
        {
        }
    }
}