After upgrading to v21.2.68.1492 x64, my custom Powershell XML sensors are starting to give the above error. After logging the result of the script, after the </prtg> a zero suddenly appears, that was not there in the previous PRTG version. The zero is obviously causing the error, but it is not displayed when I run the Powershell script from the commandline. It's almost as if PRTG adds this as a sort of resultcode after running the script...
The following script:
param($paramList) $params = $paramList.Split(" ") if ($params.Count -gt 0) { if ($params.Count -eq 1) { $params += "SAN-CLUSTER" } Import-Module FailoverClusters -ErrorAction Stop $status = Get-ClusterNode $params[0] -cluster $params[1] | ft State -HideTableHeaders | out-string $status = $status -replace "`t|`n|`r| ","" $numState = 0; switch($status) { "Up" { $numState = 1 break } "Down" { $numState = 2 break } "Joining" { $numState = 3 break } "Paused" { $numState = 4 break } } $xml_txt = @" <?xml version=`"1.0`" encoding=`"UTF-8`" ?> <prtg> <result> <channel>Clusternode State</channel> <value>$numState</value> </result> </prtg> "@ [Console]::WriteLine($xml_txt) }
returns the following output:
<?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<result>
<channel>Clusternode State</channel>
<value>1</value>
</result>
</prtg>
and there is no extra zero after </prtg>
The log result from PRTG gives the following output:
<?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<result>
<channel>Clusternode State</channel>
<value>1</value>
</result>
</prtg>
0
containing the extra zero
Is this a bug in the latest version?
Article Comments
On a system with PRTG Monitor v20.3.61.1649, using the same script the sensor output logging does not give the extra zero, so it must be a change in the way the Powershell is handled by the newer version sensor/PRTG.
Jul, 2021 - Permalink
Hi Felix,
Thanks for the advise, I've changed the code, but it does not solve the problem.
Could it be that I use an invoke script to run the main script? As the PRTG software is 32-bit, and my servers are using 64-bit Powershell I had to invoke the 64-bit version to make the script work. Although when using the invoke the output still is the same as without it, but could this cause the extra 0 in the new version?
The invoke64bit.ps1 Powershell script is as follows:
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64")
{
if ($myInvocation.Line)
{
&"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
}
}
else
{
$command = $args[0]
$params = ""
for ($i = 1; $i -lt $args.Count; $i++)
{
$params = $params + $args[$i]
if ($i -ne ($args.Count - 1))
{
$params = $params + " "
}
}
&"$env:WINDIR\system32\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -file "$command" $params
}
and the call made in PRTG monitor under 'settings' is as follows:
EXE/Script: Invoke64bit.ps1
Parameters: """C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\GetClusterNodeStatus.ps1""" SAN-CLUSTER
Jul, 2021 - Permalink
Hi there,
to run a 64-bit PowerShell with PRTG I would recommend to take a look at our KB-article for this. It could be possible that your script returns the extra 0 and this will lead to the issue.
Kind regards
Felix Wiesneth - Team Tech Support
Jul, 2021 - Permalink
Hello Felix,
I did already use this article when I experienced the initial 32/64-bit Powershell issues. As you can see in my latter Invoke64bit.ps1 script it uses the same code as in your mentioned article. That said, it worked flawless with the previous PRTG versions....
Jul, 2021 - Permalink
Hello,
we encountered that there are some issues with the handling of the output. It might be possible that write-output instead of write-host works. Please check if this works for you.
Kind regards
Felix Wiesneth - Team Tech Support
Jul, 2021 - Permalink
Hello Felix,
I've replace the write-host command with write-output and restarted the server. Unfortunately it does not change the situation, the zero is still added.
Regards gesture
Jul, 2021 - Permalink
Hello,
Since it seems I need to take a closer look into this, I would kindly ask you to open a support ticket with both scripts. Just send a mail to support@paessler.com and include PAE2144679 in the subject. Thank you in advance.
Kind regards
\
Felix Wiesneth - Team Tech Support
Jul, 2021 - Permalink
Hello there,
I recreated the output from your script in this version and couldn't reproduce the issue. In addition the logs for this sensor seems to be fine.
However I would recommend to use write-host for output. This will shorten your script. For example the code lines could look like this
Kind regards
Felix Wiesneth - Team tech Support
Jul, 2021 - Permalink