Closed olsonnn closed 6 years ago
sensor type = xml rest custom beta
Get-Sensor -Id 17835 | Set-ObjectProperty -RawProperty query_ -RawValue "/whatever = = " seems to work fine
Hi @olsonnn,
Can you please confirm what the exact value of your REST Query property is in the PRTG UI (replace any sensitive information with dummy values) and also display the output of $error[0].Exception.Stacktrace
after encountering the exception? Then, can you also check for any inner exceptions and any inner inner exceptions ($error[0].Exception.InnerException
/ $error[0].Exception.InnerException.Stacktrace
) and so on; this will allow me to identify where exactly an issue is occurring
When I assign the string "/api/Queues?subscriptionId=blabla=blabla=blabla" as the value of a REST Query I am successfully able to retrieve it with both Get-ObjectProperty -RawProperty query_
as well as see it defined on Get-ObjectProperty -Raw
here it is:
query : /api/Queues?subscriptionId=<id>&resourceGroup=<name>&resourceName=<name>&TenantId=<id>&queueName=<queue>
i have no idea what to do with:
can you also check for any inner exceptions and any inner inner exceptions ($error[0].Exception.InnerException / $error[0].Exception.InnerException.Stacktrace) and so on; this will allow me to identify where exactly an issue is occurring
so please guide me here... what to do exactly
They are PowerShell commands. Execute them after encountering the exception
C:\> $error[0].Exception.Stacktrace
C:\> $error[0].Exception.InnerException
C:\> $error[0].Exception.InnerException.Stacktrace
I was successfully able to replicate the issue using the query you provided; I will look into this issue and get back to you
Ah nice! so this does report something as you found out already:
PS C:\WINDOWS\system32> $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 System.Xml.Linq.XDocument.Parse(String text, LoadOptions options) at PrtgAPI.Helpers.XDocumentHelpers.SanitizeXml(String str) at PrtgAPI.PrtgClient.GetObjectPropertyRaw(Int32 objectId, String property) at PrtgAPI.PowerShell.Base.PrtgProgressCmdlet.WriteObjectWithProgress(Func
1 obj)
at PrtgAPI.PowerShell.Cmdlets.GetObjectProperty.ProcessRecordEx()
at PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action)
at System.Management.Automation.CommandProcessor.ProcessRecord()
`
Hi @olsonnn,
I have successfully identified the cause of the issue. By default, the PRTG endpoint api/getobjectproperty.htm
does not escape invalid XML characters (such as ampersands) unless you specify the parameter show=text
. PrtgAPI does not currently do this. As such, when you attempt to query the property via the -RawProperty
parameter you will encounter an exception if the property value contains any illegal character. The -Raw
parameter executes a different request to retrieve its values which does escape invalid XML characters correctly, hence why it does not have any issue.
This issue will be corrected in PrtgAPI 0.9.0, due out in a month or two. In the meantime, you can access the query
property by simply doing
(Get-Sensor -Id 1234 | Get-ObjectProperty -Raw).query
Regards, lordmilko
ok last question: how to do this: i want the sensor name in the part of the query: but didn't succeed
Get-Sensor -Id 17836 | Get-ObjectProperty -RawProperty name -OutVariable queue | Set-ObjectProperty -RawProperty query -RawValue "/api/Queues?subscriptionId=$queue"
tells me: Set-ObjectProperty : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. any recommendations?
Hi @olsonnn,
There are a few issues with your above command
Sensor
objects already have a Name
property, so there is no need to execute a Get-ObjectProperty
request.Get-ObjectProperty
request. Name
is also a supported object property, so you can simply do Get-ObjectProperty Name
instead of having to specify the raw property.Get-ObjectProperty
you also interrupt the pipeline, preventing the Sensor
object from being piped to Set-ObjectProperty
The correct way to do this would either be to split this over two lines, or loop on the Sensor
object and access the Name
property inside the -RawValue
expression
# Two lines
$sensor = Get-Sensor -Id 17836
$sensor | Set-ObjectProperty -RawProperty query_ -RawValue "/api/Queues?subscriptionId=$($sensor.Name)"
# One line
Get-Sensor -Id 17836 | foreach { $_ | Set-ObjectProperty -RawProperty query_ -RawValue "/api/Queues?subscriptionId=$($_.Name)" }
Please let me know if you have any issues
That was exactly what i needed! works! Is there also a way to prevent the "are you sure what you're doing?" :)
Specify -Force
Hi @olsonnn,
PrtgAPI 0.9.0 has now been released! Performing Get-ObjectProperty -Property / -RawProperty
on any property should now work, regardless of whether it contains any invalid characters
To update to the latest version of PrtgAPI, simply run
Update-Module PrtgAPI
and reopen your PowerShell. Please be aware of any breaking changes that may affect you before considering upgrading.
Please let me know if you have any issues
Regards, lordmilko
Thanks for fixing! will test asap!
Issue solved! tested successfully
when i do: Get-Sensor -Id 17835 | Get-ObjectProperty -RawProperty query_
i get Get-ObjectProperty : '=' is an unexpected token. The expected token is ';'. Line 4, position 86. At line:1 char:24
as my "query" field contains multiple = character...
PS C:\WINDOWS\system32> Get-Sensor -Id 17830 | Get-ObjectProperty -Raw
query : /api/Queues?subscriptionId=blabla=blabla=blabla