lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Get-ObjectProperty Comments raises an error - suspected due to latest PRTG update? #262

Closed carlbeechvuw closed 2 years ago

carlbeechvuw commented 2 years ago

Describe the bug

In my program, I have the code:

.... get-device -id $DeviceNode.Id | Get-ObjectProperty Comments

This has worked up until the last PRTG update which came out just before Christmas.

Now, when executed I get the error:

Get-ObjectProperty : ' ' is an unexpected token. The expected token is ';'. Line 5, position 10. At ....

The prtg object definately has a comment.

Steps to reproduce

As noted in the error.

What is the output of 'Get-PrtgClient -Diagnostic'?

PSVersion      : 5.1.14409.1018
PSEdition      : Desktop
OS             : Microsoft Windows Server 2012 R2 Standard
PrtgAPIVersion : 0.9.16
Culture        : en-NZ
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 21.4.72.1649
PrtgLanguage   : english.lng

Additional context

Error and stack trace:

$error[0] Get-ObjectProperty : ' ' is an unexpected token. The expected token is ';'. Line 5, position 10. At line:1 char:33

[DBG]: PS D:\MEDIA\VMAD\VMAD\PRTG_SCRIPTS>> $error[0].Exception.StackTrace at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos) at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) at System.Xml.XmlTextReaderImpl.FinishPartialValue() at System.Xml.XmlTextReaderImpl.get_Value() at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) at PrtgAPI.Request.ObjectEngine.<>cDisplayClass16_0.b0() at PrtgAPI.Request.ObjectEngine.ParseInvalidXml[T](Func1 action) at PrtgAPI.Request.ObjectEngine.GetObjectsXml(IXmlParameters parameters, Action1 responseValidator, Func`2 responseParser, CancellationToken token) at PrtgAPI.PrtgClient.GetObjectPropertyRawInternal(GetObjectPropertyRawParameters parameters, String property) at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.b33_0(String p) at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.<>cDisplayClass39_0.b__0() at PrtgAPI.PowerShell.Base.PrtgProgressCmdlet.WriteObjectWithProgress(Func1 obj) at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.ProcessRawProperty(Func2 getValue) at PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action) at System.Management.Automation.CommandProcessor.ProcessRecord()

lordmilko commented 2 years ago

Hi @carlbeechvuw,

Can you please do

Set-PrtgClient -LogLevel -All

... $TmpStr=get-device -id $DeviceNode.Id | Get-ObjectProperty Comments -Verbose

and then provide the verbose output from Get-ObjectProperty? Please obfuscate your server/username/passhash in the API request prior to posting on GitHub

carlbeechvuw commented 2 years ago

Hi

Set-PrtgClient -LogLevel -All Set-PrtgClient : Cannot bind parameter 'LogLevel'. Cannot convert value "-All" to type "PrtgAPI.LogLevel". Error: "Unable to match the identifier name -All to a valid enumerator name. Specify one of the following enumerator names and try again: None, Trace, Request, Response, All"

So I'm assuming '-All' should be 'All'

Information is attached as file.

carlbeechvuw commented 2 years ago

PRTG_Info_CommentError.txt

lordmilko commented 2 years ago

Hi @carlbeechvuw,

Sorry, my mistake - yes it should be All rather than -All

It appears you did Get-ObjectProperty -Verbose rather than Get-ObjectProperty Comments -Verbose

Are you able to provide the output from

get-device -id 26645  | Get-ObjectProperty Comments -Verbose
carlbeechvuw commented 2 years ago

Hi

Sorry - my mistake - here's the output... (a whole lot more manageable! :-) )

Thanks

VERBOSE: Get-ObjectProperty: Synchronously executing request https://xxxx/api/getobjectstatus.htm?id=26645&name=comments&show=text&username=xxxx&passhash=xxxx
VERBOSE: Get-ObjectProperty: <?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<version>21.4.72.1649+</version>
<result>xxxx 
Desc: xxxx  
IP: xxxx 
Environment: Development 
OS: Red Hat Enterprise Linux 
Physical or Virtual: Virtual </result>
</prtg>
Get-ObjectProperty : ' ' is an unexpected token. The expected token is ';'. Line 5, position 10.
At line:1 char:25
+ get-device -id 26645  | Get-ObjectProperty Comments -Verbose
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ObjectProperty], XmlException
    + FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetObjectProperty
lordmilko commented 2 years ago

It's possible one of the values you omitted from the output is responsible for the exception. Are you able to try and retrieve the comments of a device with a simpler set of comments on it (in particular, does not include any symbol characters) and then try and gradually add 1 line at a time from device 26645

lordmilko commented 2 years ago

More broadly, if you can provide the verbose output of a device whose comments you don't need to redact that also reproduces the issue I can take over the investigation from my end

carlbeechvuw commented 2 years ago

Hi - ok many thanks for the advice I'll give that a go over the next 24 hours...

Many thanks

carlbeechvuw commented 2 years ago

Hi Sorry - looks like I've located the issue... its down to the comment containing a '&' character ( ... T&D server.... ) Once I took this out, it worked correctly... I'll ammend my code to stop this coming through - or is there an escape character that I could use do you think?

Many thanks for your help on this one... much appreciated!

Carl.

lordmilko commented 2 years ago

Regardless of what characters you have PrtgAPI should be able to parse it without issues. I am able to request a comment containing a "&" character in it

Are you able to provide the full text of a comment that includes a & where you can reproduce the issue

carlbeechvuw commented 2 years ago

Hi Yep - now I know what to look for, I've been able to reproduce without redacting the comment text...

Does this help?

Cheers Carl.

get-device -id 26645  | Get-ObjectProperty Comments -Verbose
VERBOSE: Get-ObjectProperty: Synchronously executing request https://xxxx/api/getobjectstatus.htm?id=26645&name=comments&show=text&username=xxxx&passhash=xxxx
VERBOSE: Get-ObjectProperty: <?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<version>21.4.72.1649+</version>
<result>testing 
Desc: T&D server for testing
</result>
</prtg>
Get-ObjectProperty : ' ' is an unexpected token. The expected token is ';'. Line 5, position 10.
At line:1 char:25
+ get-device -id 26645  | Get-ObjectProperty Comments -Verbose
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ObjectProperty], XmlException
    + FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetObjectProperty
lordmilko commented 2 years ago

Thanks @carlbeechvuw,

I was successfully able to reproduce this issue and am now investigating

carlbeechvuw commented 2 years ago

Ah - ok many thanks - much appreciated!

lordmilko commented 2 years ago

Hi @carlbeechvuw,

I have pushed a new pre-release version of PrtgAPI which should include a fix for this issue

Are you able to try using the manual installation instructions to run the latest pre-release and advise whether the issue is now resolved?

Regards, lordmilko

carlbeechvuw commented 2 years ago

Hi - Yep I can confirm the update works :-)

Many thanks that's brilliant!

Carl.