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