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.5.24.
    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 Oct 27, 2017 6:24:00 AM by  Luciano Lingnau [Paessler Support]



18 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.5.24.
    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 Oct 27, 2017 6:24:00 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)



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.