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

EXEXML Script problem - Hyper-V Replication Status

Votes:

0

I understand that custom scripts are not supported, I am just trying to figure out why one server is working but the other isn't.

So we have 2 monitoring servers (different sites) We monitor the Hyper-V replication to the same host. Both version of PRTG are 21.2.68.1492 and both running windows server 2012 r2 with .Net 4.8.

I ran this script on both servers under an elevated powershell x86 command and they generate the xml properly.


#Script for Getting Primary Replication Percent Successful
# Arthur:  Todd Kisida, [email protected]
#Takes list of servers in quote delimited by comma as a parameter
#Returns XML for PRTG Custom Advanced Sensor
#The Value returned for each VM is the percentage of successful replication cycles.
param(
[string]$Hypervservers
)
$ErrorActionPreference = "SilentlyContinue"
#start writing in XML
Write-host '<?xml version="1.0" encoding="UTF-8"?>'
Write-Host 	"<prtg>"
#Split the parameter into list of servers
$ServerList = $Hypervservers.Split(",")
foreach ($Hypervserver in $ServerList) {
	#I had issues getting the remote server data unless I opened the remote session to the specific server I was getting the data about.
	#Open a new remote PS session
	$Session = New-PSSession -computername $Hypervserver
	Import-PSSession $Session -Module Hyper-V -warningaction "SilentlyContinue" >$null
	#Get the replication data
	$VMReplication = Measure-VMReplication  -computername $Hypervserver  -ReplicationRelationshipType Simple | select VMname,SuccessfulReplicationCount,MissedReplicationCount
	#Write the data for each VM as a PRTG channel
	foreach ($Name in $VMReplication) {
		#I couldn't get PRTG to display the percent with only 2 decimal places, so I rounded here
		$AvgSuccess = [math]::Round(($Name.SuccessfulReplicationCount / ($Name.SuccessfulReplicationCount + $Name.MissedReplicationCount))*100,0)
		$VM = $Name.VMName
		#The Channel
		Write-Host 	"<result>"
					"<channel>$VM</channel>"
					"<unit>Percent</unit>"
					"<float>1</float>"
					"<decimalMode>2</decimalMode>"
					"<value>$AvgSuccess</value>"
					"<LimitMinWarning>80</LimitMinWarning>"
					"<LimitMinError>70</LimitMinError>"
					"<LimitMode>1</LimitMode>"
					"</result>"
	}
	#Close the remote PS session so it can be opened to the next host
	Remove-PSSession $Session
}
#Close the XML
Write-Host 	"</prtg>"
#Exit code 0 so PRTG knows the script ran successfully
Exit 0

But when I add it to prtg as a sensor, one of the server is missing some of the data.

debug Output from PRTG the working server :

<prtg>
<result>
<channel>Server1</channel>
<Unit>Percent</Unit>
<Float>1</Float>
<DecimalMode>2</DecimalMode>
<value>100</value>
<LimitMinWarning>80</LimitMinWarning>
<LimitMinError>70</LimitMinError>
<LimitMode>1</LimitMode>
</result>
<result>
<channel>Server2</channel>
<Unit>Percent</Unit>
<Float>1</Float>
<DecimalMode>2</DecimalMode>
<value>100</value>
<LimitMinWarning>80</LimitMinWarning>
<LimitMinError>70</LimitMinError>
<LimitMode>1</LimitMode>
</result>
</prtg>

Here is the debug output of the PRTG server that isn't working :

<channel>Server1</channel>
<unit>Percent</unit>
<float>1</float>
<decimalMode>2</decimalMode>
<value>100</value>
<LimitMinWarning>80</LimitMinWarning>
<LimitMinError>70</LimitMinError>
<LimitMode>1</LimitMode>
</result>
<channel>Server2</channel>
<unit>Percent</unit>
<float>1</float>
<decimalMode>2</decimalMode>
<value>100</value>
<LimitMinWarning>80</LimitMinWarning>
<LimitMinError>70</LimitMinError>
<LimitMode>1</LimitMode>
</result>

As you can see the <prtg> <result> and </prtg> are missing.

And the error message is "XML: Junk after document element </channel> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)"

What would cause this?

BTW. This started to happen after the update to 21.2.68.1492. I had to recreate the Sensor on the working server because it had stop working and I repeated the same steps on the server that isn't working.

exexml hyper-v prtg-script

Created on Jul 6, 2021 6:49:53 PM

Last change on Jul 7, 2021 6:49:51 AM by  Felix Wiesneth [Paessler Support]



Replies

Nobody has replied yet


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.