New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Can I monitor Ubiquiti UniFi network devices with PRTG?

Votes:

1

Your Vote:

Up

Down

I recently installed several Ubiquiti UniFi devices on my network. I have a UniFi Security Gateway (USG), two UniFi AP AC PRO wireless access points, and a UniFi Cloud Key. How can I monitor these devices with PRTG, has anyone developed a sensor or script yet?

custom-script-exe custom-sensor exe-script-advanced-sensor exe-script-sensor powershell prtg sensor ubiquiti unifi

Created on Sep 15, 2016 7:33:20 PM by  KAL (1) 1

Last change on Jan 10, 2017 1:13:21 PM by  Martina Wittmann [Paessler Support]



Best Answer

Accepted Answer

Votes:

2

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 16.4.27 or later

Monitoring Ubiqiti UniFi Devices with PRTG

We've put together an EXE/Script Advanced sensor that you can use to monitor general statistics and information of your Ubiquiti UniFi deployment, regarding especially the access points.

What the Sensor Monitors

The sensor shows you the following per-site statistics:

  • Response time from the controller's API
  • Number of Connected Clients (Total (Clients+Guests))
  • Number of Connected Guests
  • Number of Connected Access Points (UAPs in Connected status)
  • Number of Upgreadeable Access Points (UAPs in Connected status with upgradable flag set)

Requirements

  • PRTG Network Monitor 16.4.27 or later
  • The PRTG probe on which you want to deploy the sensor must be able to reach the UniFi controller on the "API" port (default is 8443).
  • The PRTG probe on which you want to deploy the sensor must run PowerShell version 3 or later.
  • The script was tested with the UniFi controller versions 5.3.8 ~ 5.7.23.
    Note: We cannot guarantee that it works with other UniFi controller versions.
  • Configure your PRTG probe to enable the execution of unsigned scripts/code. For further information refer to the Knowledge Base articles Guide for PowerShell based custom sensors and PowerShell 32-bit and 64 bit and execution policy.

Known Limitations

The sensor will not produce any alerts by default, unless it is unable to authenticate or contact the UniFi controller. Once the sensor is deployed, you're advised to set up limits in the channel's settings. For example, define a lower error limit for the number of connected access points. This way you are notified as soon as the number of connected access points is lower than expected. Please refer to this set up guide for notifications using limits: Notification via Limits - Example.

Sensor Creation and Usage

1. Copy the Custom Sensor Code below and save it as Custom Powershell Unifi Status.ps1 under the following path of the desired PRTG Probe:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML

2. Create a new device in PRTG with the address (IP or FQDN) of the UniFi Controller that you want to monitor.

3. Now, select Add Sensor. On the search field, type "Script Advanced" and then select the EXE/Script Advanced sensor from the result list.

4. On the Add Sensor to Device screen, enter the following:

4.1 The sensor's name and tags (optional)

4.2 Under Exe/Script, use the Drop-down to select Custom Powershell Unifi Status.ps1 from the list.

4.2 The parameters should be:

-server '%host' -port '8443' -site 'default' -username 'ctrllerUsername' -password 'ctrllerPassword'

You can omit -port and -site when working with the default. For non-default sites, use the site's "code" as pointed out here by wimkoopman.

4.3 Unless required for other reasons, leave the default Environment and Security Context and Mutex Name.

4.4 Reduce the Timeout to 30 seconds, the query shouldn't take this long.

4.5 The EXE Result should only be enabled if you need to troubleshoot the sensor's execution.

4.6 Click Continue to deploy the sensor.

5. The sensor should display channels and values after one scanning interval. Once this happened, you can start adjusting the channel limits to your requirements (optional).

The Script

This is the sensor's PowerShell code:

