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

Limited SNMP Location and Geomaps

Votes:

0

My appliances do support the SNMP location, but only in a very limited way. I only have one line available for the string, but i'd like to use the GeoMaps feature that shows the icon in the correct location, but only it's name, similar to the following screenshot:



When entering the following string in the location: Paessler Headquarters,49.4874996,11.1278013 ...the location is correct, but instead of only "Paessler Headquarters", it shows the entire string, since I can't enter a <br /> or a different line break character within the device location.

While it would be easy to change, it's read from the device with every auto discovery, so changing them manually would be in vain. Is there any way to modify the location automatically with a sensor?

exe-script geomaps snmp snmp-location

Created on Mar 16, 2017 12:13:01 PM by  Stephan Linke [Paessler Support]



1 Reply

Accepted Answer

Votes:

0

This article applies to PRTG Network Monitor 16 or later

Introduction

PRTG does indeed always read the SNMP location string of the device, since it could've been possibly relocated since the last auto discovery. The following script will iterate through all devices under a given Object ID and modify their location according to the current location string. Here's what it does:

  1. Retrieve all devices under that Object ID, e.g. a group in PRTG
  2. Check if the device currently has a location similar to the following:
    <location name>,<latitude>,<longitude>
  3. If the string matches, PRTG will update the location accordingly and it will look like in your screenshot.

Installation

Remarks

PowerShell based scripts must be allowed to run on the probe you're running the script on.
Please check out our Guide For PowerShell based Custom Sensors.

Setup
  1. Save the script as PRTG-UpdateSNMPLocations.ps1 to
    C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE
  2. Modify the script's parameters according to the table in the Parameters section of this post
  3. Create a new EXE/Script Sensor on the Local Probe device
  4. Enter the following parameter:
    -parentId 0
  5. Select PRTG-UpdateSNMPLocations.ps1 from the EXE/Script dropdown menu
  6. Hit Continue

    You can give the script a small test run, make sure that you have devices that have a matching location string. Simply open up a PowerShell and execute the script. You will see something like this:

    Console output of the script

    As you can see, it also outputs a PRTG compliant result at the end.

Parameters

Parameter NameDescriptionExample
$prtgProtocolThe protocol used by your PRTG.Use either http or https.
$prtgPortThe port your webinterface uses80
$prtgHostThe FQDN of your PRTG webinterfaceprtg.acme.com
$prtgUserThe user accessing the APIprtgadmin
$prtgPasshashThe passhash of the above user12345678
$parentIdThe the ID of the Auto Discovery group0

Script

#requires -version 4.0
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Active PRTG Users
# ================================
# The following script will iterate through all devices under a given 
# Object ID and modify their location according to the current location string. 
# 
# Version History
# ----------------------------
# 1.0      initial release
# # # # # # # # # # # # # # # # # # # # # # # # # #
param( 
       [string]$prtgProtocol = "http",
          [int]$prtgPort     = 80, 
       [string]$prtgHost     = "prtg.acme.com", 
       [string]$prtgUser     = "prtgadmin", 
       [string]$prtgPasshash = "123456789",
          [int]$parentId     = 0
     );

function Console-ShowMessage([string]$type,[string]$message){
        Write-Host ("[{0}] " -f (Get-Date)) -NoNewline;
        switch ($type){
            "success"       { Write-Host "    success    "  -BackgroundColor Green      -ForegroundColor White -NoNewline; }
            "information"   { Write-Host "  information  "  -BackgroundColor DarkCyan   -ForegroundColor White -NoNewline; }
            "warning"       { Write-Host "    warning    "  -BackgroundColor DarkYellow -ForegroundColor White -NoNewline; }
            "error"         { Write-Host "     error     "  -BackgroundColor DarkRed    -ForegroundColor White -NoNewline; }
            default         { Write-Host "     notes     "  -BackgroundColor DarkGray   -ForegroundColor White -NoNewline; }
        }
        Write-Host (" {0}{1}" -f $message,$Global:blank) 
}

#region configuration
$progressPreference = 'silentlyContinue'
$counter = 0; 

#endregion


# This will retrieve all active users from the configuration file and compare them to the webserver log
function This-UpdateLocations(){

    begin 
    { Console-ShowMessage -type information -message "Starting location update." }

    process {
        
        # regex for matching <string>,<latitude>,<longitude>
        $regex = '^.+,([-+]?\d{1,2}([.]\d+)?),\s*([-+]?\d{1,3}([.]\d+)?)$'

        # Get all devices beneath the configured ID
        $Devices = (((Invoke-Webrequest -Uri ([string]::Format("{0}://{1}:{2}/api/table.json?content=devices&output=json&id={3}&columns=group,objid,device,location&username={4}&passhash={5}", $prtgProtocol,$prtgHost, $prtgPort,$parentId,$prtgUser,$prtgPasshash))).Content | ConvertFrom-Json).devices)

       
        Console-ShowMessage -type information -message "$($Devices.Count) devices found in this group."


        Foreach($Device in $Devices){

            Console-ShowMessage -type information -message "Checking $($Device.device). Location: $($Device.location_raw)"
            
            if($Device.location_raw -match $regex)
            { 
                
                Console-ShowMessage -type warning -message "$($Device.device) still has SNMP location from the device. Updating...";

                # put the location into an array so we can put it in the corresponding URL
                $location = $Device.location_raw.Split(",")

                if((Invoke-Webrequest -Uri ([string]::Format("{0}://{1}:{2}/api/setlonlat.htm?id={3}&location={4}&lonlat={5},{6}&username={7}&passhash={8}",$prtgProtocol,$prtgHost,$prtgPort,$device.objid, $location[0],$location[2],$location[1],$prtgUser,$prtgPasshash))))
                { Console-ShowMessage -type success -message "$($Device.device) location updated successfuly!"; $counter++; }
                else
                { Console-ShowMessage -type error -message "Error while updating location of $($Device.device)"; Write-Host ("{0}:Device location could not be updated for $($Device.device)"); exit 1; }
            }
            else 
            { Console-ShowMessage -type notes -message "$($Device.device) already has the correct location format"; } 

        }
               
    }

    End 
    { Write-Host ("{0}:{0} device(s) had their location updated in the last run" -f $counter) }    
}

This-UpdateLocations

Created on Mar 16, 2017 12:29:37 PM by  Stephan Linke [Paessler Support]

Last change on Apr 21, 2017 12:41:27 PM by  Stephan Linke [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.