What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom XML sensor error XML: Junk after document element </prtg> -- JSON

Votes:

0

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?

custom-sensor powershell script xml

Created on Jul 9, 2021 9:01:40 AM

Last change on Jul 9, 2021 10:17:55 AM by  Felix Wiesneth [Paessler Support]



9 Replies

Votes:

0

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

Write-Host "<?xml version=`"1.0`" encoding=`"UTF-8`" ?>
<prtg>
    <result>
        <channel>Clusternode State</channel>
            <value>$numState</value>
    </result>
</prtg>"

Kind regards

Felix Wiesneth - Team tech Support

Created on Jul 12, 2021 9:06:40 AM by  Felix Wiesneth [Paessler Support]



Votes:

0

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.

Created on Jul 12, 2021 10:09:56 AM



Votes:

0

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

Created on Jul 12, 2021 10:25:42 AM



Votes:

0

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

Created on Jul 12, 2021 1:55:52 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

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....

Created on Jul 12, 2021 3:04:37 PM



Votes:

0

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

Created on Jul 15, 2021 3:03:06 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

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

Created on Jul 16, 2021 9:42:31 AM



Votes:

0

Any news on the status of the issues handling the output?

Created on Jul 20, 2021 9:52:42 AM



Votes:

0

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 [email protected] and include PAE2144679 in the subject. Thank you in advance.


Kind regards
\ Felix Wiesneth - Team Tech Support

Created on Jul 20, 2021 4:13:47 PM by  Felix Wiesneth [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.