lordmilko / PrtgAPI

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

Get-Sensor from pipeline, dropping filter_parentid from request #10

Closed sprkbrn closed 6 years ago

sprkbrn commented 6 years ago

Good day,

Having an issue with populating a sensor for a single group. For some reason it pulls all sensors instead. It appears to occur only with this particular group, as far as I see the group is the same as our others. Any further assistance would be greatly appreciated.

I believe the issue originates from this line of the beneath log. I can't figure out why it drops the "count=*&filter_parentid=46827&" from the request, causing it to pull all the sensors down from PRTG.

VERBOSE: Get-Sensor: Synchronously executing request 
https://prtg-app/api/table.xml?content=sensors&columns=probe,group,favorite,lastvalue,device,downtime,downtimetime,downtimesince,uptime,uptimetime,uptimesince,knowntime,cumsince,lastcheck,lastup,lastdown,minigraph,schedule,basetype,baselink,parentid,notifiesx,interval,intervalx,access,dependency,position,status,comments,priority,message,type,tags,active,objid,name&count=*&&username={redacted}&passhash={redacted}

brokenlog.txt

lordmilko commented 6 years ago

Hi @sprkbrn,

This is very concerning! So to clarify, you are doing the following

Get-Group -Id 46827 | Get-Sensor

When you do this, the following should happen

  1. Get the group with ID 46827 (omitted from logs)
  2. Get all groups named "SomeApp"
  3. Since you have multiple groups named "SomeApp", we need to retrieve our child sensors via the group's child devices
  4. Retrieve all child devices of group ID 46827
  5. Retrieve all sensors under all of the specified devices. If your child devices have IDs 1234 and 5678 this should result in `&filter_parentid=1234&filter_parentid=5678``

But it seems for some reason we're not getting any Parent IDs that should be created in step 5

Before we look into this deeper, can you please run Get-Module PrtgAPI and confirm the version of PrtgAPI you're running? See below

lordmilko commented 6 years ago

Hi @sprkbrn,

I have figured out what is going on here. The issue is occurring because the SomeApp group does not have any child devices directly under it. As result, this request

https://prtg-app/api/table.xml?content=devices&columns=location,host,group,probe,favorite,condition,upsens,downsens,downacksens,partialdownsens,warnsens,pausedsens,unusualsens,undefineds
ens,totalsens,schedule,basetype,baselink,parentid,notifiesx,interval,intervalx,access,dependency,position,status,comments,priority,message,type,tags,active,objid,name&count=*&filter_parentid=46827&usern
ame={redacted}&passhash={redacted}

returns a list of zero devices. Get-Sensor selects all of the IDs in the empty list (none) and updates the SensorFilter (overwriting it with nothing) resulting in the behavior you are seeing. What Get-Sensor should do instead is if it sees there are no devices, skip retrieving sensors from this group and continue onto all child groups (of which you appear to have 3)

VERBOSE: Get-Sensor: Processing 3 child groups of parent group SomeApp

I will try and release PrtgAPI 0.8.3 with the required fix tomorrow. In the meantime you can circumvent this issue by manually retrieving all child sensors via all child devices

Get-Group -Id 46827 | Get-Device | Get-Sensor
lordmilko commented 6 years ago

Hi @sprkbrn,

PrtgAPI 0.8.3 has now been released. Can you please run Update-Module PrtgAPI, reopen PowerShell and confirm whether this issue is resolved?

Note: if you are not currently on PrtgAPI 0.8.2, please be aware of any breaking changes between your current and the latest version.

Regards, lordmilko

sprkbrn commented 6 years ago

Hey @lordmilko , thanks for all your help this update did work. Also great thinking for the workaround. Thanks so much!