
Monitoring Ubiquiti UniFi at Centreon
And it's time to rule Ubiquiti's APs and switches! So if you have any such device in your organization… it is time to centralise and control it from Centreon. With the mere fact of having everything supervised and anticipating possible problems, ¡Started! 😛
Well, For many of the services we're going to monitor, we'll rely on the wonderful Script check_unifi.php by Jörg Hörter; so download it and as always save it in the Centreon scripts directory. With this script we will be able to get a lot of information from the UniFi part of Ubiquiti, what is the health of each PA, Your traffic, clients, Connections, Resource consumption… Same for switch'es, and the same goes for the controller, availability, Versioning, number of APs/SWs..
We need to have php installed on the machine and 'php-curl', Once the requirements are installed, we try to run it:
yum install php-curl /usr/bin/php check_unifi.php
This script if we pass '-h’ nos dará información con todas sus posibilidades de uso:
Usage: /usr/bin/php check_unifi.php -H [controller] -u [controlleruser] -p [controllerpassword] -P [controllerport] -m [mode] -a [Accesspoint] -w [Warning] -c [Critical] (-S [site] -s =https -C [configfile]) -d =debug) mode - controller = Controller Version, warning if there is an update site = list all Site ID and Name clients = list all clients (only use in console) clients_wifi ( + Accesspoints) = list all wifi clients with connection speed, optional for one accesspoint (only use in console) clients_name + Accesspoint = list all clients of an accesspoint clients_name_guest + Accesspoint = list all clients and guests of an accesspoint clients_count + Accesspoint = count clients of an accesspoint clients_count_guest + Accesspoint = count clients and guests of an accesspoint channels + Accesspoint = channels 2GHz/5GHz of an accesspoint transfer + Accesspoint = rx/tx transfer of an accesspoint (KBit/MBit) transfer+ + Accesspoint = rx/tx transfer of an accesspoint (KByte/MByte) Uptime + Accesspoint/Switch = uptime and firmware of an accesspoint/switch update + Accesspoint/Switch = update firmware is available of an accesspoint/switch and warn/critical (point release, major version, minor version) uplink + Accesspoint warn crit = uplink of an accesspoint (wireless: with connection speed and warn/critical) experience + Accesspoint warn crit = wireless experience of an accesspoint with warn/critical utilisation + Accesspoint warn crit = wireless utilisation of an accesspoint with warn/critical (2GHz,5GHz) Mem + Accesspoint warn crit = memory usage output Mb of an accesspoint or a switch with warn/critical percent mem% + Accesspoint warn crit = memory usage output percent of an accesspoint or a switch with warn/critical percent cpu + Accesspoint/Switch warn crit = cpu and load combination usage of an accesspoint or a switch with warn/critical percent cpu% + Accesspoint/Switch warn crit = cpu usage of an accesspoint or a switch with warn/critical percent load + Accesspoint/Switch warn crit = linux load usage of an accesspoint or a switch with warn/critical 1,5,15 temperature + Switch = temperature of a switch with warn/critical ap warn crit = count Accesspoint (Online and Offline) with warn and critical offline Accesspoints switch warn crit = count Switch (Online and Offline) with warn and critical offline Switch -C - config file (default=unifi.php) instead of the controller parameters -H,-u,-p,-P,-s -S (you can specify any file with path) example: <?php $host='192.168.2.213'; # IP or Hostname unifi controller Server $prot='https'; # Value http or https $port='8443'; # Controller Port $user='nagios'; # Loginuser Controller $pass='nagios'; # Password Loginuser $siteid='default'; # Site ID $dir_unifi_client=''; # Directory unifi_client.php ?>
Well, If you want to tinker with it in Shell and see how it goes/try it, Here are some examples, Not all possibilities, but those that I considered most useful (For me):
Check Controller version and give Warning if there is an update:
/usr/bin/php /usr/lib/centreon/plugins/check_unifi.php/check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m controller -s https
Clients per AP:
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m clients_count -a NOMBRE_AP -s https
2GHz/5GHz channels of each AP:
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m channels -a NOMBRE_AP -s https
Check AP/SW firmware version:
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m update -a NOMBRE_AP -s https
Quality of AP Experience:
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m experience -a NOMBRE_AP -w 90: -c 80: -s https
CPU del AP/SW
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m cpu% -a NOMBRE_AP -w 80 -c 90 -s https
AP/SW Memory
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m mem% -a NOMBRE_AP -w 80 -c 90 -s https
AP/SW Load
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m load -a NOMBRE_AP -w 4,3,2 -c 6,5,4 -s https
SW Temperature
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m temperature -a NOMBRE_SWITCH -w 40 -c 50 -s https
SW or AP Uptime
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m uptime -a NOMBRE_SWITCH -w 80 -c 90 -s https
Number of APs
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m ap -w 1 -c 0 -s https
Number of SWs
/usr/bin/php ./check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USER -p PASSWORD -m switch -w 1 -c 0 -s https
Now, Once you've tinkered and tasted, it's time to take it as usual to Centreon, as usual, initially we will define the Commands that we will need to then create the Services that interest us. In my case I have created these 4 Commands, I leave them to you in case you want to copy them, some go with more or less arguments and the possibility of putting Warning / Critical if we were interested. We're going to “Configuration” > “Commands” > “Checks” > “Add…”
- Command Name: check_unifi.php
- Command Line: /usr/bin/php $CENTREONPLUGINS$/check_unifi.php/check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m $ARG 1$ -s https
- Command Name: check_unifi.php_wc
- Command Line: /usr/bin/php /usr/lib/centreon/plugins/check_unifi.php/check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m $ARG 1$ -w $ARG 2$ -c $ARG 3$ -s https
- Command Name: check_unifi.php_a
- Command Line: /usr/bin/php /usr/lib/centreon/plugins/check_unifi.php/check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m $ARG 1$ -a $ARG 2$ -s https
- Command Name: check_unifi.php_a_wc
- Command Line: /usr/bin/php /usr/lib/centreon/plugins/check_unifi.php/check_unifi.php -H DIRECCION_IP_CONTROLLER -P 8443 -u USERNAME -p PASSWORD -m $ARG 1$ -a $ARG 2$ -w $ARG 3$ -c $ARG 4$ -s https
And then from “Configuration” > “Hosts” > “Add…” we must register the PAs as usual, SW, machine with Controller… with the ultimate goal of adding the services that we are interested in monitoring each Host.
So finally from “Configuration” > “Services” > “Services by Host” We are adding the Services, and we associate each one with the Command that must be carried and we feed them with the corresponding Arguments.
If we want to put the state of the Hardware to the Switches, we will use the wonderful Centreon plugin pack called 'centreon-plugins', that we already saw how to use it and use it In this post. And this script does use SNMP, so you will have to enable it previously in the 'UniFi Network' console, since “Settings” > “Advanced Features” > “Advanced Gateway Settings” > “SNMP” and set up a Community for v2 or if we want v3 some credentials. And with the next Command we would have it sucked:
perl $CENTREONPLUGINS$/centreon-plugins/centreon_plugins.pl --plugin=network::Ubiquiti::Edge::snmp::plugin --hostname $HOSTADDRESS$ --snmp-community=$_HOSTSNMPCOMMUNITY$ --mode hardware
As usual, Record and export settings.
If we've followed all the steps we'll have something like this above, Excuse me but you know it's crazy if I do one by one. If you have doubts about the use of Centreon, it is better to go to initial documents where it gave more detail on how to create a Service, a Commando… So you're done! We have the CPUs, Network Interfaces/Ports, Memoirs, Loads, Wifi Channels, Versioning and firmwares, Experiences, Temperatures, Hardware Status… of our controlled Ubiquiti Access Points and Switches!
And if we have a Grafana Well, we can make some cool visualizations, Mine is a bit crappy, but acceptable, I have this one designed for a tiny 😉 screen So I couldn't put more in it.