# Monitor the Status of AP's on Unfi Controller in PRTG v0.8 27/06/2017
# Published Here: https://kb.paessler.com/en/topic/71263
#
# Parameters in PRTG are: Controller's URI, Port, Site, Username and Password. Example without placeholders:
# -server 'unifi.domain.tld' -port '8443' -site 'default' -username 'admin' -password 'somepassword'
#
# -server '%host' -port '8443' -site 'default' -username '%windowsuser' -password '%windowspassword'
# This second option requires the device's address in PRTG to be the controller's address, the credentials for windows devices
# must also match the log-in/password from the controller. This way you don't leave the password exposed in the sensor's settings.
#
# It's recommended to use larger scanning intervals for exe/xml scripts. Please also mind the 50 exe/script sensor's recommendation per probe.
# The sensor will not generate alerts by default, after creating your sensor, define limits accordingly.
# This sensor is to be considered experimental. The Ubnt's API documentation isn't completely disclosed.
#
#   Source(s):
#   http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
#   https://github.com/fbagnol/class.unifi.php
#   https://www.ubnt.com/downloads/unifi/5.3.8/unifi_sh_api
#   https://github.com/malle-pietje/UniFi-API-browser/blob/master/phpapi/class.unifi.php

param(
	[string]$server = 'unifi.domain.com',
	[string]$port = '8443',
	[string]$site = 'default',
	[string]$username = 'admin',
	[string]$password = '123456',
	[switch]$debug = $false
)

#Ignore SSL Errors
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}  

#Define supported Protocols
[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3")


# 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
}

# Create $controller and $credential using multiple variables/parameters.
[string]$controller = "https://$($server):$($port)"
[string]$credential = "`{`"username`":`"$username`",`"password`":`"$password`"`}"

# Start debug timer
$queryMeasurement = [System.Diagnostics.Stopwatch]::StartNew()

# Perform the authentication and store the token to myWebSession
try {
$null = Invoke-Restmethod -Uri "$controller/api/login" -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
}

#Query API providing token from first query.
try {
$jsonresultat = Invoke-Restmethod -Uri "$controller/api/s/$site/stat/device/" -WebSession $myWebSession
}catch{
	Write-Output "<prtg>"
	Write-Output "<error>1</error>"
	Write-Output "<text>API Query Failed: $($_.Exception.Message)</text>"
	Write-Output "</prtg>"
	Exit
}

# Load File from Debug Log
# $jsonresultatFile = Get-Content '.\unifi_sensor2017-15-02-05-42-24_log.json'
# $jsonresultat = $jsonresultatFile | ConvertFrom-Json

# Stop debug timer
$queryMeasurement.Stop()


# Iterate jsonresultat and count the number of AP's. 
#   $_.state -eq "1" = Connected 
#   $_.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'
}

#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>"

# 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"
}

Result

The resulting sensors (after setting limits) will look like the following (Sensor v0.4):

Sensor Overview

Click here to enlarge.

The sensor's settings will look like this:

Sensor Settings

Click here to enlarge.

Troubleshooting

Got any issues?

  • Check your Powershell version. Just type $PSVersionTable in a PowerShell prompt.
  • Make sure that the execution of scripts is allowed on the PRTG Probe where you've deployed the sensor.
  • Double check that the parameters are correct and that the credentials are valid.
  • Make sure that the remote probe can reach the UniFi controller at the required port. A proxy may not work here.
  • You can append the -debug parameter, the script will then write the whole JSON-formatted content to a file named unifi_sensor...json under Logs (Sensors) in PRTG's Data Path. This should be disabled when debugging is complete as it will endlessly create new files.
  • For any other troubles: Don't hesitate to contact us by replying to this post or by contacting us via a support ticket. Please also link this Knowledge Base post.

Version History

0.12017/01-Initial Release
0.42017/01-Now Ignores SSL Certificate issues
0.52017/02-Includes a channel for "Access Points Upgradeable"
0.72017/02-Includes a command line switch for debugging on the JSON response
-Only polls guests from uap devices(improved filter)
0.82017/06-SSL/TLS compatibility improved

Remarks

  • Please understand that we cannot provide in-depth technical support for custom sensors nor can we guarantee that the above described sensors will work on your systems. You use all components at your own risk.
  • Feel free to further modify this script to monitor other properties, feel free to share it (free of charge) as well.
  • msxfaq.de provides a "fork" of the original script on their website. German only: PRTG mit Ubiquiti WLAN Access Points

Best Regards,
Luciano Lingnau [Paessler Support]

More

Created on Jan 10, 2017 6:52:00 AM by  Luciano Lingnau [Paessler Support]

Last change on May 19, 2018 7:55:03 AM by  Luciano Lingnau [Paessler Support]



