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

Add groups and devices using a CSV file

Votes:

5

After speaking to (Danish) customers with a XL1 configuration it was remarkable there were two of them asking for the same feature.

For companies it is often the case they have a list from their previous solution a list of devices that they want to add the soonest, with VERY little labor to their PRTG configuration.

Currently the PRTG API only allows you to clone an existing device, which needs to be started after the cloning as well.

Please provide us with a solution to add groups and devices using a CSV format type of file.

The solution should allow:

GROUPS: For groups to indicate the parent group by using the group ID (It is OK to inherit the setting from this parent). A record header could like like this: "Group Name","ID of Parent Group Name"

DEVICES: For a device the CSV record must contain: • name of the device to be imported • the id of the group that will hold the new device • indicate for the IP version, like IP4 or IP6 • the actual IP address in the format of version • sensor detection

For the sensor detection you might allow a value like a 1,2 or 3 value where: • 1=no auto discovery • 2=automatic device discovery which in the current web console is called "standard" • 3=automatic device discovery which in the current web console is called "detailed"

From my experience multiple organizations that already use PRTG will benefit from this feature as well.

Hope this gets voted up very high ;-)

Thank you all for your support of this request in advance

api device-tools massimport

Created on Jan 18, 2019 11:14:07 AM by  HenkHill (5) 1



1 Reply

Votes:

1

Hi HenkHill,

For reference, you can currently do this fairly easily in PowerShell with PrtgAPI

For example, given the file Servers.csv with the following contents

Name,State,District,Location
NY-NEWYORK,New York,NY1,"23 Fleet Street, New York, New York, USA"
NY-QUEENS,New York,NY1,"48 Queen Street, Queens, New York, USA"
NY-BRONX,New York,NY2,"35 West Street, The Bronx, New York, USA"
IL-CHICAGO,Illinois,IL1,"42 South Street, Chicago, Illinois, USA"

where

  • You have separate probes for "New York" and "Illinois"
  • "NY1", "NY2" and "IL1" districts you wish to create groups for, and
  • "NY-NEWYORK", "NY-QUEENS", "NY-BRONX" and "IL-CHICAGO" are devices within each district

you can import this hierarchy by creating a file AddServers.ps1 containing the following code

if(!(Get-PrtgClient))
{
    Connect-PrtgServer prtg.contoso.local
}

# Import the CSV
$csv = Import-Csv $PSScriptRoot\Servers.csv

# Group each record by its State
$states = $csv | group State

function ProcessStates($states) {

    foreach($state in $states)
    {
        Write-Host "Processing state $($state.Name)"

        # Get this state's PRTG Probe
        $probe = Get-Probe $state.Name

        if(!$probe)
        {
            throw "Could not find probe '$($state.Name)'"
        }

        # Group each record in this state by its District
        $districts = $state.Group | group District

        ProcessDistricts $probe $districts
    }
}

function ProcessDistricts($probe, $districts) {

    foreach($district in $districts)
    {
        Write-Host "   Processing district $($district.Name)"

        # Get this district's PRTG Group
        $districtGroup = $probe | Get-Group $district.Name

        if(!$districtGroup)
        {
            # If no such group exists, create one
            $districtGroup = $probe | Add-Group $district.Name
        }

        ProcessOffices $district $districtGroup
    }
}

function ProcessOffices($district, $districtGroup) {

    foreach($office in $district.Group)
    {
        # Get this office's server
        $device = $districtGroup | Get-Device $office.Name

        if(!$device)
        {
            Write-Host "      Adding device $($office.Name)"

            $fqdn = "$($office.Name).$env:userdnsdomain".ToLower()

            # Add the device using a Host of <hostname>.<domain>
            $device = $districtGroup | Add-Device $office.Name $fqdn

            # Set the location
            $device | Set-ObjectProperty Location $office.Location
        }
    }
}

ProcessStates $states

This can then be used as the basis for developing your own scripts (for example, retrieving existing objects by ID, deciding whether to specify -AutoDiscover to the Add-Device cmdlet, or perhaps later on perform a detailed or template based auto-discovery using the Start-AutoDiscovery cmdlet

For more information on using PrtgAPI please see the wiki

Regards,

lordmilko

Created on Jan 18, 2019 12:09:08 PM




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.