lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

PrtgAPI Treating [ ] in Object Name As Wildcard Expression #255

Open Dreystein opened 2 years ago

Dreystein commented 2 years ago

Describe the bug

Hello,

get-sensor: Seems there is a Parsing Problem of the Name Property (maybe the device also). Maybe its a Problem with Brackets)

example is below

PRTG: PRTG Version PRTG Network Monitor 21.4.73.1656 x64 Operating SystemMicrosoft Windows Server 2019 Datacenter (10.0 Build 17763), 16 CPUs (16x x64 Model 63 Step 0), code page "Windows-1252", on VMware

Under some circumstances when get-sensor throw an error it will deliver all Sensors. When you alter the Data with a piped set-ObjectProperty all Sensor Data will be overwritten not only the one you tried too ...

But anyway thanks for this very good solution to access and chance the Data on PRTG. You made my day when i discovered this program.

Thanks Heiko

Steps to reproduce

[DBG]: PS Y:\>> get-sensor -Device $Dev
Name                         Id     Device               Group                     Probe      Status
----                         --     ------               -----                     -----       -----
PING                         24496  esxgi02              VMWare Hosts              Probe        Up            
esxgi02 Host Performance]    24497  esxgi02              VMWare Hosts              Probe        Up            
esxgi02 [Hardware Status]    24498  esxgi02              VMWare Hosts              Probe        Up            
HTTPS                        24501  esxgi02              VMWare Hosts              Probe        Up            

[DBG]: PS Y:\>> get-sensor -Name "esxgi02 [Hardware Status]"
<no result>

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

PSVersion      : 5.1.17763.2268
PSEdition      : Desktop
OS             : Microsoft Windows Server 2019 Datacenter
PrtgAPIVersion : 0.9.16
Culture        : de-DE
CLRVersion     : .NET Framework 4.7.2 (461814)
PrtgVersion    : 21.4.73.1656
PrtgLanguage   : english.lng

Additional context

No response

lordmilko commented 2 years ago

Correction to my earlier message, this is actually as a result of how PowerShell treats wildcards.

Typically when people talk about "wildcard characters" in PowerShell are usually referring to the * character, which is the only character that is used in 99.99% of cases, and indeed is the only character PrtgAPI supports in its wildcard processing logic. However, PowerShell actually supports a whole range of wildcard characters, including the [ ] combination. As a result, When you filter for a name containing text inside [ ] PowerShell's wildcard filter (invoked by PrtgAPI) filters out the result returned from PRTG, which isn't what you want in this scenario.

If you absolutely must filter for this sensor by name, your best bet would be to do it like so

flt name eq "esxgi02 [Hardware Status]" | Get-Sensor

For more information on creating custom filters, please see the wiki

lordmilko commented 2 years ago

I've had a look into this a little further and have found a way PrtgAPI may be able to work around this in a future release; for the meantime however you should be able to get by by using the workaround described above

Dreystein commented 2 years ago

Hi there,

thanks for your efforts, i think my approach was anyway wrong and i solved the problem of searching for a known sensor through the sensors id. this approach makes more sense because of the clarity Identity of the Sensor.

And thank you again for your great api. it makes many of my ideas possible

Regards Heiko