39 Replies

Votes:

0

Your Vote:

Up

Down

Update: Please refer to Custom Script for Unifi

Hello KAL,
thank you for your KB-Post.

We haven't experimented with Ubiquity's devices until now, from support experience we know that some device families (Airmax, Airfiber) implement SNMP (V1, rather limited) through proprietary or trough Mikrotik's MIB, but at this time there's no definitive answer we can provide on the subject for the UniFi family of devices.

The UniFi Controller offers an HTTP API that can be used to query statistics, for PRTG integration this would mean a custom exe/script sensors or multiple HTTP XML/REST Value Sensor(if compatible).

Should these devices be compatible with SNMP, please check:

I'll leave your inquiry open should someone else with more experience on these devices be able to contribute as well.


Best Regards,
Luciano Lingnau [Paessler Support]

Created on Sep 16, 2016 12:13:48 PM by  Luciano Lingnau [Paessler Support]

Last change on Jan 10, 2017 8:20:52 AM by  Luciano Lingnau [Paessler Support]



Accepted Answer

Votes:

2

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 16.4.27 or later

Monitoring Ubiqiti UniFi Devices with PRTG

We've put together an EXE/Script Advanced sensor that you can use to monitor general statistics and information of your Ubiquiti UniFi deployment, regarding especially the access points.

What the Sensor Monitors

The sensor shows you the following per-site statistics:

  • Response time from the controller's API
  • Number of Connected Clients (Total (Clients+Guests))
  • Number of Connected Guests
  • Number of Connected Access Points (UAPs in Connected status)
  • Number of Upgreadeable Access Points (UAPs in Connected status with upgradable flag set)

Requirements

  • PRTG Network Monitor 16.4.27 or later
  • The PRTG probe on which you want to deploy the sensor must be able to reach the UniFi controller on the "API" port (default is 8443).
  • The PRTG probe on which you want to deploy the sensor must run PowerShell version 3 or later.
  • The script was tested with the UniFi controller versions 5.3.8 ~ 5.7.23.
    Note: We cannot guarantee that it works with other UniFi controller versions.
  • Configure your PRTG probe to enable the execution of unsigned scripts/code. For further information refer to the Knowledge Base articles Guide for PowerShell based custom sensors and PowerShell 32-bit and 64 bit and execution policy.

Known Limitations

The sensor will not produce any alerts by default, unless it is unable to authenticate or contact the UniFi controller. Once the sensor is deployed, you're advised to set up limits in the channel's settings. For example, define a lower error limit for the number of connected access points. This way you are notified as soon as the number of connected access points is lower than expected. Please refer to this set up guide for notifications using limits: Notification via Limits - Example.

Sensor Creation and Usage

1. Copy the Custom Sensor Code below and save it as Custom Powershell Unifi Status.ps1 under the following path of the desired PRTG Probe:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML

2. Create a new device in PRTG with the address (IP or FQDN) of the UniFi Controller that you want to monitor.

3. Now, select Add Sensor. On the search field, type "Script Advanced" and then select the EXE/Script Advanced sensor from the result list.

4. On the Add Sensor to Device screen, enter the following:

4.1 The sensor's name and tags (optional)

4.2 Under Exe/Script, use the Drop-down to select Custom Powershell Unifi Status.ps1 from the list.

4.2 The parameters should be:

-server '%host' -port '8443' -site 'default' -username 'ctrllerUsername' -password 'ctrllerPassword'

You can omit -port and -site when working with the default. For non-default sites, use the site's "code" as pointed out here by wimkoopman.

4.3 Unless required for other reasons, leave the default Environment and Security Context and Mutex Name.

4.4 Reduce the Timeout to 30 seconds, the query shouldn't take this long.

4.5 The EXE Result should only be enabled if you need to troubleshoot the sensor's execution.

4.6 Click Continue to deploy the sensor.

5. The sensor should display channels and values after one scanning interval. Once this happened, you can start adjusting the channel limits to your requirements (optional).

The Script

This is the sensor's PowerShell code:

