lordmilko / PrtgAPI

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

Problem with get-sensor -filter on empty return #403

Open JR-Otava opened 1 week ago

JR-Otava commented 1 week ago

Describe the bug

$Objectparent | Get-Sensor -Filter $Local:filter -Recurse:$recurse

2024-09-12 03:48:57Z [Error ] : PRTGCFindSensor: Get-Sensor[] returned XML Exception(PRTG Bug), [

Property Operator Value                                    FilterMode
-------- -------- -----                                    ----------
    Name Contains XXXXXXX-IFACE_restored1027                Normal

]Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index VERBOSE: Get-Sensor: Synchronously executing request

https://prtgserver/api/table.xml?content=sensors&columns=objid,name,probe,group,favorite,lastvalue,device,downtime,downtimetime,downtimesince,uptime,uptimetime,uptimesince,knowntime,cu
msince,lastcheck,lastup,lastdown,minigraph,schedule,basetype,baselink,notifiesx,intervalx,access,dependency,position,status,comments,priority,message,parentid,tags,type,active&count=*&filter_name=@
sub(XXXXXXX-IFACE_restored1027)&username=xxxx&passhash=YYYY

result using rest tool

<?xml version="1.0" encoding="UTF-8" ?>
<sensors totalcount="0" listend="1">
    <prtg-version>24.3.98.1210</prtg-version>
</sensors>

Steps to reproduce

Unfortunately hard to reproduce with a direct query

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

PSVersion      : 5.1.17763.6054
PSEdition      : Desktop
OS             : Microsoft Windows Server 2019 Datacenter
PrtgAPIVersion : 0.9.19
Culture        : en-US
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 24.3.98.1210
PrtgLanguage   : english.lng

Additional context

perhaps it does not like '_' ?

Or did our friends at Paessler change something in the search routine ?

lordmilko commented 1 week ago

After reproducing the crash can you please provide the output of $error[0].Exception.StackTrace. This will tell me where in the code the crash is happening

JR-Otava commented 1 week ago

Hi.. Thanks for getting back to me.. This is all I get:

   at System.Collections.ArrayList.set_Item(Int32 index, Object value)
   at CallSite.Target(Closure , CallSite , Object , Object , Object )
   at PRTGCAddCachedSensors(Closure , FunctionContext )

But it might be operator error.. Let me get back to you...

lordmilko commented 1 week ago

This indicates the bug is in your code, somewhere in your PRTGCAddCachedSensors function, rather than in PrtgAPI. PrtgAPI does not have a function called PRTGCAddCachedSensors

Consider inspecting $error[0].ScriptStackTrace after reproducing the error to see exactly where in your script the issue is occurring