Good Morning I already created the sensor with all the steps of the t Powershell script, it runs the sensor it is in green state without errors, but it doesn't show information about the connected clients, the connected APs etc.

I followed all the steps to create the script and everything ok but I can't see the statistics


Article Comments

Dear hector2010,

all script come without technical support. In order to debug the issue, pleas open the sensors's "Settings" tab, enable "Write Exe result to disk", and after next scan, check the output in ""C:\ProgramData\Paessler\PRTG Network Monitor\Logs\sensors".


May, 2020 - Permalink

Annex the log to the sensor

<prtg> <result> <channel>Access Points Connected</channel> <value>0</value> </result> <result> <channel>Access Points Upgradeable</channel> <value>0</value> </result> <result> <channel>Clients (Total)</channel> <value>0</value> </result> <result> <channel>Guests</channel> <value>0</value> </result> <result> <channel>Response Time</channel> <value>2018</value> <CustomUnit>msecs</CustomUnit> </result> </prtg>


May, 2020 - Permalink

param( [string]$server = '10.10.1.100', [string]$port = '8443', [string]$site = 'default', [string]$username = 'admin', [string]$password = 'c3rv3c3r14', [switch]$debug = $false )

  1. Ignore SSL Errors [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  2. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  1. Define supported Protocols [System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3")
  1. Confirm Powershell Version. if ($PSVersionTable.PSVersion.Major -lt 3) { Write-Output "<prtg>" Write-Output "<error>1</error>" Write-Output "<text>Powershell Version is $($PSVersionTable.PSVersion.Major) Requires at least 3. </text>" Write-Output "</prtg>" Exit }
  1. Create $controller and $credential using multiple variables/parameters. [string]$controller = "https://$($server):$($port)/manage/account/login" [string]$credential = "`{`"username`":`"$username`",`"password`":`"$password`"`}"
  1. Start debug timer $queryMeasurement = [System.Diagnostics.Stopwatch]::StartNew()
  1. Perform the authentication and store the token to myWebSession try { $null = Invoke-Restmethod -Uri "$controller" -method post -body $credential -ContentType "application/json; charset=utf-8" -SessionVariable myWebSession }catch{ Write-Output "<prtg>" Write-Output "<error>1</error>" Write-Output "<text>Authentication Failed: $($_.Exception.Message)</text>" Write-Output "</prtg>" Exit }
  1. Query API providing token from first query. try { $jsonresultat = Invoke-Restmethod -Uri "https://10.10.1.100:8443/manage/site/default/devices/1/50" -WebSession $myWebSession }catch{ Write-Output "<prtg>" Write-Output "<error>1</error>" Write-Output "<text>API Query Failed: $($_.Exception.Message)</text>" Write-Output "</prtg>" Exit }
  1. Load File from Debug Log
  2. $jsonresultatFile = Get-Content '.\unifi_sensor2017-15-02-05-42-24_log.json'
  3. $jsonresultat = $jsonresultatFile | ConvertFrom-Json
  1. Stop debug timer $queryMeasurement.Stop()
  1. Iterate jsonresultat and count the number of AP's.
  2. $_.state -eq "1" = Connected
  3. $_.type -like "uap" = Access Point ?

$apCount = 0 Foreach ($entry in ($jsonresultat.data | where-object { $_.state -eq "1" -and $_.type -like "uap"})){ $apCount ++ }

$apUpgradeable = 0 Foreach ($entry in ($jsonresultat.data | where-object { $_.state -eq "1" -and $_.type -like "uap" -and $_.upgradable -eq "true"})){ $apUpgradeable ++ }

$userCount = 0 Foreach ($entry in ($jsonresultat.data | where-object { $_.type -like "uap"})){ $userCount += $entry.'num_sta' }

$guestCount = 0 Foreach ($entry in ($jsonresultat.data | where-object { $_.type -like "uap"})){ $guestCount += $entry.'guest-num_sta' }

  1. Write Results

write-host "<prtg>"

Write-Host "<result>" Write-Host "<channel>Access Points Connected</channel>" Write-Host "<value>$($apCount)</value>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Access Points Upgradeable</channel>" Write-Host "<value>$($apUpgradeable)</value>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Clients (Total)</channel>" Write-Host "<value>$($userCount)</value>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Guests</channel>" Write-Host "<value>$($guestCount)</value>" Write-Host "</result>"

Write-Host "<result>" Write-Host "<channel>Response Time</channel>" Write-Host "<value>$($queryMeasurement.ElapsedMilliseconds)</value>" Write-Host "<CustomUnit>msecs</CustomUnit>" Write-Host "</result>"

write-host "</prtg>"

  1. Write JSON file to disk when -debug is set. For troubleshooting only. if ($debug){ [string]$logPath = ((Get-ItemProperty -Path "hklm:SOFTWARE\Wow6432Node\Paessler\PRTG Network Monitor\Server\Core" -Name "Datapath").DataPath) + "Logs (Sensors)\" $timeStamp = (Get-Date -format yyyy-dd-MM-hh-mm-ss)

$json = $jsonresultat | ConvertTo-Json $json | Out-File $logPath"unifi_sensor$($timeStamp)_log.json" }


May, 2020 - Permalink

Dear hector2010,

it seems the script yields zero-values. You could run the individual commands manually and debug it in order to see where it is going wrong. As from our side, script usage is not covered by technical support.


May, 2020 - Permalink