# Monitor the Status of AP's on Unfi Controller in PRTG v0.8 27/06/2017
# Published Here: https://kb.paessler.com/en/topic/71263
#
# Parameters in PRTG are: Controller's URI, Port, Site, Username and Password. Example without placeholders:
# -server 'unifi.domain.tld' -port '8443' -site 'default' -username 'admin' -password 'somepassword'
#
# -server '%host' -port '8443' -site 'default' -username '%windowsuser' -password '%windowspassword'
# This second option requires the device's address in PRTG to be the controller's address, the credentials for windows devices
# must also match the log-in/password from the controller. This way you don't leave the password exposed in the sensor's settings.
#
# It's recommended to use larger scanning intervals for exe/xml scripts. Please also mind the 50 exe/script sensor's recommendation per probe.
# The sensor will not generate alerts by default, after creating your sensor, define limits accordingly.
# This sensor is to be considered experimental. The Ubnt's API documentation isn't completely disclosed.
#
#   Source(s):
#   http://community.ubnt.com/t5/UniFi-Wireless/little-php-class-for-unifi-api/m-p/603051
#   https://github.com/fbagnol/class.unifi.php
#   https://www.ubnt.com/downloads/unifi/5.3.8/unifi_sh_api
#   https://github.com/malle-pietje/UniFi-API-browser/blob/master/phpapi/class.unifi.php

param(
	[string]$server = 'unifi.domain.com',
	[string]$port = '8443',
	[string]$site = 'default',
	[string]$username = 'admin',
	[string]$password = '123456',
	[switch]$debug = $false
)

#Ignore SSL Errors
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}  

#Define supported Protocols
[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3")


# 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
}

# Create $controller and $credential using multiple variables/parameters.
[string]$controller = "https://$($server):$($port)"
[string]$credential = "`{`"username`":`"$username`",`"password`":`"$password`"`}"

# Start debug timer
$queryMeasurement = [System.Diagnostics.Stopwatch]::StartNew()

# Perform the authentication and store the token to myWebSession
try {
$null = Invoke-Restmethod -Uri "$controller/api/login" -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
}

#Query API providing token from first query.
try {
$jsonresultat = Invoke-Restmethod -Uri "$controller/api/s/$site/stat/device/" -WebSession $myWebSession
}catch{
	Write-Output "<prtg>"
	Write-Output "<error>1</error>"
	Write-Output "<text>API Query Failed: $($_.Exception.Message)</text>"
	Write-Output "</prtg>"
	Exit
}

# Load File from Debug Log
# $jsonresultatFile = Get-Content '.\unifi_sensor2017-15-02-05-42-24_log.json'
# $jsonresultat = $jsonresultatFile | ConvertFrom-Json

# Stop debug timer
$queryMeasurement.Stop()


# Iterate jsonresultat and count the number of AP's. 
#   $_.state -eq "1" = Connected 
#   $_.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'
}

#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>"

# 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"
}

Result

The resulting sensors (after setting limits) will look like the following (Sensor v0.4):

Sensor Overview

Click here to enlarge.

The sensor's settings will look like this:

Sensor Settings

Click here to enlarge.

Troubleshooting

Got any issues?

  • Check your Powershell version. Just type $PSVersionTable in a PowerShell prompt.
  • Make sure that the execution of scripts is allowed on the PRTG Probe where you've deployed the sensor.
  • Double check that the parameters are correct and that the credentials are valid.
  • Make sure that the remote probe can reach the UniFi controller at the required port. A proxy may not work here.
  • You can append the -debug parameter, the script will then write the whole JSON-formatted content to a file named unifi_sensor...json under Logs (Sensors) in PRTG's Data Path. This should be disabled when debugging is complete as it will endlessly create new files.
  • For any other troubles: Don't hesitate to contact us by replying to this post or by contacting us via a support ticket. Please also link this Knowledge Base post.

Version History

0.12017/01-Initial Release
0.42017/01-Now Ignores SSL Certificate issues
0.52017/02-Includes a channel for "Access Points Upgradeable"
0.72017/02-Includes a command line switch for debugging on the JSON response
-Only polls guests from uap devices(improved filter)
0.82017/06-SSL/TLS compatibility improved

Remarks

  • Please understand that we cannot provide in-depth technical support for custom sensors nor can we guarantee that the above described sensors will work on your systems. You use all components at your own risk.
  • Feel free to further modify this script to monitor other properties, feel free to share it (free of charge) as well.
  • msxfaq.de provides a "fork" of the original script on their website. German only: PRTG mit Ubiquiti WLAN Access Points

