Skip to content
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

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

Closed
carlbeechvuw opened this issue Jan 12, 2022 · 15 comments
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version

Comments

@carlbeechvuw
Copy link

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

  • ... $TmpStr=get-device -id $DeviceNode.Id | Get-ObjectProperty Comments
  •                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Get-ObjectProperty], XmlException
    • FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetObjectProperty

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

  • ... -device -id $DeviceNode.Id | Get-ObjectProperty -RawProperty Comments
  •                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Get-ObjectProperty], XmlException
    • FullyQualifiedErrorId : System.Xml.XmlException,PrtgAPI.PowerShell.Cmdlets.GetObjectProperty

[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.<>c__DisplayClass16_0.b__0()
at PrtgAPI.Request.ObjectEngine.ParseInvalidXml[T](Func1 action) at PrtgAPI.Request.ObjectEngine.GetObjectsXml(IXmlParameters parameters, Action1 responseValidator, Func2 responseParser, CancellationToken token) at PrtgAPI.PrtgClient.GetObjectPropertyRawInternal(GetObjectPropertyRawParameters parameters, String property) at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.<ProcessRecordEx>b__33_0(String p) at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.<>c__DisplayClass39_0.<WriteObjectWithProgressSafe>b__0() at PrtgAPI.PowerShell.Base.PrtgProgressCmdlet.WriteObjectWithProgress(Func1 obj)
at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.ProcessRawProperty(Func`2 getValue)
at PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action)
at System.Management.Automation.CommandProcessor.ProcessRecord()

@carlbeechvuw carlbeechvuw added the alleged-bug Bugs raised by people helpfully using the Bug Report template! label Jan 12, 2022
@lordmilko
Copy link
Owner

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
Copy link
Author

carlbeechvuw commented Jan 12, 2022

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
Copy link
Author

@lordmilko
Copy link
Owner

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
Copy link
Author

carlbeechvuw commented Jan 13, 2022

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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

Many thanks

@carlbeechvuw
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

carlbeechvuw commented Jan 13, 2022

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 lordmilko added bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version and removed alleged-bug Bugs raised by people helpfully using the Bug Report template! labels Jan 13, 2022
@lordmilko
Copy link
Owner

Thanks @carlbeechvuw,

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

@carlbeechvuw
Copy link
Author

Ah - ok many thanks - much appreciated!

@lordmilko
Copy link
Owner

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
Copy link
Author

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

Many thanks that's brilliant!

Carl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version
Projects
None yet
Development

No branches or pull requests

2 participants