1- Odd method to acquire total number of active WiFi Clients
Bash script to acquire some info via UniFi controller like active number of WiFi clients connected with different UniFi AP LR in the company.
#!/bin/bash # Script to query active clients by curl from unifi controller # Syed jahanzaib / aacable . wordpress . com / aacable at hotmail dot com # 2nd-January-2017 #set -x # UniFi Controller IP and Port IP="10.0.0.1" PORT="8443" COOKIE="/tmp/cookies.txt" TMP_HOLDER="/tmp/$IP.active.wifi.clients.txt" # pattern to match to count active clients using string matching PATTERN="hostname" # First Login to controller via CURL curl -s "https://$IP:$PORT/api/login" --data-binary '{"username":"admin","password":"CONTROLLERPASSWORD","strict":true}' --compressed --insecure -c $COOKIE > /dev/null # Download Statistics from controller using CURL curl -s --insecure -b $COOKIE -c $COOKIE "https://$IP:$PORT/api/s/default/stat/sta" > $TMP_HOLDER # Count active users by pattern match, what an odd method, may not work correctly, but so far working for me ACTIVE=`cat $TMP_HOLDER | grep -o $PATTERN | wc -l` echo $ACTIVE echo $ACTIVE
Result in command …
CFG file for MRTG …
# Unifi Controller - WiFi Active WiFi Clients - syed.jahanzaib Target[unifi_wifi_active_users]: `/temp/unifi-client.sh` Title[unifi_wifi_active_users]: Active Wifi Clients via Unifi Controller PageTop[unifi_wifi_active_users]: <H1>Active Wifi Clients via Unifi Controller</H1> MaxBytes[unifi_wifi_active_users]: 50000 Colours[unifi_wifi_active_users]: B#8888ff,B#0813B7,B#5398ff,B#0813B7 Options[unifi_wifi_active_users]: growright,nopercent,gauge,integer,nobanner,printrouter,pngdate,noo LegendI[unifi_wifi_active_users]: Active Wifi Users LegendO[unifi_wifi_active_users]: YLegend[unifi_wifi_active_users]: Active Wifi Users Legend1[unifi_wifi_active_users]: Active Wifi Users Legend2[unifi_wifi_active_users]: ShortLegend[unifi_wifi_active_users]: #Unscaled[unifi_wifi_active_users]: dwmy
MRTG Graph for Active WiFi Clients via UniFi Controller …
- – – – – – – – – –
- – – – – – – – – –
- – – – – – – – – –
- – – – – – – – – –
Following are some snapshots from the UniFi Controller for some comparison that script is working accurate so far …
(However it is still under observation to monitor its accuracy result / zaib)
2- Odd method to acquire total number of Active Access Points Vs Down [Registered in UniFi Controller]
Bash script to acquire total number of registered access points (unifi AP-LR) and there status as well to compare Active vs down.
#!/bin/bash # Script to query active clients by curl from unifi controller #set -x IP="10.0.0.1" PORT="8443" COOKIE="/tmp/cookies.txt" TMP_HOLDER="/tmp/$IP.total.ap.txt" PATTERN="adopted" curl -s "https://$IP:$PORT/api/login" --data-binary '{"username":"admin","password":"CONTROLLERPASSWORD","strict":true}' --compressed --insecure -c $COOKIE > /dev/null curl -s --insecure -b $COOKIE -c $COOKIE "https://$IP:$PORT/api/s/default/stat/device" > $TMP_HOLDER ACTIVE=`cat $TMP_HOLDER | grep -o $PATTERN | wc -l` DOWN=`grep -oP '\"state\" : \K[^ ]*' $TMP_HOLDER | grep 0 | wc -l` echo $DOWN echo $ACTIVE
Result in command …
[Total access points vs DOWN]
CFG file for MRTG …
# Unifi Controller - UniFi AP-LR - Active Access Points vs DOWN Target[unifi_ap_total_vs_down]: `/temp/unifi-devices.sh` Title[unifi_ap_total_vs_down]: UniFi AP-LR - Active Access Points vs DOWN PageTop[unifi_ap_total_vs_down]: <H1>UniFi AP-LR - Active Access Points vs DOWN</H1> MaxBytes[unifi_ap_total_vs_down]: 5000 Colours[unifi_ap_total_vs_down]: B#0000FF,R#FF0000,B#0000FF,R#FF0000 Options[unifi_ap_total_vs_down]: growright,nopercent,gauge,integer,nobanner,printrouter,pngdate LegendI[unifi_ap_total_vs_down]: Active AP --> LegendO[unifi_ap_total_vs_down]: Down AP --> YLegend[unifi_ap_total_vs_down]: Active vs Down Legend1[unifi_ap_total_vs_down]: Active Access Points Legend2[unifi_ap_total_vs_down]: Down Access Points ShortLegend[unifi_ap_total_vs_down]: #Unscaled[unifi_ap_total_vs_down]: dwmy
MRTG Graph for Active WiFi AP DEVICES via UniFi Controller …
3# Upgrade UniFi AP LR Access Point via SSH/CLI
We have few unifi AP-LR Wireless Access Points in our company which are connected with the Unifi Controller ver 5.2.9.0 on windows 2008 r2 / x64 server. For some unknown reasons I was unable to upgrade the access point’s firmware from the controller. Therefore I upgraded all AP’s via SSH method which is posted below …
First download the appropriate firmware and upload it to some web server. (at the time of upgrading the latest firmware version was 3.7.21.5389 , you make sure to download latest one available)
Select your model / download from following link …
[Luckily I had local web server available so I simply put this file into my /var/www folder (for ubuntu)]
Now login in the access point via SSH , and issue this command
upgrade http://101.0.0.1/BZ.ar7240.v3.7.21.5389.161017.0923.bin
Make sure to change the path or ip according to your network. Once its upgraded it rebooted and new Firmware was 3.7.21.5389
I will post more info later … 3.7.21.5389
Regard’s
Syed Jahanzaib
Filed under: Ubiquiti