Best Regards,
Luciano Lingnau [Paessler Support]

More

Created on Jan 10, 2017 6:52:00 AM by  Luciano Lingnau [Paessler Support]

Last change on May 19, 2018 7:55:03 AM by  Luciano Lingnau [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Hi Great sensor !!!! It works fine on the default site, however on any other site it returns error 401 Niet gemachtigd (Not Authorized) From the controller point of view I authenticated with the main account, which should have no restrictions Please let me know if you have any suggestions


Update: It also works on other sites, but instead of the site name you have to pick up the number of the site by checking the URL example:

Https:unifi.yourdomain.com:8443/manage/site/3kh0qlq5/devices/1/50

In this case 3kh0qlq5 is the ID which you should use as a site name in this script


Update 2: Additional question:

  • Can you easily add information like 2G clients 5G Clients RX TX CH. Util 2G CH. Util 5G Would be highly appreciated !!!

Created on Jan 16, 2017 7:27:47 AM by  wimkoopman (10)

Last change on Jan 16, 2017 8:30:54 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello wimkoopman,
thank you very much for your feedback and input.

I've "merged" all your replies together. :)

Regarding your inquiry, yes, that should be possible with minor modifications. As a general rule, everything that's available in the web-interface (properties, counters) is also available in the API.

I advise you to copy/paste this code into Powershell's ISE, you can then run the code once to get all variables assigned with values. Then, just run (using Run Selection) the following command/variable: $jsonresultat.

This will print-out the whole content of the variable, which is a huge chunk of JSON-encoded data. There are tens if not hundreds of properties available, feel free to modify the script (or add/remove logic and channels) to fit exactly your requirements. There are also links in the script to the available documentation provided by unifi, it provides hints to what's available/possible.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jan 16, 2017 8:40:50 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

This looks great!

Im trying to get it work, but I dont know if im doing something crazy. I get an error when creating the sensor

XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Anyone have any guess what this could be?

The controller is ver 5.2.9 PRTG is 17.1.28.1341

Created on Mar 9, 2017 10:10:17 PM by  Bosse (0) 1

Last change on Mar 10, 2017 7:54:04 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello there Bosse, please beware that I haven't tested the script with version 5.2.9, so I can't guarantee that it ever worked. However, I don't see why it shouldn't..

Please try something else: Instead of deploying the sensor in PRTG, open up the 32-bit powershell shell (Windows Powershell x86), navigate to the path of the script and run it from there, using the same parameters.

Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\> cd '.\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML'
PS & '.\Custom Powershell Unifi Status.ps1' -server "unifi.domain.tld" -port "8443" -site "default" -username "user" -password "somepassword"

What's the outcome? This may provide us further details about what's going wrong.

Please also make sure that you're running a supported powershell version on the server and that you've followed the Guide for PowerShell based custom sensors

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 10, 2017 8:19:02 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello Luciano,

Thanks for your very helpfull tips. I did as you wrote. I tested the script directly in PS and noticed some issues (only my fault). After some trial and error it worked perfectly. The sensor is now up and running!

Thanks alot!

Created on Mar 19, 2017 8:44:41 PM by  Bosse (0) 1



Votes:

0

Your Vote:

Up

Down

Looks great ! However, I'm stuck with PS v2 on some of my servers (SBS2008). Has anyone rewritten this PS script for PS 2 ?

Created on Apr 16, 2017 10:56:23 AM by  dirksamson (0)



Votes:

0

Your Vote:

Up

Down

Hello Dirk,
thank you for your reply.

I'm not aware of any Powershell V2 compatible version, you could try converting it. For instance:

I'm not sure if any other cmdlets will also required adjustments. Keep in mind however that you could employ a remote probe in PRTG, this would allow you to run the script somewhere else (on a different system). Or even, do an Invoke-Command and run the script on a different system that has a newer powershell version.

I'll leave your reply published in case anyone else has input, but I'm not working on any PS2.0 compatible version at the moment.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Apr 18, 2017 6:43:33 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

updated my Unifi Controller to 5.6.x unfortunately the PS script has stopped working. any ideas?

Created on Jun 6, 2017 10:22:16 AM by  crazypete00 (0)



Votes:

0

Your Vote:

Up

Down

Dear crazypete00

Please clarify what "stopped working" means in this case.

Created on Jun 7, 2017 2:38:36 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I tried this now, and get this message in PRTG:

XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Created on Jun 19, 2017 5:41:26 PM by  Morbus (0)



Votes:

0

Your Vote:

Up

Down

Hello @Morbus,
thank you for your reply.

I encourage you to run the script from the command-line to check whenever it works. But keep in mind that you need to include the correct parameters. You can also include -debug in the parameters to write a log file. Please refer to the "Troubleshooting" section in the main article.

Hello @crazypete00. Please note that the latest stable unifi release at the time of this writing is 5.4.16 - I can confirm that the sensor works with that version but haven't tried the beta version yet. If you get me credentials and a controller to connect to I can take a look into why it doesn't work.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jun 20, 2017 7:13:09 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello everyone,

I am trying to add Unify AP into PRTG, I am getting an error from PRTG that user is not authorizerd. Can you please tell me if this can be related to SW that we are running on WLC - 3.2.10 Power shell is 4, and account that I am using has role as admin.

Thank you, Best regards, Pavel Kedron

Created on Jun 20, 2017 7:58:40 AM by  Pavel Kedron (0) 1



Votes:

0

Your Vote:

Up

Down

Hello Pavel,
thank you for your post/reply.

I've never tested the script against a 3.2.10 controller. The API's could greatly differ and I'm unable to confirm that it would work. You may want to consider upgrading/deploying version 5.x instead.

Other than that "user is not authorizerd" sounds like an authentication issue. Make sure you're providing valid credentials to the script. Otherwise, please let me know the complete result/error. If you have a proxy in place it could also be denying the HTTP connection to the controller.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jun 20, 2017 8:52:28 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello,

This is a good Sensor. I run this on different devices. But since last night I have on one of them an Error. In the night nobody changed some settings. But nearly 0:00 the sensor stopped working. Error message is :

<prtg>
<error>1</error>
<text>Authentication Failed: The underlying connection was closed: An unexpected error occurred on a receive.</text>
</prtg> 

I tried in Power Shell ISE same Error and with –Debug
But could not find a Debug File.
Shuld the Debug File not be on the Core Server \PRTG_DB\Logs (Sensors)?

Created on Sep 13, 2017 8:13:00 AM by  PRTG-Nutzer (0)

Last change on Sep 13, 2017 8:36:52 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello there,
thank you for your reply.

Please double check that you're using the latest version (0.8) of the ps1 file, published on 27/06/2017. As for the message:

An unexpected error occurred on a receive.

This could be related to the SSL cyphers. Please note that the script is specially configured to accept/work with the following:

[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3")

Are you using any different protocol or version? You could change this setting (directly in the script) for additional testing. Is the Unifi controller that is being polled up-to-date? Was the Powershell version on the probe perhaps updated/downgraded?

The exception is thrown by the Invoke-Restmethod, so you could also search for generic documentation about this error: powershell "An unexpected error occurred on a receive"

Lastly, regarding the -debug option. It will only work if the sensor is actually able to perform the API call. Since the authentication is failing, the sensor doesn't even connect (and the debug isn't written).

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Sep 13, 2017 8:44:37 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Excellent - worked like a charm! Many thanks for this!

Created on Oct 26, 2017 8:30:28 PM by  mfries (0)



Votes:

0

Your Vote:

Up

Down

Thank you for the information. I seem to be having the issue where I am receiving the error:

XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

within the console.

If I run the script from Powershell, it seems to run fine:

PS C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML> C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\Custom Powershell Unifi Status.ps1
<prtg>
<result>
<channel>Access Points Connected</channel>
<value>4</value>
</result>
<result>
<channel>Access Points Upgradeable</channel>
<value>0</value>
</result>
<result>
<channel>Clients (Total)</channel>
<value>12</value>
</result>
<result>
<channel>Guests</channel>
<value>11</value>
</result>
<result>
<channel>Response Time</channel>
<value>936</value>
<CustomUnit>msecs</CustomUnit>
</result>
</prtg>

I'm not sure what is going on here or what I'm doing wrong. I have the sensor setup under the Windows server that I have the Unifi Controller on. I have the sensor parameters setup with:

-server '%host' -port '8443' -site 'default' -username 'admin' -password 'mypassword'

I also tried the german extended script, but could not get that to work either.

Any help is appreciated.

PRTG

PRTG Enterprise Consolev17.4.35.3441

Powershell:

PSVersion3.0
WSManStackVersion3.0
SerializationVersion1.1.0.1
CLRVersion4.0.30319.36366
BuildVersion6.2.9200.22199
PSCompatibleVersions{1.0, 2.0, 3.0}
PSRemotingProtocolVersion2.2

Created on Nov 29, 2017 6:59:26 PM by  stu68 (10)

Last change on Nov 30, 2017 6:58:18 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello @stu68,
thank you for your reply.

The output from the command-line confirms that the sensor is working and so is the authentication/credentials. Now we need to find out what causes the XML code produced by PRTG to not work (what leads to PE231).

Within the Sensor's settings it is possible to set the "EXE Result" to "Write EXE result to disk". Once configured to do so a resulting Text File (Filename: 'Result of Sensor [ID].txt') will be stored under the Logs (Sensors) directory on the next scan of the sensor.

This folder's path is by default "C:\ProgramData\Paessler\PRTG Network Monitor" of the probe where the sensor is monitored.

Please have a look at the generated files, it may contain the description for a powershell error, for example telling you that the executionpolicy doesn't allow the sensor to run the file/script. In this case please have a look here:

If you're not able to spot anything wrong with the logs of the sensor, please share these so that we can have a look.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Nov 30, 2017 9:50:46 AM by  Luciano Lingnau [Paessler Support]

Last change on Nov 30, 2017 9:50:56 AM by  Luciano Lingnau [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Thank you Luciano. It ended up being the 32 bit Powershell restrictions. Once I did that it worked fine.

Created on Nov 30, 2017 10:08:43 PM by  stu68 (10)



Votes:

0

Your Vote:

Up

Down

Hello,

i have same problem : XML:

The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)
Powershell x64 and x86 Urestricted
PRTG18.1.36.3728
Ubiquiti ctrl5.6.29

Idea ?

Very Thanks

Created on Jan 20, 2018 10:53:54 AM by  yvan_rossier (0)

Last change on Jan 23, 2018 7:01:58 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello @yvan_rossier,
thank you for your reply.

What happens if you run the script manually/interactively? (with the appropriate parameters)

Alternatively, you could configure/enable the "Write EXE result to disk" to find out what the actual output is (that leads to the PE231 error).

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jan 23, 2018 7:04:14 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I recently updated Unifi to a new version (5.6.29) which is beyond the the firmware listed above. I now get the error "Authentication Failed: The request was aborted: Could not create SSL/TLS secure channel." when ran from PS.

Would any one have any suggestions on what might cause that error? I would really like to get this sorted as I find it is a very useful sensor.

Created on Feb 1, 2018 11:37:57 AM by  BF (0)



Votes:

0

Your Vote:

Up

Down

Hello BF,
thank you for your reply.

I have not validated the sensor against the version above because I didn't get a chance to update yet, but will update the document/page as soon as I've updated to test.

However, the following error is produced by powershell, not by "my script" (actually) :

The request was aborted: Could not create SSL/TLS secure channel.

So it appears as if for some reason powershell doesn't like the certificate os ciphers supported by your instance. The script is supposed to work with TLS1.2, TLS1.2, TLS and SSL3.0. The sensor is also supposed to ignore certificate errors.

Unfortunately that's all I can tell you for now, but will update the document as soon as I've updated my test controller.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Feb 1, 2018 1:47:23 PM by  Luciano Lingnau [Paessler Support]

Last change on Feb 2, 2018 7:18:18 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Thanks for the reply Luciano.

Your reply lead me to resolve my problem. I had not updated my script to the latest version. It now connects fine.

Thanks for your assistance.

Created on Feb 1, 2018 2:57:29 PM by  BF (0)



Votes:

0

Your Vote:

Up

Down

Hoorray BF,
thank you for your reply and happy to hear it worked out.

All settled then. Have a nice weekend!

Cheers,
Luciano Lingnau [Paessler Support]

Created on Feb 2, 2018 7:18:10 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Morning,

THIS SCRIPT IS AWSOME!

Thanks for creating and sharing it. Any chance it could also include some data like Top AP (user/bandwidth), or throughput in last 24 hours. Details like you see on the main Ubiquiti statistic page?

Cheers.

Created on Mar 1, 2018 10:07:12 PM by  daven1985 (0) 1



Votes:

0

Your Vote:

Up

Down

Morning,

FEEDBACK IS AWESOME! :)

