Server Clock Drift (PowerShell)

The template allows you to check the server clock drift by comparing the target server time with internet time.

Prerequisites: None.

Credentials: Administrator on the target server.


Component Monitors

Clock Drift (Internet Time Service)

This monitor shows the clock drift between the target client (target node) and the target Internet Time Service server (argument) in seconds. Positive values of clock drift in the message field indicates that the time on the target server is running faster than it should. Negative values indicate time on the target server is running slower than it should. This monitor also returns the current time on the target server. 

In the Scripts Arguments field you should provide the hostname of the time server. Time servers can be found here: http://tf.nist.gov/tf-cgi/servers.cgi.

Following is an example of how to use the Scripts Arguments field:

time.nist.gov

Clock Drift (NTP)

This monitor shows the clock drift between the target client (target node) and the target NTP server (argument) in seconds. Positive values of clock drift in the message field indicates that time on the target server is running faster than it should. Negative values indicates time on the target server is running slower than it should.

In the Scripts Arguments field you should provide the hostname of the NTP server. Time servers can be found here: http://www.pool.ntp.org/.

Following is an example of how to use the Scripts Arguments field:

pool.ntp.org


Portions of this document were originally created by and are excerpted from the following sources:

Microsoft Corporation, “Microsoft Support:  Windows Management Framework Core,” Copyright Copyright 2012 Microsoft Corporation.  All rights reserved. Available at http://support.microsoft.com/kb/968930.
PowerShell.com, “Set Internet Time,” Copyright Copyright 2011-2012 PowerShell.com.  All rights reserved. Available at
http://powershell.com/cs/media/p/9869.aspx.
Cardiff University, “Using the Time Service,” Copyright Copyright 2012
.  All rights reserved. Available at http://www.cs.cf.ac.uk/Dave/PERL/node174.html.

Last updated: 11/19/2014 (Rounding error fixed)

Anonymous
  • I wanted to get the Time Difference to be  Printed on the Alert Email. I have configured the Clock Drift(PowerShell) Monitoring the Domain Controller

  • Can some One help to get the Time Difference should be printed on the Alert Email ? 

  • If the clock drift is a small negative number, the SAM Server Clock Drift (PowerShell) template returns an invalid result, the application monitor shows an Unknown status, and the following message may appear: "Scripting Error: Script does not contain the expected parameters or is improperly formatted. 'Statistic' missing." This issue was fixed in SAM 6.4 but if you started with SAM 6.3 or earlier, note that most templates are not automatically updated during upgrades. If you receive this error, download the latest version of the template, as attached to this post. Click here​ for another workaround.

    Note: SolarWinds recommends that you check THWACK periodically for updates to out-of-the-box (OOTB) templates included with SAM. With the exception of AppInsight templates, application monitor templates are not updated automatically during upgrades to avoid overwriting any custom changes that may have been made to templates.

  • hi cczech  ,

         I think it works for me. emoticons_happy.png

    Initially, I was getting an error for few nodes so I added them to a new monitor to observe the results if the monitor is showing the same error for those nodes.

    But as of now they are in green State. I am putting them under observation for 24 hours.

    Thank you so much!!

    Regards

    Rahul Bajpai

  • I've modified the original code to allow for running this default SolarWinds monitor against the SolarWinds server itself, or systems where the Agent has been installed.  This was previously not an option with the script provided out of the box...

    [code]

    $ntpServer = $args[0];

    if ( !$ntpServer )

    {

    Write-Host "Message: Can't find ""ntpServer"" argument. Check documentation.";

    exit 1;

    }

    $ntpQuery  =  Invoke-Expression "w32tm /monitor /computers:$ntpServer" | Out-String;

    $findSkew = [regex]"(?:NTP\: )(?<Value>/?[^s]+)";

    If (($ntpQuery -match $findSkew))

    {

        $ntpToSolarSkew = $Matches['Value'];

        $Error.Clear();

        try

        {

            $params = @{

            'Class' =  'Win32_UTCTime'

            }

            if ($computer) {

            $params += @{'ComputerName' = $Computer}

            switch ($computer){

                "$env:COMPUTERNAME" {break}

                'localhost' {break}

                '.'   {break}

                default {$params += @{'Credential' = $CREDENTIAL}}

                }

            }

            $remoteServerTime = Get-WmiObject @params

        }

        catch

        {

            Write-Host "Message: Unable to Get-WmiObject Win32_UTCTime on remote client. $($Error[0])";

            exit 1;

        }

        $localTime = $(Get-Date).ToUniversalTime();

        $remoteToSolarSkew = New-TimeSpan $localTime $(Get-Date -year $remoteServerTime.Year -month $remoteServerTime.Month -day $remoteServerTime.Day -hour $remoteServerTime.Hour -minute $remoteServerTime.Minute -second $remoteServerTime.Second);

        If ($remoteToSolarSkew)

        {

            $Skew = $remoteToSolarSkew.TotalSeconds - $ntpToSolarSkew;

            $stat=[math]::round($Skew,2);

            $symb=$stat.ToString().Substring(0,1);

            if ($symb -eq "-")

            {

                $tmp=$stat.ToString().Remove(0,1);

                Write-Host "Message: Clock drift: $stat.";

                Write-Host "Statistic: $tmp";

                exit 0;

            }

            else

            {

                $stat=[math]::round($Skew,2);

                Write-Host "Message: Clock drift: $stat s.";

                Write-Host "Statistic: $stat";

                exit 0;

            }

        }

        Else

        {

            Write-Host "Message: Unable to Get-WmiObject Win32_UTCTime";

            exit 1;

        }

    }

    Else

    {

        Write-Host "Message: Unable to query NTP server $ntpServer.";

        exit 1;

    }

    [/code]