What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Export list of devices and parentIDs

Votes:

0

I'm trying to export a list of devices and their parentIDs using the api and PowerShell. I have the lines entered to ignore invalid SSL certs and if I paste the following URL into a web browser, it works fine after clicking SaveAs and providing a path:

https://{host_name}/api/table.xml?content=devices&output=csvtable&columns=device,host,objid,parentid&id=$StartingID&count=20000&username={user_name}&passhash={passhash}

But if I put it in to PowerShell, it does not work:

function getObjGroupList($oHost, $oUser, $oPass)
{
	$url = "https://$oHost/api/table.xml?content=devices&output=csvtable&columns=device,host,objid,parentid&id=$StartingID&count=20000&username=$oUser&passhash=$oPass"
	$objGroupList = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore
	$objGroupList | Export-CSV -Path  "{Path}\groupID.csv" -NoTypeInformation
}

It creates the CSV file, but it only contains the headers, no data. Has anyone been able to successfully export parentIDs in order to pause and resume probes based on parentID?

api parentid powershell

Created on May 9, 2019 5:52:32 PM

Last change on May 9, 2019 7:07:52 PM by  Dariusz Gorka [Paessler Support]



3 Replies

Votes:

0

Hi jrob,

You can do this fairly easily using PrtgAPI

C:\> Get-Device | Export-Csv C:\devices.csv -notype

This will contain all properties of devices, including their ParentId, Group and Probe names. If you don't actually need a CSV however and simply want to pause based on probes you can this fairly easily using PowerShell

C:\> Get-Device | group Probe | foreach { Get-Probe $_.name | Pause-Object -Forever }

Note that you can't pause probes based on "ParentId" as you suggest, as there's no guarantee that the ParentId of a device is a probe and not a group

If you wish to execute these API requests manually, you can specify the -Verbose parameter to any cmdlet within PrtgAPI to see the exact URL that it requests

Regards,

lordmilko

Created on May 14, 2019 7:58:05 AM



Votes:

0

Hello Milko,

Thanks for the response. Hoping to avoid installing a PRTG module for PS as this may be launched from multiple computers. This is being put together as a PowerShell script to be run from a SCORCH runbook.

Pausing probes by parentID is working fine, I find the parentID of a hostname for one of our clients, all of their servers have the same parentID, I can pause and then resume without issue. The only problem is getting the export to find the parentID. I have to do it manually every time.

Thanks, jrob

Created on May 14, 2019 9:21:08 PM



Votes:

0

Hi jrob,

One issue I'm seeing is you're trying to export the response to a file as a CSV, however you haven't actually converted the response into a series of objects yet. You need to parse the response *from* a CSV using the ConvertFrom-Csv cmdlet before you can re-export it *to* a CSV using the Export-Csv cmdlet

Potentially you can try the following

C:\> $response = iwr "http://prtg.example.com/api/table.csv?content=devices&columns=objid,name,location,host,group,probe,favorite,condition,upsens,downsens,downacksens,partialdownsens,warnsens,pausedsens,unusualsens,undefinedsens,totalsens,schedule,basetype,baselink,notifiesx,intervalx,access,dependency,position,status,comments,priority,message,parentid,tags,type,active&count=*&username=prtgadmin&passhash=12345678"

C:\> $response.content | ConvertFrom-Csv | Export-Csv C:\output.csv -notype

If you wanted to output the existing CSV response to a file as is, potentially you could use the Set-Content cmdlet instead of the Export-Csv cmdlet; I would recommend going through the intermediate steps of using ConvertFrom-Csv / Export-Csv however, as this will rectify any issues in PRTG's response such as certain columns missing headers, etc

Regards,

lordmilko

Created on May 15, 2019 5:44:04 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.