You're more than welcome, I'm happy it was useful to you. The problem with this sort of "top" metric is that PRTG doesn't really have a way to display it in PRTG, channels are too static for this sort of information and I'm not able to display custom data in a toplist at the present time.

Under remarks, there is a link to msxfaq.de: PRTG mit Ubiquiti WLAN Access Points, this is a "fork" of my script that includes per-access point data, in case that helps you in any way (but it requires one sensor per access point, so it may only be useful/applicable up to a deployment size).

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 2, 2018 8:04:49 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Is there a way to get more information via PS from the USG?

Created on Mar 22, 2018 6:09:25 PM by  PeterH (0) 1



Votes:

0

Your Vote:

Up

Down

Hello Peter,
thank you for your reply.

Haven't had a chance to try that yet, but if the information is available on the Unifi Controller over the API, then most likely it could be polled using a similar script as the one above.

What sort of metrics/values/readings from the USG are you looking for?

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 23, 2018 8:09:55 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I have upgraded the controller from 5.4 to 5.7 and now I too am getting "Authentication Failed: The request was aborted: Could not create SSL/TLS secure channel"

I get this if I run the Powershell script from the PRTG server, or directly on the Windows server running the Unifi controller software.

Any suggestions?

Created on Mar 23, 2018 11:15:34 AM by  miyo360 (0) 2



