Deploying the OMS Windows Agent using DSC


On this article we are going to deploy the OMS windows agent on a server using DSC.

Before proceeding with the DSC part, there are some requirements that have to be met. We need to store the agent file on a file share that is going to be accessible by the server and we need to know the product id of the agent software in order to use it with the package resource.

On my lab environment, I've configured a FreeNAS virtual machine to provide all kinds of file shares and I'm using a public SMB share to host the agent installation file. You can host it on any other location such as web, as long as there's a way to get it using DSC.

I've also configured a DSC Pull server and I'm publishing the configurations there, but since it does not contain any custom configurations, you can publish it directly to the machines.

An easy way to get it is to install the agent on a computer and then execute the following PowerShell command:

PS C:\> Get-WmiObject Win32_Product | ? Name -like "Microsoft Monitoring*"
IdentifyingNumber : {EE0183F4-3BF8-4EC8-8F7C-44D3BBE6FDF0}
Name              : Microsoft Monitoring Agent
Vendor            : Microsoft Corporation
Version           : 8.0.11081.0
Caption           : Microsoft Monitoring Agent

PS C:\>

We now have the product id and the location of the setup file, thus we ready to construct the package resource configuration.

I'm a big fan of nested configurations so we going to create a configuration that's going to be easily included to an existing one.

First of, the configuration directive and a few variables to make things easier:
# The OMS nested configuration
Configuration OMS
{
    $OIPackageLocalPath = "C:\Temp\MMASetup-AMD64.exe"
    $OPSINSIGHTS_WS_ID = "cfa4****-7***-****-****-**********72"
    $OPSINSIGHTS_WS_KEY = "J***************A***************Xc9ttHWvnc8Tj*********************=="
The first part of the configuration is to create a temporary directory: 
    # Create the C:\Temp directory
    File TempDirectory
    {
        Ensure = "Present"
        Type = "Directory"
        DestinationPath = "C:\Temp"
    }
Then we are going to copy the setup file on the temporary directory:
    # Copy the setup file
    File AgentSetupFile
    {
        Ensure = "Present"
        Type = "File"
        SourcePath = "\\freenas\PublicFiles\Software\OMS\Agents\Windows\8.0.11081.0\MMASetup-AMD64.exe"
        DestinationPath = $OIPackageLocalPath
        DependsOn = "[File]TempDirectory"   
    }
The next step is to configure the package:
    # Configure the package    
    Package OMSPackage
    {
        Ensure = "Present"
        Path  = $OIPackageLocalPath
        Name = "Microsoft Monitoring Agent"
        ProductId = "EE0183F4-3BF8-4EC8-8F7C-44D3BBE6FDF0"
        Arguments = '/C:"setup.exe /qn NOAPM=1 ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=' +
                    $OPSINSIGHTS_WS_ID + ' OPINSIGHTS_WORKSPACE_KEY=' + 
                    $OPSINSIGHTS_WS_KEY + ' AcceptEndUserLicenseAgreement=1"'
        DependsOn = "[File]AgentSetupFile"
    }
In case you have to use a proxy server to connect to the workspace, you can configure the agent using the following block:
    # Configure the proxy server
    Registry OMSGateway
    {
        Ensure      = "Present"
        Key         = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HealthService\Parameters"
        ValueName   = "Http Connection Proxy Url"
        ValueData   = "OMSGateway.lab.local:8080"
        ValueType   = 'String'
        DependsOn   = "[Package]OMSPackage"         
    }
The last part of the nested configuration is to make sure that the health service is running:
    # Make sure the service is running
    Service OMSService
    {
        Name = "HealthService"
        State = "Running"
        DependsOn = "[Package]OMSPackage"
    }
}
Finally, the main configuration block:
Configuration FileServer
{
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration' 
 
    Node localhost 
    {
        OMS OMSConfig {}
    }
}
Now that the configuration is completed, it's time to send it to the machine! Below are some lines from the configuration command on the machine:

Applying the new configuration
VERBOSE: [CLUSTERNODE2]: [] Checksum is different. LCM will execute GetConfiguration.
VERBOSE: [CLUSTERNODE2]: [] Configuration document is pulled from server.
VERBOSE: [CLUSTERNODE2]: [] Applying the configuration document pulled.

Testing the configuration and configuring items
VERBOSE: [CLUSTERNODE2]: LCM: [ End Test ] [[File]TempDirectory::[OMS]OMSConfig] in 0.2070 seconds.
VERBOSE: [CLUSTERNODE2]: LCM: [ Start Set ] [[File]TempDirectory::[OMS]OMSConfig]
VERBOSE: [CLUSTERNODE2]: LCM: [ End Test ] [[File]AgentSetupFile::[OMS]OMSConfig] in 2.8000 seconds.
VERBOSE: [CLUSTERNODE2]: LCM: [ Start Set ] [[File]AgentSetupFile::[OMS]OMSConfig]
VERBOSE: [CLUSTERNODE2]: LCM: [ End Test ] [[Package]OMSPackage::[OMS]OMSConfig] in 3.1810 seconds.
VERBOSE: [CLUSTERNODE2]: LCM: [ Start Set ] [[Package]OMSPackage::[OMS]OMSConfig]
VERBOSE: [CLUSTERNODE2]: [[Package]OMSPackage::[OMS]OMSConfig] Starting C:\Temp\MMASetup-AMD64.exe with /C:"setup.exe /qn NOAPM=1...
VERBOSE: [CLUSTERNODE2]: LCM: [ End Test ] [[Registry]OMSGateway::[OMS]OMSConfig] in 1.4100 seconds.
VERBOSE: [CLUSTERNODE2]: LCM: [ Start Set ] [[Registry]OMSGateway::[OMS]OMSConfig]

Completing the configuration
VERBOSE: [CLUSTERNODE2]: LCM: [ End Resource ] [[Service]OMSService::[OMS]OMSConfig]
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 86.998 seconds

Give it some time and then go back to the Advanced Analytics workspace and check the heartbeat to verify that the agents are reporting.

Related articles
    Introduction to Azure Advanced Analytics
    Configuring Log and Performance Counter collection on the OMS Workspace
    Install and Configure the OMS Windows Agent
    Verify the Agent Connectivity to OMS Workspace
    Deploying the OMS Windows Agent using DSC
    Querying OMS for Performance Data
    Querying OMS for Events
    Collecting IIS Log Files
    Install and Configure the OMS Linux Agent
    Syslog Message Collection for OMS from sources that do not support the agent
    Generating Alerts on OMS
    Update Management using OMS
    Monitoring Active Directory Health using OMS
    Assessing Security using OMS
    Monitoring Microsoft SQL using OMS
    Monitoring Azure Activity Log using OMS

Popular posts from this blog

Domain Controller Machine Password Reset

Managing Active Directory User Certificates using PowerShell

Configuring a Certificate on Exchange Receive Connector