09. 09. 2020 Alessandro Romboli NetEye

Installing and Configuring Monitoring Agents in a Windows Domain – Part 1

Scenario

It’s quite typical to have several managed Windows Servers joined to a Windows Active Directory Domain.

But how do you handle the automated installation and configuration of the monitoring agents? How do you keep them up to date?

DSC Framework: A Potential Native Solution

DSC (Desired State Configuration) is a management platform in PowerShell that enables you to manage your IT and development infrastructure with configuration as code.

DSC is a declarative platform used for configuration, deployment, and management of systems. It consists of three primary components:

  • Configurations are declarative PowerShell scripts which define and configure instances of resources. Upon running the configuration, DSC (and the resources being called by the configuration) will simply “make it so”, ensuring that the system exists in the state laid out by the configuration. DSC configurations are also idempotent: the Local Configuration Manager (LCM) will continue to ensure that machines are configured in whatever state the configuration declares.
  • Resources are the “make it so” part of DSC. They contain the code that puts the target of a configuration in the specified state and keeps it there. Resources reside in PowerShell modules and can be written to model something as generic as a file or Windows process, or as specific as an IIS server or a VM running in Azure.
  • The Local Configuration Manager (LCM) is the engine by which DSC facilitates the interaction between resources and configurations. The LCM regularly polls the system using the control flow implemented by resources to ensure that the state defined by a configuration is maintained. If the system is out of state, the LCM makes calls to the code in resources to “make it so” according to the configuration.

Desired State Configuration is included in Windows and updated through the Windows Management Framework. It’s already configured and available on Windows Server 2012 onward, and can be configured also on (the no longer supported) Windows Server 2008 R2 SP1.

DSC Generic Configuration

Here is a sample DSC configuration taken from the Microsoft online documentation. It can be applied to the local node (as in this example “localhost”), or pushed to a remote one:

Configuration EnvironmentVariable_Path
{
    param ()
 
    Import-DscResource -ModuleName 'PSDscResources'
 
    Node localhost
    {
        Environment CreatePathEnvironmentVariable
        {
            Name = 'TestPathEnvironmentVariable'
            Value = 'TestValue'
            Ensure = 'Present'
            Path = $true
            Target = @('Process', 'Machine')
        }
    }
}
 
EnvironmentVariable_Path -OutputPath:"C:\EnvironmentVariable_Path"

This configuration PowerShell script, when executed, will generate a .MOF file in the C:\EnvironmentVariable_Path. This MOF configuration can be then applied to the localhost through a Start-DscConfiguration command, and queried using the Get-DscConfiguration statement to verify whether the desired configuration matches.

A Practical Example of Using DSC: Deploying the telegraf Agent to Remote Windows Servers

In this first example, I will show you how to install the telegraf agent on remote Windows servers.

In the second part of this Blog, I will show you how to handle the Icinga2 agent remote installation.

Both agents can be used for remote monitoring by the NetEye server.

In this example I choose a Windows server as a configuration master and push all the configurations to the remote nodes. (DSC could also work in scheduled Pull mode, but it’s a little more difficult to set up).

On the Master server I will create a C:\DSC path and, under that, a couple of subdirectories: SW and MOF.

SW must be shared for reading by the remote computer accounts (use the built-in Domain Group) and will contain the telegraf binaries under SW\telegraf\ and a basic telegraf configuration file as SW\telegraf_cfg\telegraf-base.conf.

C:\DSC\MOF will receive the generated configurations. Here’s the PowerShell configuration script:

#Requires -module ComputerManagementDsc
<#
        Test installation Telegraf
#>
Configuration Monitor
{
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
    Node @("server1","server2","server3")
    {
        File DirectoryCopy
        {
            Ensure = "Present"
            Type = "Directory"
            Recurse = $true
            SourcePath = "\\master\SW\telegraf"
            DestinationPath = "c:\Program Files\telegraf"
            MatchSource = $true
            Checksum = "modifiedDate"
        }
        File TelCfgCopy
        {
            Ensure = "Present"
            Type = "File"
            SourcePath = "\\master\SW\telegraf_cfg\telegraf-base.conf"
            DestinationPath = "c:\Program Files\telegraf\telegraf.conf"
            MatchSource = $true
            Checksum = "modifiedDate"
        }
       Service CreateService
        {
            Name   = "telegraf"
            Ensure = "Present"
            Path   = "c:\Program Files\telegraf\telegraf.exe"
            Description = "Telegraf monitoring"
            BuiltInAccount = "LocalSystem"
            StartupType = "Automatic"
            State = "Running"
        }
    }
}
Monitor -OutputPath:"C:\DSC\MOF"

In this script, “master” is the Master server name and server1, server2, server3 are the remote configured servers.

In the first step, it will copy the telegraf binaries, then the telegraf configuration file and finally create and start the telegraf service.

At every execution, the script will check the timestamp of all the files and copy them again if changed.

When I execute this script on the master node, it will generate 3 MOF files in the path C:\DSC\MOF.

These configurations can then be applied (pushed) with a simple PowerShell command:

Start-DscConfiguration -Path 'C:\DSC\MOF' -Wait

How to Get Started with the DSC Framework

DSC is a very powerful framework, allowing you to control every aspect of a Windows machine.  DSC is designed to maintain the desired configurations! It’s not just an installation language.

If used in the right way, DSC can handle any configuration changes, reducing the configuration time to a few seconds.  More information can be found on the Microsoft online documentation:

https://docs.microsoft.com/en-us/powershell/scripting/dsc/getting-started/wingettingstarted?view=powershell-5.1

Alessandro Romboli

Alessandro Romboli

Site Reliability Engineer at Würth Phoenix
My name is Alessandro and I joined Würth-Phoenix early in 2013. I have over 20 years of experience in the IT sector: For a long time I've worked for a big Italian bank in a very complex environment, managing the software provisioning for all the branch offices. Then I've worked as a system administrator for an international IT provider supporting several big companies in their infrastructures, providing high availability solutions and disaster recovery implementations. I've joined the VMware virtual infrastructure in early stage, since version 2: it was one of the first productive Server Farms in Italy. I always like to study and compare different technologies: I work with Linux, MAC OSX, Windows and VMWare. Since I joined Würth Phoenix, I could also expand my experience on Firewalls, Storage Area Networks, Local Area Networks, designing and implementing complete solutions for our customers. Primarily, I'm a system administrator and solution designer, certified as VMware VCP6 DCV, Microsoft MCP for Windows Server, Hyper-V and System Center Virtual Machine Manager, SQL Server, SharePoint. Besides computers, I also like photography, sport and trekking in the mountains.

Author

Alessandro Romboli

My name is Alessandro and I joined Würth-Phoenix early in 2013. I have over 20 years of experience in the IT sector: For a long time I've worked for a big Italian bank in a very complex environment, managing the software provisioning for all the branch offices. Then I've worked as a system administrator for an international IT provider supporting several big companies in their infrastructures, providing high availability solutions and disaster recovery implementations. I've joined the VMware virtual infrastructure in early stage, since version 2: it was one of the first productive Server Farms in Italy. I always like to study and compare different technologies: I work with Linux, MAC OSX, Windows and VMWare. Since I joined Würth Phoenix, I could also expand my experience on Firewalls, Storage Area Networks, Local Area Networks, designing and implementing complete solutions for our customers. Primarily, I'm a system administrator and solution designer, certified as VMware VCP6 DCV, Microsoft MCP for Windows Server, Hyper-V and System Center Virtual Machine Manager, SQL Server, SharePoint. Besides computers, I also like photography, sport and trekking in the mountains.

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive