Is it possible to somehow mark the sensor for the interface with the highest traffic on a network device?
Determine the uplink port on a switch
Votes:
0
1 Reply
Votes:
0
This can be done with the following script:
[string]$prtgHostName = "" [string]$prtgProtocol = "http" [int]$prtgPort = 80 [string]$prtgUserName = 'prtgadmin' [string]$prtgPasshash = 12345678 [string]$uplink_tag = "UPLINK - " $retrieve_url = "{0}://{1}:{2}/api/table.json?content=sensors&output=json&columns=objid,device,parentid,sensor,status,lastvalue_,priority,favorite&filter_tags=@tag(bandwidthsensor)&username={3}&passhash={4}" $get_sensors = "{0}://{1}:{2}/api/table.json?content=sensors&output=json&columns=objid,sensor&id={3}&username={4}&passhash={5}" $rename_url = "{0}://{1}:{2}/api/setobjectproperty.htm?id={3}&name=name&value={4}&username={5}&passhash={6}" # this will output debug messages to the console function Console-ShowMessage([string]$type,$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) } $response = (Invoke-WebRequest ([string]::Format($retrieve_url,$prtgProtocol,$prtgHostName,$prtgPort,$prtgUserName,$prtgPasshash))); $result = ($response.Content | ConvertFrom-Json) $sensors = $result.sensors ## remove uplink tag first Console-ShowMessage -type "information" -message "Removing '$($uplink_tag)' from all traffic sensors" foreach($sensor in $sensors){ $sensor_name = ($sensor.sensor -replace $uplink_tag,"") Invoke-WebRequest ([string]::Format($rename_url,$prtgProtocol,$prtgHostName,$prtgPort,$sensor.objid,$sensor_name,$prtgUserName,$prtgPasshash)) -UseBasicParsing | out-null } $fastest = $sensors | Group Device | Foreach { $_.Group | Sort lastvalue_raw -Descending | Select -First 1 } Console-ShowMessage -type "information" -message "$($Sensors.Count) traffic sensors found." foreach($sensor in $fastest){ Console-ShowMessage -type "information" -message "Highest traffic for $($sensor.device): $($sensor.sensor)" # get sensor count $sensor_count = ((Invoke-WebRequest([string]::Format($get_sensors,$prtgProtocol,$prtgHostName,$prtgPort,$sensor.parentid,$prtgUserName,$prtgPasshash)))); $sensor_count = ($sensor_count.Content | ConvertFrom-Json).sensors.Count # rename sensors accordingly $new_sensorname = [string]::Format("{0}{1}",$uplink_tag, $sensor.sensor) Console-ShowMessage -type "information" -message "Sensor $($sensor.objid) is being marked with '$($uplink_tag)'" Invoke-WebRequest ([string]::Format($rename_url,$prtgProtocol,$prtgHostName,$prtgPort,$sensor.objid,$new_sensorname,$prtgUserName,$prtgPasshash)) | out-null }
Enter your credentials and PRTG host data. The script will automatically retrieve all traffic sensors from PRTG for all devices and tag them accordingly. The one with the highest traffic is considered the uplink port. The script will output which sensors have been edited.
note the script is provided as is, use it at your own risk. Make a configuration backup to stay safe. note the script won't work with a untrusted SSL certificate installed
Created on Aug 26, 2016 10:38:18 AM by
Stephan Linke [Paessler Support]
Last change on Aug 26, 2016 10:39:20 AM by
Stephan Linke [Paessler Support]
Add comment