Votes:

0

Your Vote:

Up

Down

Hello miyo360,
thank you for your reply.

Please double check that you are indeed using the latest available version of the powershell code, the original version of the sensor/script didn't correctly handle some cyphers, as I've mentioned here.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 23, 2018 1:31:51 PM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Created on Mar 23, 2018 1:33:19 PM by  yvan_rossier (0)



Votes:

0

Your Vote:

Up

Down

@yvan_rossier,
thank you for your contribution.

The Custom sensor runs in powershell and interacts with the Web-Interface/API of the controller directly, no JAVA is required for the sensor to work.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 23, 2018 1:34:48 PM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

@Luciano Lingnau Thanks for the response. I googled the error and tried the suggestion here: https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel

I then fixed the script error by...

commenting out your line: #[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

adding this line: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

The sensor now works

Created on Apr 3, 2018 9:55:01 AM by  miyo360 (0) 2

Last change on Apr 3, 2018 7:08:12 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello miyo360,
thank you for your reply and feedback.

It's interesting to hear that this worked. Because basically, the first line (see below) should essentially tell the script to ignore any certificate errors (Self signed certificates for example). The second line should tell Powershell to accept all of the Security Protocols (("Tls12","Tls11","Tls","Ssl3")). But if changing that to allow TLS1.2 only worked for you, I'm happy with that. :)

#Ignore SSL Errors
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}  

#Define supported Protocols
[System.Net.ServicePointManager]::SecurityProtocol = @("Tls12","Tls11","Tls","Ssl3")

Cheers!
Luciano Lingnau [Paessler Support]

Created on Apr 16, 2018 7:16:29 AM by  Luciano Lingnau [Paessler Support]

Last change on Jun 11, 2018 11:45:56 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

This works great. But is there similar sensors for the switches and gateways from Unifi?

Created on Jun 9, 2018 5:39:48 PM by  Artius (0)



Votes:

0

Your Vote:

Up

Down

Hello Artius,
thank you for your reply.

Regarding your inquiry:

This works great. But is there similar sensors for the switches and gateways from Unifi?

There are currently no plans for this. But should be possible with minor modifications to the script.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jun 11, 2018 11:45:46 AM by  Luciano Lingnau [Paessler Support]



Please log in or register to enter your reply.


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.