Advertisement
stephanlinke

[PRTG] Import devices with latitude/longitude

Nov 13th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -Version 4
  2. # ___ ___ _____ ___
  3. #| _ \ _ \_   _/ __|
  4. #|  _/   / | || (_ |
  5. #|_| |_|_\ |_| \___|
  6. #    NETWORK MONITOR
  7. # ------------------
  8. # (c) 2014 Paessler AG
  9. # this will create new devices including lat and lon. from a CSV.
  10. # Make sure it looks like this and is named devices.csv within the same directory as the script:
  11. <#
  12. DeviceName;DeviceAddress;TargetGroup;LocationName;Longitude;Latitude
  13. Server1;server2.network.com;1;Nuremberg;11.1296;49.4741
  14. #>
  15. $Server         = "<insert-your-prtgserver>"
  16. $Username       = "<insert-administrative-prtg-user>"
  17. $Passhash       = "<insert-above-users-passhash-from-its-account-settings>"
  18. $DeviceID       = 2042      # Enter the id of a device with no sensors here, you can get it from the URL of the devices overview page
  19.  
  20. # The list of URLs you want to monitor. Please use the same syntax as the examples.
  21. $DeviceList = (Get-Content("devices.csv") | ConvertFrom-Csv -Delimiter ';');
  22.  
  23. ForEach($Device in $DeviceList){
  24.  
  25.     # create the sensor
  26.     $CreateURL = "http://{0}/api/duplicateobject.htm?id={1}&name={2}&targetid={3}&username={4}&passhash={5}" -f
  27.                  $Server,
  28.                  $DeviceID,
  29.                  $Device.DeviceName,
  30.                  $Device.TargetGroup,
  31.                  $Username,
  32.                  $Passhash
  33.  
  34.     $response = [System.Net.WebRequest]::Create($CreateURL).GetResponse();
  35.    
  36.     # extract the sensor id, every number with at least 4 digits counts as id
  37.     $newDeviceID = $response.ResponseUri.Query -match "(\d{4,})";
  38.     $newDeviceID = $matches[0];
  39.  
  40.     # modify the device settings to feature latitude and longitude
  41.     $UrlLatLon = "http://{0}/api/setlonlat.htm?id={1}&location={2}&lonlat={3},{4}&username={5}&passhash={6}" -f
  42.                  $Server,$newDeviceID,$Device.LocationName,$Device.Longitude,$Device.Latitude,$Username,$Passhash
  43.  
  44.     Invoke-WebRequest -Uri $UrlLatLon | Out-Null
  45.  
  46.     # Unpause the new sensor
  47.     Invoke-WebRequest "http://$Server/api/pause.htm?id=$newDeviceID&action=1&username=$username&passhash=$passhash" > $null
  48.     Write-Host "Device $($Device.DeviceName) created successfully. Should be up and running..."
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement