-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Xml.XmlException: ReadElementContentAs() methods cannot be called on an element that has child elements #334
Comments
In order to diagnose this issue, are you able to provide the XML of the sensor in question? In C# you can do client.LogLevel = LogLevel.Request | LogLevel.Response;
client.LogVerbose (sender, args) => {
Debug.WriteLine(args.Message);
};
client.GetSensor(objectId); when it fails, the XML will be emitted to the debug window. Can you ensure there is no sensitive content in this XML and copy and paste this here? |
Just want to make sure I'm looking at the right output... It looks more like HTML from the sensor page than it does XML that would be returned by the native PRTG API. The scrollback in my window went to 13000 lines and it all looked roughly like this., so I just picked an arbitrary number of lines at the end to copy. I was also getting the same output for sensors that did not get a parsing error.
|
I found a workaround but still not sure what I was doing wrong. I use a recursive method to check if an object ID is a sensor, and if not get the children of that object. It seemed like every time the recursive method was called, the number of instances of below would increase. So the first time through the method I only got one of the below lines, but that increased by one each time I called client.GetSensor again. Eventually after 30 or so I would see that the responses from PRTG were empty, though I didn't capture a sample of that output. If it's needed I can probably recreate the issue.
The debug information suggested that it was actually calling that many times, as I would see multiple printouts for the requested object. I updated my method to instead create a new instance of PrtgClient for each iteration of the method. I hacked this together and it seems to function fine. Each time client.GetSensor is called, only one instance of the "synchronously executing request" line shows in the debug logs. If I take out the client = new PrtgClient line, then its back to its old behaviour.
|
Hi @moffitj, Apologies for not responding to this earlier. The HTML output you provided 2 weeks ago looks like the response you would get when retrieving channel properties. When you call |
Hi. Is there a solution for this problem available? I also have the problem now with get-sensor :( get-sensor : ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 33. |
Hi @wiede78, Can you do Set-PrtgClient -LogLevel Response and then execute |
` get-sensor : ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 33.
At line:2 char:26
get-group "HS-Hosting" | get-sensor "SSL Certificate"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Sensor], XmlException
+ FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetSensor 2.) Name Id Device Group Probe Status
---- -- ------ ----- ----- ------
SSL Certificate 56154 xxx.de HostEurope Azure-Tier2 (vmapr... Up 3.) get-sensor : ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 33.
At line:4 char:1
get-sensor -Id 56154
~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Sensor], XmlException
+ FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetSensor` 4.) Clone-Object : ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 33.
At line:1 char:60
... ificate" | Clone-Object -DestinationId $((get-device $webpag).id) | ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Object], XmlException
+ FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.CloneObject ` |
Woops, sorry - I forgot to say that you also need to specify the Are you able to provide the output of Set-PrtgClient -LogLevel Response
Get-Sensor -Id 56154 -Verbose |
hmm, strange...today it works fine. maybe a problem with the PRTG Server self during the mass import!? Sorry for the trouble....and also many thanks for this Powershell Module, it makes my life with PRTG so much easier 👍 🥇 |
Can you please provide the verbose output when you can next reproduce this issue, thanks |
I think this is what you're looking for. Request is executed and the content received back is the single debug line. This causes the XmlException. I added functionality to keep a count of how many times this happens and retry. After it tries again, it is successful. Could this be a timeout response that isn't detected as such since a response is technically received?
|
Thanks @moffitj, It seems the issue is that PRTG is providing an illegal response: <HTML><BODY class="no-content"><B class="no-content">OK</B></BODY></HTML> It is completely illegal for PRTG to respond like this. Requests against their XML API should return an XML response. I could amend PrtgAPI to throw an error saying that PRTG didn't return anything, or retry the request and see if it works the second time, however as I'm leaning towards saying this is an issue with PRTG, and am no longer actively developing PrtgAPI, I am inclined to say this will be a "won't fix" and would recommend retrying the request in the event you see this is happening |
You may potentially want to try your luck with Paessler support, since, even if you weren't using PrtgAPI, their API endpoint is responding with HTML instead of XML |
Describe the bug
When calling PrtgApi.GetSensor, I sometimes get this error.
The specific object that I called GetSensor on is definitely a sensor and doesn't have any child elements. If I rerun my application, then this specific Sensor will probably be fine (I've had no repeats), but some other sensor will get this error.
Steps to reproduce
What is the output of 'Get-PrtgClient -Diagnostic'?
Additional context
No response
The text was updated successfully, but these errors were encountered: