Applications Systems

SAM Server Clock Drift (PowerShell) template returns scripting error if clock drift is small, negative number

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.

First published date

8/29/2019 1:55 PM

Last published date

12/2/2021 4:49 PM

Overview

This article describes how to resolve an issue with the Server Clock Drift (PowerShell) template in SAM if it 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.

Product section

Server Application Monitor

Cause

The following code throws an error if the clock drift is a very small negative number, such as -0.001:
$Skew = $remoteToSolarSkew.TotalSeconds - $ntpToSolarSkew;
        $symb=$Skew.ToString().Substring(0,1);
        if ($symb -eq "-") 
        {
            $stat=[math]::round($Skew,2);
            $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: $symb $stat s.";
            Write-Host "Statistic: $stat";
            exit 0;
        }
For example, if the $Skew is -0.001, the returned script will look like this:
Message: Clock drift: 0.
Statistic: 


 

Resolution

This template was updated in SAM 6.4 to fix this issue. If you started with a fresh install of SAM 6.4 or later, you should already have the updated template.

If you began using an earlier version of SAM, note that only AppInsight templates are updated automatically during upgrades. Standard SAM templates like Server Clock Drift are not updated to avoid overwriting custom changes.

To resolve this issue, you can either:
$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: -$tmp s.";
            Write-Host "Statistic: $tmp";
            exit 0;
        }
        else
        {
            Write-Host "Message: Clock drift: $stat s.";
            Write-Host "Statistic: $stat";
            exit 0;
        }