Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_unifi.php Popular
1.20240514
2024-05-14
- Nagios 3.x
- Nagios 4.x
MIT
20293
If you find a bug or have a request, write me an email: nagios@jhoerter.com
You need to install php-curl and php Version above 7.2
Thanks to https://github.com/Art-of-WiFi
API Version 1.1.90
Note
Support for UniFi OS-based controllers (UniFi Dream Machine Pro or Cloud Key Gen2/Cloud Key Gen2 Plus with firmware version 2.0.24 or higher) has been added as of API version 1.1.47. The class automatically detects UniFi OS devices and adjusts URLs and several functions/methods accordingly. If your own code applies strict validation of the URL that is passed to the constructor, please adapt your logic to allow URLs without a port suffix when dealing with a UniFi OS-based controller.
In case of my script use -P 443 and -s
NEW
NEW API Version
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m uplink -a AP02 -w 200 -c 100
OK - Uplink: AP01 - signal=-67% tx_rate=234 Mbps rx_rate=526.5 Mbps | tx_rate=234;rx_rate=526.5;signal=67
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m cpu -a AP02 -w 80 -c 90
OK - 10.4% (load average: 0.01, 0.05, 0.05) | load=0.01;;;; load5=0.05;;;; load15=0.05;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m cpu% -w 75 -c 90
OK - 3.0% | cpu=3.0%;75;90;0;100
/usr/bin/php ./check_unifi.php -C -a AP01 -m load -w 1,1,1 -c 2,2,2
OK - load average: 0.02, 0.04, 0.01 | load=0.02;1;2;; load5=0.04;1;2;; load15=0.01;1;2;;
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m ap -w 0 -c 1
OK - AP [unifi.jhoerter.com]: 3 (Online: 3, Offline: 0) | AP=3 Online=3 Offline=0;0;1;;
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m switch -c 0
OK - Switch [unifi.jhoerter.com]: 1 (Online: 1 / Offline: 0) | Switch=1 Online=1 Offline=0;0;0;;
/usr/bin/php ./check_unifi.php -C -m mem -a AP03 -w 80 -c 90
OK - 54.09 MB | Total=122.66MB;98.13;110.39;0;122.66 Used=54.09MB;;;; Free=40.37MB;;;; Caches=28.20MB;;;;
/usr/bin/php ./check_unifi.php -C -m mem% -a AP03 -w 80 -c 90
OK - 44.10% (54.09 MB) | Total=100%;80;90;0;100 Used=44.10%;;;; Free=32.91%;;;; Caches=22.99%;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m clients_name_guest
OK - Clients [unifi.jhoerter.com]: 5/User:5/Guest:0 (2GHz: 2/U:2/G:0, 5GHz: 3/U:3/G:0) MACBOOK(5) VIRTUAL-WLAN(5) CAM01(2) TABLETT04(5) PRS01(2) | Clients=5;;;; 2GHz=2 5GHz=3
/usr/bin/php ./check_unifi.php -C -a AP01 -m channels
OK - 2GHz: auto (11(13,-1)) HT40 - 5GHz: auto (58(64,-1)) VHT80| 2GHz=11 5GHz=58
/usr/bin/php ./check_unifi.php -C -a AP01 -m transfer
OK - RX: 5,09 Mbit - TX: 166,84 Kbit | RX=5215,38Kbit;;;; TX=166,84Kbit;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m experience -w 30 -c 20
OK - WIFI Experience: 99% | Experience=99%;30;20;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m utilisation -w 75,75 -c 85,85
OK - 2GHz Utilized: 11% (RX Frames: 9%, TX Frames: 1%, Interference: 1%) - 5GHz Utilized: 8% (RX Frames: 6%, TX Frames: 2%, Interference: 0%)| 2GHz=11;75;85;; RX=9;;;; TX=1;;;; Interference=1 5GHz=8;75;85;; RX=6;;;; TX=2;;;; Interference=0
/usr/bin/php ./check_unifi.php -C -m update -a AP02 -w 1,1,1 -c 1,5,10
CRITICAL - firmware upgradable from version 4.3.28.11361 to 5.43.30.12622
/usr/bin/php ./check_unifi.php -C -m site
---------+------------------------------------
Site ID | Site Name
---------+------------------------------------
default | unifi.test.com
a3uobpaz | Test
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -s -u nagios -p nagios -S default -m uptime -a AP01
OK - UniFi AP-AC-Lite [unifi.test.com] - 0 days, 3 hours, 44 mins.| Uptime=13445
/usr/bin/php ./check_unifi.php -C -m client_transfer+ -a PC05 -r 0
OK - RX: 2.743 KB/s - TX: 16.066 KB/s (AP: AP03) | RX=2.743KByte;;;; TX=16.066KByte;;;;
/usr/bin/php ./check_unifi.php -C -m client_uplink -a MACBOOK
OK - Uplink: JHSAP01 (JH/ 5GHz) - signal: -78% TX: 650 Mbps RX: 260 Mbps | TX=650;0;0;; RX=260;0;0;; Signal=78
/usr/bin/php ./check_unifi.php -C -m client_uptime -a PHONE04
OK - 0 days, 0 hours, 18 mins.| Uptime=1124
/usr/bin/php ./check_unifi.php -C -m clients_count_guest
OK - Clients [unifi.test.com]: 13/ User:11/ Guest:2 (2GHz: 8/U:8/G:0, 5GHz: 5/U:3/G:2) | Clients=13;;;; 2GHz=8;;;; 5GHz=5;;;; User=11;;;; 2GhzU=8;;;; 5GhzU=3;;;; Guest=0;;;; 2GhzG=0;;;; 5GhzG=2;;;;
/usr/bin/php ./check_unifi.php -C -m clients_all
OK - Clients [unifi.test.com]: 32 (Wired: 21, Wifi: 11) | Clients=32;;;; Wired=21;;;; Wifi=11;;;;
/usr/bin/php ./check_unifi.php -C -m ap_unifi_name -w 0 -c 1
WARNING - AP: 4 (Online: 3, Offline: 1 (AP03-OLD)) | AP=4 Online=3 Offline=1;0;1;;
/usr/bin/php ./check_unifi.php -C -m clients_count_ssid -a WLAN
OK - SSID WLAN Client: 12 (2GHz: 7, 5GHz: 5) | Clients=12;;;; 2GHz=7 5GHz=5
/usr/bin/php ./check_unifi.php -C -m clients_wifi
OK - WiFi [default]: 13 (WiFi6=1, WiFi5=3, WiFi4=8) | WiFi=13;;;; WiFi6=1 Wifi5=3 WiFi4=8
/usr/bin/php ./check_unifi.php -C -m ap_unifi_name -w 0 -c 1 -a AP02-OLD,AP03-OLD
WARNING - AP: 3 (Online: 3, Offline: 0 | AP=3 Online=3 Offline=1;0;1;;
/usr/bin/php ./check_unifi.php -C -a PHONE01 -m client_experience -w 30 -c 20
OK - WIFI Experience: 99% | Experience=99%;30;20;;
/usr/bin/php ./check_unifi.php -C -m udm_temperature -a DREAMMACHINE -w 55,50,55 -c 60,60,60
WARNING - Temperature (CPU: 53 °C , Local: 50.75 °C , PHY: 53 °C) | CPU=53;55;60;; Local=50.75;50;60;; PHY=53;55;60;;
/usr/bin/php ./check_unifi.php -C -m lte -a LTEPRO
OK - LTE eutran-20 [o2 - de+] | connected=1
/usr/bin/php ./check_unifi.php -C -m lte_uplink -a LTEPRO -w -90,-15,-100 -c -100,-20,-110
CRITICAL - LTE-Uplink - RSSI: -80 dBm, RSRQ: -12 db, RSRP: -113dBm | RSSI=-80;-90;-100;; RSRQ=-12;-15;-20;; RSRP=-113;-100;-110;;
/usr/bin/php ./check_unifi.php -C -m lte_failover -a LTEPRO
OK - mode failover: off | failover=-a LTEPRO
/usr/bin/php ./check_unifi.php -C -m alarms_count
OK - no active Alarms (Archiv: 403) | Alarms=0;;;;
/usr/bin/php ./check_unifi.php -C -m clients_ssid -r 1 -i
WARNING - SSID Clients [unifi.test.com] - JH: 8, GUEST(G): enabled, CAM: 2 | Total=10 JH=8 GUEST=0 CAM=2
/usr/bin/php ./check_unifi.php -C -m switch_transfer+ -a SWITCH01 -n 3
OK - Port 3: NAS-LAN (1000 Mbit/s) - rx: 71.446 KB/s - tx: 2.301 MB/s | rx=71.446KB;;;; tx=2356.719KB;;;;
You need to install php-curl and php Version above 7.2
Thanks to https://github.com/Art-of-WiFi
API Version 1.1.90
Note
Support for UniFi OS-based controllers (UniFi Dream Machine Pro or Cloud Key Gen2/Cloud Key Gen2 Plus with firmware version 2.0.24 or higher) has been added as of API version 1.1.47. The class automatically detects UniFi OS devices and adjusts URLs and several functions/methods accordingly. If your own code applies strict validation of the URL that is passed to the constructor, please adapt your logic to allow URLs without a port suffix when dealing with a UniFi OS-based controller.
In case of my script use -P 443 and -s
NEW
NEW API Version
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m uplink -a AP02 -w 200 -c 100
OK - Uplink: AP01 - signal=-67% tx_rate=234 Mbps rx_rate=526.5 Mbps | tx_rate=234;rx_rate=526.5;signal=67
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m cpu -a AP02 -w 80 -c 90
OK - 10.4% (load average: 0.01, 0.05, 0.05) | load=0.01;;;; load5=0.05;;;; load15=0.05;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m cpu% -w 75 -c 90
OK - 3.0% | cpu=3.0%;75;90;0;100
/usr/bin/php ./check_unifi.php -C -a AP01 -m load -w 1,1,1 -c 2,2,2
OK - load average: 0.02, 0.04, 0.01 | load=0.02;1;2;; load5=0.04;1;2;; load15=0.01;1;2;;
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m ap -w 0 -c 1
OK - AP [unifi.jhoerter.com]: 3 (Online: 3, Offline: 0) | AP=3 Online=3 Offline=0;0;1;;
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -u nagios -p nagios -s -m switch -c 0
OK - Switch [unifi.jhoerter.com]: 1 (Online: 1 / Offline: 0) | Switch=1 Online=1 Offline=0;0;0;;
/usr/bin/php ./check_unifi.php -C -m mem -a AP03 -w 80 -c 90
OK - 54.09 MB | Total=122.66MB;98.13;110.39;0;122.66 Used=54.09MB;;;; Free=40.37MB;;;; Caches=28.20MB;;;;
/usr/bin/php ./check_unifi.php -C -m mem% -a AP03 -w 80 -c 90
OK - 44.10% (54.09 MB) | Total=100%;80;90;0;100 Used=44.10%;;;; Free=32.91%;;;; Caches=22.99%;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m clients_name_guest
OK - Clients [unifi.jhoerter.com]: 5/User:5/Guest:0 (2GHz: 2/U:2/G:0, 5GHz: 3/U:3/G:0) MACBOOK(5) VIRTUAL-WLAN(5) CAM01(2) TABLETT04(5) PRS01(2) | Clients=5;;;; 2GHz=2 5GHz=3
/usr/bin/php ./check_unifi.php -C -a AP01 -m channels
OK - 2GHz: auto (11(13,-1)) HT40 - 5GHz: auto (58(64,-1)) VHT80| 2GHz=11 5GHz=58
/usr/bin/php ./check_unifi.php -C -a AP01 -m transfer
OK - RX: 5,09 Mbit - TX: 166,84 Kbit | RX=5215,38Kbit;;;; TX=166,84Kbit;;;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m experience -w 30 -c 20
OK - WIFI Experience: 99% | Experience=99%;30;20;;
/usr/bin/php ./check_unifi.php -C -a AP01 -m utilisation -w 75,75 -c 85,85
OK - 2GHz Utilized: 11% (RX Frames: 9%, TX Frames: 1%, Interference: 1%) - 5GHz Utilized: 8% (RX Frames: 6%, TX Frames: 2%, Interference: 0%)| 2GHz=11;75;85;; RX=9;;;; TX=1;;;; Interference=1 5GHz=8;75;85;; RX=6;;;; TX=2;;;; Interference=0
/usr/bin/php ./check_unifi.php -C -m update -a AP02 -w 1,1,1 -c 1,5,10
CRITICAL - firmware upgradable from version 4.3.28.11361 to 5.43.30.12622
/usr/bin/php ./check_unifi.php -C -m site
---------+------------------------------------
Site ID | Site Name
---------+------------------------------------
default | unifi.test.com
a3uobpaz | Test
/usr/bin/php ./check_unifi.php -H 192.168.2.213 -P 8443 -s -u nagios -p nagios -S default -m uptime -a AP01
OK - UniFi AP-AC-Lite [unifi.test.com] - 0 days, 3 hours, 44 mins.| Uptime=13445
/usr/bin/php ./check_unifi.php -C -m client_transfer+ -a PC05 -r 0
OK - RX: 2.743 KB/s - TX: 16.066 KB/s (AP: AP03) | RX=2.743KByte;;;; TX=16.066KByte;;;;
/usr/bin/php ./check_unifi.php -C -m client_uplink -a MACBOOK
OK - Uplink: JHSAP01 (JH/ 5GHz) - signal: -78% TX: 650 Mbps RX: 260 Mbps | TX=650;0;0;; RX=260;0;0;; Signal=78
/usr/bin/php ./check_unifi.php -C -m client_uptime -a PHONE04
OK - 0 days, 0 hours, 18 mins.| Uptime=1124
/usr/bin/php ./check_unifi.php -C -m clients_count_guest
OK - Clients [unifi.test.com]: 13/ User:11/ Guest:2 (2GHz: 8/U:8/G:0, 5GHz: 5/U:3/G:2) | Clients=13;;;; 2GHz=8;;;; 5GHz=5;;;; User=11;;;; 2GhzU=8;;;; 5GhzU=3;;;; Guest=0;;;; 2GhzG=0;;;; 5GhzG=2;;;;
/usr/bin/php ./check_unifi.php -C -m clients_all
OK - Clients [unifi.test.com]: 32 (Wired: 21, Wifi: 11) | Clients=32;;;; Wired=21;;;; Wifi=11;;;;
/usr/bin/php ./check_unifi.php -C -m ap_unifi_name -w 0 -c 1
WARNING - AP: 4 (Online: 3, Offline: 1 (AP03-OLD)) | AP=4 Online=3 Offline=1;0;1;;
/usr/bin/php ./check_unifi.php -C -m clients_count_ssid -a WLAN
OK - SSID WLAN Client: 12 (2GHz: 7, 5GHz: 5) | Clients=12;;;; 2GHz=7 5GHz=5
/usr/bin/php ./check_unifi.php -C -m clients_wifi
OK - WiFi [default]: 13 (WiFi6=1, WiFi5=3, WiFi4=8) | WiFi=13;;;; WiFi6=1 Wifi5=3 WiFi4=8
/usr/bin/php ./check_unifi.php -C -m ap_unifi_name -w 0 -c 1 -a AP02-OLD,AP03-OLD
WARNING - AP: 3 (Online: 3, Offline: 0 | AP=3 Online=3 Offline=1;0;1;;
/usr/bin/php ./check_unifi.php -C -a PHONE01 -m client_experience -w 30 -c 20
OK - WIFI Experience: 99% | Experience=99%;30;20;;
/usr/bin/php ./check_unifi.php -C -m udm_temperature -a DREAMMACHINE -w 55,50,55 -c 60,60,60
WARNING - Temperature (CPU: 53 °C , Local: 50.75 °C , PHY: 53 °C) | CPU=53;55;60;; Local=50.75;50;60;; PHY=53;55;60;;
/usr/bin/php ./check_unifi.php -C -m lte -a LTEPRO
OK - LTE eutran-20 [o2 - de+] | connected=1
/usr/bin/php ./check_unifi.php -C -m lte_uplink -a LTEPRO -w -90,-15,-100 -c -100,-20,-110
CRITICAL - LTE-Uplink - RSSI: -80 dBm, RSRQ: -12 db, RSRP: -113dBm | RSSI=-80;-90;-100;; RSRQ=-12;-15;-20;; RSRP=-113;-100;-110;;
/usr/bin/php ./check_unifi.php -C -m lte_failover -a LTEPRO
OK - mode failover: off | failover=-a LTEPRO
/usr/bin/php ./check_unifi.php -C -m alarms_count
OK - no active Alarms (Archiv: 403) | Alarms=0;;;;
/usr/bin/php ./check_unifi.php -C -m clients_ssid -r 1 -i
WARNING - SSID Clients [unifi.test.com] - JH: 8, GUEST(G): enabled, CAM: 2 | Total=10 JH=8 GUEST=0 CAM=2
/usr/bin/php ./check_unifi.php -C -m switch_transfer+ -a SWITCH01 -n 3
OK - Port 3: NAS-LAN (1000 Mbit/s) - rx: 71.446 KB/s - tx: 2.301 MB/s | rx=71.446KB;;;; tx=2356.719KB;;;;
Reviews (7)
byTotter, January 8, 2024
What a great script. It works like a charm and is easy to understand!
I especially love the ability to check for updates ready to be installed. One minor thing is that I haven't been able to get warnings when you run Early Access update channel for your devices. But maybe it will come in a later version? :-)
At any rate I highly recommend this script as it is by far the best way I have seen to integrate Ubiquiti/Unifi to nagios.
I especially love the ability to check for updates ready to be installed. One minor thing is that I haven't been able to get warnings when you run Early Access update channel for your devices. But maybe it will come in a later version? :-)
At any rate I highly recommend this script as it is by far the best way I have seen to integrate Ubiquiti/Unifi to nagios.
byReiner030, December 26, 2022
Hello,
I tried to checkout this script on weekend but sadly on X-Mas the Whois entry of download URL was updated to some weird state - only NS entries are there, nothing more, so I even can't contact by email.
And sadly there is no alternate download possible like here or github so I could only hope that it would be fixed when recognized.
From uses PHP-client API the browser version looks very impresse what can bei all requested and monitored.
Bests Reiner
I tried to checkout this script on weekend but sadly on X-Mas the Whois entry of download URL was updated to some weird state - only NS entries are there, nothing more, so I even can't contact by email.
And sadly there is no alternate download possible like here or github so I could only hope that it would be fixed when recognized.
From uses PHP-client API the browser version looks very impresse what can bei all requested and monitored.
Bests Reiner
Owner's reply
Sorry, i wasn't a long time here, i have corrected it.
How to get it working with UniFi-CloudKey-Gen2-Plus? I can see from the review on February 5, 2021, that the user darco was able to get it working with Gen2 CloudKey. But unfortunately darco didn't specify, how he got it working...
What I do know is that Gen2 is not using port 8443 anymore, but access is done straight to HTTPS/443 port.
And I'm able to query the device info from the browser from:
https://[local-IP-of-Gen2-CloudKey]/proxy/network/api/s/default/stat/device
What I do know is that Gen2 is not using port 8443 anymore, but access is done straight to HTTPS/443 port.
And I'm able to query the device info from the browser from:
https://[local-IP-of-Gen2-CloudKey]/proxy/network/api/s/default/stat/device
Owner's reply
Please download the new Version 1.20210507
If it function please give me a feedback to info@jhoerter.com, thanks
bySysAdmRBE, April 22, 2021
Is it possible to get the total number of connected wifi clients with a nagios/centreon compatible check? The console check works fine but it would be great to get a counter inside the monitoring system.
Owner's reply
it's implementated in the new version 1.20210427
bykemecs, March 6, 2021
why "OK" the "Current Status:" on the nagios webgui?
>>>>
Current Status: OK (for 0d 3h 58m 35s)
Status Information: WARNING - Online: 1 - Offline: 1
Performance Data: AP=2 Online=1 Offline=1;0;1;;
the query is correct:
/usr/bin/php ./check_unifi.php -H 192.168.25.15 -u admin -p ********- -P 8443 -s -m ap -w 0 -c 1
WARNING - Online: 1 - Offline: 1 | AP=2 Online=1 Offline=1;0;1;;
>>>>
Current Status: OK (for 0d 3h 58m 35s)
Status Information: WARNING - Online: 1 - Offline: 1
Performance Data: AP=2 Online=1 Offline=1;0;1;;
the query is correct:
/usr/bin/php ./check_unifi.php -H 192.168.25.15 -u admin -p ********- -P 8443 -s -m ap -w 0 -c 1
WARNING - Online: 1 - Offline: 1 | AP=2 Online=1 Offline=1;0;1;;
Owner's reply
The error has been corrected in the current version 1.20210308.
Thank you very much!!
I've just tested with UniFi-CloudKey-Gen2-Plus
I've just tested with UniFi-CloudKey-Gen2-Plus
Downloaded the files and adjusted the clients.php
But then the skript does nothing. I can even use the example:
# usr/bin/php usr/local/nagios/libexec/check_unifi.php -H 192.168.2.1 -u USER -p PASS -P 8443 -s -m uplink -a AP01 -w 200 -c 100
And get nothing.
Any ideas?
(sorry, rating required)
But then the skript does nothing. I can even use the example:
# usr/bin/php usr/local/nagios/libexec/check_unifi.php -H 192.168.2.1 -u USER -p PASS -P 8443 -s -m uplink -a AP01 -w 200 -c 100
And get nothing.
Any ideas?
(sorry, rating required)
Owner's reply
Unfortunately I don't know which version is in use. A config.php is no longer required.