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

API: xml from a batch to get all objects from a starting point

Votes:

0

I need to query all objects from a starting point in a for loop and take action on specific type of device To make it simple I show the logic [xml] foreach (object in AllObjectsFromStartGroupID) { if type=Group => set some group property if type=device ==> set host=newIP if type=sensor ==> set name Sitecode + old name (ie: PING becomes "99-PING" I thought of using a "type" property but it sounds like it does not exist Did I miss something?

api objecttype type

Created on Mar 23, 2018 10:53:33 AM



3 Replies

Votes:

0

There's no way to retrieve all types of objects in a single request; instead, you can either iterate over the children of an object, splitting the processing of each object type up via functions, or execute a series of highly specified queries to target the actual objects you're interested in.

If you really wish to loop over all objects, the following code snippet shows an example of how to do this using PrtgAPI, adapted from a script originally designed to generate a "tree" of PRTG's object hierarchy

function ProcessRootChildren()
{
    $probes = Get-Probe

    foreach($probe in $probes)
    {
        ProcessProbeChildren $probe
    }
}

function ProcessProbeChildren($probe)
{
    ProcessContainerChildren $probe
}

function ProcessContainerChildren($parentObj)
{
    $filter = flt parentid eq $parentObj.Id

    $groups = $filter|Get-Group

    foreach($group in $groups)
    {
        ProcessGroupChildren $group
    }

    $devices = $filter|Get-Device

    foreach($device in $devices)
    {
        ProcessDeviceChildren $device
    }
}

function ProcessGroupChildren($parentObj)
{
    ProcessContainerChildren $parentObj
}

function ProcessDeviceChildren($device)
{
    $sensors = $device | Get-Sensor

    foreach($sensor in $sensors)
    {
        # Do stuff to sensors
    }
}

Most likely though you don't really need to loop over every object, and would be better served executing more specified queries

$groups = Get-Group -Tags newyork

foreach($group in $groups)
{
    # Suppose the site code is encoded in the first few letters of the group name

    $siteCode = $group.Name.Substring(0, 2)

    # etc
}

If you have a CSV of your device names (as displayed in PRTG) that's even better

$csv = Import-Csv C:\servers.csv

foreach($server in $csv)
{
    Get-Device $csv.Device | Set-ObjectProperty Host $csv.NewHost
}

Regards,

lordmilko

Created on Mar 26, 2018 7:33:56 AM



Votes:

0

Thank you for this exhaustive answer Apologies for my late answer I didn't know the module PrtgAPI I will give it a try My question raised after I have found out that when running a query with an invalid or empty content (content=device instead of content=devices) I got every kind of objects

Created on Mar 27, 2018 6:44:22 PM



Votes:

0

Hi there,

The module is a third party application developed by lordmilko! We highly recommend it for doing basic (and even extensive) API-Tasks.

Best regards.

Created on Mar 27, 2018 7:44:18 PM by  Dariusz Gorka [Paessler Support]




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.