Ubnt API Aircontrol
Ubnt API Aircontrol
4 API
For use with development build: Open the About dialog. Press CTRL-SHIFT-U Change update site URL to: http://www.ubnt.com/downloads/aircontrol/upd138/ Click Check for Updates and then update to the new version shown
(URL above is not for entry into the browser address bar but into the AirControl update dialog.) To revert to previous version: stop server Go into the <ACDIR>/webapps directory delete ROOT/ delete ROOT.war rename previous archive to ROOT.war start server
There is also a sample HTML/JavaScript example for JSON and dynamic script tags that you can get from the running server:
http://localhost:9080/ApiGetDeviceList.html
http://localhost:9080/api/devices/00:15:6D:72:42:0E/currentStats?auth.user=ubnt&auth.password=ubnt&type=tsv URL query parameters including output options are same as for device group list.
Statistics History:
Single Device:
http://localhost:9080/api/devices/00:15:6D:72:42:0E/stats/wlanTxBytes? auth.user=ubnt&auth.password=ubnt&statsIntervalPeriod=hour&statsIntervalCount=24
Parameters: MAC ID and attribute name in the URI. Attribute name (not title) as found in the Attribute Configuration dialog in the GUI. statsIntervalPeriod: Aggregation/time interval ('minute', 'hour', 'day', 'week') statsIntervalCount: Number of intervals in the ouput. Currently only supports TSV output format. The report will have a column for each interval, with the interval start date as header. Report currently does not contain line or column summary (sum, min, max, avg). Device Group:
http://localhost:9080/api/devicegroup/All%20Devices/stats/wlanTxBytes? auth.user=ubnt&auth.password=ubnt&statsIntervalPeriod=hour&statsIntervalCount=24
One of the use cases is to generate usage reports and load the data into a spreadsheet application for further processing.
Get Device Map KML
http://localhost:9080/api/devicegroup/All%20Devices/map/kml?auth.user=ubnt&auth.password=ubnt
The resulting KML file can be loaded into Google earth or viewed through Google maps (http://econym.org.uk/gmap/kml.htm)
Specifying the the port numbers as null or omitting them will indicate that the system wide settings should be effective for the new device.
Remove Device
Control Operations
A few control operations are now available: Connect, upgrade (optional for non-managed device), restore configuration. Affected devices can be specified as MAC address list or device group. Example on how to submit a request specified in a file as HTTP POST request:
wget -v -O ac-response.txt --post-file ac-request.txt --header="Content-Type: application/json" 'http://localhost:9080/api/task?auth.user=ubnt&auth.password=ubnt'
Above submits the file api-request.txt (JSON format) to AirControl, running on localhost:9080, using login ubnt/ubnt. The account used to schedule tasks must have ADMIN priviledge. The request will be executed asynchronously, look at the progress list in AC and the system log for results. Successful scheduled will result in HTTP status 201. Should the request return HTTP error 500, check <AC_HOME>/logs/server.log. Most likely the JSON format was invalid. Currently there is no way to poll the task status through the API based on the task identifier returned with HTTP response status 201; this is something that will be added in the future. At this time it is fire and forget as far as the API client is concerned. If you received status 201, AirControl has scheduled the request and it will for a short time appear in the schedule list. Once processing, look for status in the respective device details (like any other in-progress operation in AirControl). Should processing fail, the error will be recorded in the event log. The API request specifics are encoded in JSON format in the file. Sample payloads are given below, copy these into the text file referenced on the wget command line. Each request has the common parameter deviceMacList or deviceGroup. Device groups can be specified as the simple name of any of the groups under "Watch" in the group tree (e.g. "All Devices" or "Low Signal") or, for convenience, also auto-groups, such as "AP-Groups/THOMAS-NSM2-UPD5", where the leading path component is the grouping name and the second component the specific attribute value.
(The device(s) must have been added in AirControl before.) Connect using device authentication with SSH key instead of password:
{ "actionType" : "connect", "deviceMacList":["00:15:6D:16:C3:7B"], "login": "ubnt", "sshKeyFile": "/ubnt/console/test/config/id_rsa_api" }
Upgrade device:
{ "actionType" : "firmwareUpdate", "deviceMacList":["00:15:6D:16:C3:7B"], "firmwareVersion" : "XM.ar7240.v5.3-beta5.7493.101210.2221"
Upgrade unmanaged device with explicit device authentication (SSH key): { "actionType" : "firmwareUpdate", "deviceMacList":["00:15:6D:16:C3:7B"], "firmwareVersion" : "XM.ar7240.v5.3-RC2.7694.110105.1630", "login": "ubnt", "sshKeyFile": "/ubnt/console/test/config/id_rsa_api" }
A not so obvious use case for this: Backup a set of devices (from the AirControl UI, on-demand or scheduled) Manipulate the configuration files with a custom routine (at your own risk!) Restore manipulated files through the API to all units. Note this not a recommended solution for configuration change, use at own risk if you know how to deal with system.cfg and want to accomplish things that cannot be accomplished through higher level tools at this time!
(Mass) Configuration
A limited set of parameters is available for configuration through the API (see list below examples). Supported firmware versions are 5.3 and 3.6. This is alpha functionality. Please always test on a radio that you can reset easily before applying changes to multiple or critical devices. If you are running AirControl on Linux and using OpenJDK (not Sun JDK): Some OpenJDK distributions do not include the script engine that is required by the configuation API. I have seen it missing on Centos, Fedora OpenJDK etc. distributions. I have seen it present on Ubuntu 9.x and 10.x. If you see an error in the system log referring to the script engine, please either install the Sun JDK or email for instructions on how to add it to the existing OpenJDK (mention exact Linux and OpenJDK version). When changing multiple devices in the same request, make sure to only specify devices that are managed and online. Changing many devices in a batch will synchronize the configuration change so that restart occurs at the same time (the larger the batch the more system resources are required to process it and may impact the performance of your server significantly). Batch request will be cancelled if any one device fails to update (necessary for
change of parameters that affect dependency within groups). Also make sure to test changes before applying to multiple/many units. If changes do not require synchronized execution, specify serial execution to change one device at a time and ignore processing errors (add "executeSequential" : true to the request). The default is "false" synchronized batch processing.
{ "actionType" : "configure" "deviceGroup": "MyDeviceGroup", "executeSequential" : true, "attributeValues" : { ... }
As general guideline, keep batch sizes relatively small for synchronized changes such as wireless paramaters that requires all devices to be updated at once and use sequential processing other modifications. The configuration changes are specified as a list of attributes, which will be applied on top of the current configuration on the device. Each request can contain multiple key-value pairs. Some of those parameters have dependencies. For example, you first need to enable WPA security before attempting to set the PSK. Likewise, you only need to send the PSK if WPA was already enabled. Below are examples only, which you can adjust to the current configuration state of the devices. Note that the keys used, while they may match the property names in system.cfg on the device, are not the same property names. They are mapped by AirControl and you will only be able to change what is published in the API. (Amongst other reasons this is necessary to enforce integrity rules and guard from misconfiguration.) Examples: Change security to WPA and set PSK:
{ "actionType" : "configure", "deviceMacList":["00:15:6D:16:C3:7B"], "attributeValues" : { "wireless.1.security" : "wpa", "wireless.1.security.wpa.auth" : "WPA-PSK", "wireless.1.security.wpa.psk" : "1234567890" }
} Change SSID, wireless mode, channel width, channel shifting (v5.3, M2):
{ "actionType" : "configure", "deviceMacList":["00:15:6D:16:C3:7B"], "attributeValueList" : [ ["radio.1.mode", "stawds"], ["wireless.1.ssid", "SSIDTEST1"], ["radio.1.clksel" , "E"], ["radio.1.rate.max" , "7"], ["radio.1.chanshift" , "enabled"] ]
"actionType" : "configure", "deviceMacList":["00:15:6D:16:C3:7B"], "attributeValueList" : [ ["system.users.1.name", "admin"], ["system.users.1.password.confirm", "ubnt"], ["system.users.1.password", "ubnt"] ]
List of currently supported parameters as of v1.3.7 (will be expanded in the near future and as per feedback received): More has been added since. Use the device configuration dialog in the AirControl GUI to confirm supported settings. Make changes in the configuration tree and then review the parameters on the confirmation step. Values displayed there are the same that need to be sent through the API. Parameter RADIO SETTINGS
AirMax Priority radio.1.airmax-priority radio.1.mode IEEE mode radio.1.ieee_mode Channel Width radio.1.clksel {0:'High',1:'Medium',2:'Low',3:'None'}
Allowed values/description
"0" 20 MHz
"disabled" "enabled" Maximum TX Rate as index. Compare drop-down in AirOS UI Wireless Tab. Values for AirOS 5.3: [7,6,5,4,3,2,1,0] and [15..0] for 2x2 chain Values for 3.6:
{ [7..0] for 5GHz / A mode } { [3..0] for 2GHz / B only } { [7..0] for 2GHz / G only } { [7..0] for 2GHz / B/G mixed / 5 or 10MHz } { [11..0] for 2GHz / B/G mixed / 20MHz }
"disabled" "enabled" The output power at which wireless module transmits data . The minimun and maximum power depends on product. Below are the examples Bullet M5:- min:6dBm,max:25dBm Bullet M2:- min:12dBm,max:28dBm Rocket M2X2:- min: -3dBm,max:28dBm Picostation 5:- min:3dBm,max:22dBm PicoStation 2:- min:4dBm,max:20dBm It should be less than max distance for given IEEE mode and channel width Defaults to max distance if input distance is greater than max distance Examples: AirOS 3.x {[max:32.7miles] for B/G Mixed and 20Mhz}, {[max:65.9miles] for B/G Mixed and 10Mhz},
Output Power
radio.1.txpower
Ack distance
radio.1.ackdistance
Ack Timeout
radio.1.acktimeout
{[max:132miles] for B/G Mixed and 5Mhz}, {[max:67miles] for B Only and 20Mhz}, AirOS 5.x {[max:32.2miles] for B/G/N Mixed and 20Mhz}, {[max:65.3miles] for B/G/N Mixed and 10Mhz}, {[max:131miles] for B/G/N Mixed and 5Mhz},
It should be between Min and Max values . Min and Max values for timeout are derived based on IEEE mode, channel width and depend on the AirOS version. If value is <min then it defaults to min For value is >max defaults to max Examples: AirOS 3.x {[min:21 max:372] for B/G mixed and 20Mhz}, {[min:37 max:744] for B/G mixed and 10Mhz}, {[min:73 max:1489] for B/G mixed and 5Mhz}, {[min:25 max:744] for B Only and 20Mhz}, {[min:11 max:204] for A Only and 40Mhz}, AirOS 5.x {[min:27 max:204] for A/N mixed(11naht40,11naht40Plus,11naht40Minus) and 40Mhz}, {[min:37 max:409] for A/N mixed(11naht20) and 20Mhz}
Auto Ack
radio.1.ack.auto.status
enabled or disabled AirOS 3.x ONLY. Possible values are same as "radio.1.rate.max" Possible values AirOS 3.6: {"ath_rate_sample":"Optimistic","ath_rate_onoe":"Conservative","ath_rate_minstrel","EWMA "} <ESSID> enabled or disabled
Muticast Rate
radio.1.mcastrate
Rate Algorithm
radio.1.rate_modue
WIRELESS/SSID
wireless.1.ssid wireless.1.mac_acl.status
"allow", "deny"
comma separated list of MAC IDs "wpa" "wpatkip" "wpaaes" "wpa2" "wpa2tkip" "wpa2aes" "wep64" "wep128" "wep152" "none" "WPA-PSK", "WPA-EAP" station mode only (valid with "wireless.1.security"= "wpa"XXX) <PSK> (valid with "wireless.1.security.wpa.auth"= "WPA-PSK") "TTLS", "PEAP" valid with "wireless.1.security.wpa.auth"= "WPA-EAP" station mode only "MSCHAPV2" // fixed
wireless.1.security.wpa.auth
wireless.1.security.wpa.psk wireless.1.security.wpa.eap.type
wireless.1.security.wep.key-length wireless.1.security.wep.key-type
WEP Key Length: "wep64" 64 bit, "wep128" 128 bit "1" hex "2" - ascii
wireless.1.security.wep.key
WEP key (Length depends on WEP key length and type, see AirOS UI Wireless Tab)
wireless.1.security.wep.authmode
"Authentication Type" : "1" - open, "2" - shared key <name of the device> System location, coordinates in decimal notation, e.g. -122.049200 <user name> - default "ubnt" The new password, sent twice. Configuration of read-only account. Status is either "enabled" or "disabled"
SYSTEM
system.device.name system.latitude system.longitude system.users.1.name system.users.1.password.confirm system.users.1.password system.users.2.status system.users.2.name system.users.2.password
SERVICES
service.pwdog.status service.pwdog.host service.pwdog.period service.pwdog.delay service.pwdog.retry service.sshd.status service.sshd.port service.snmp.status service.snmp.community service.snmp.contact service.snmp.location service.ntpclient.status NTP "enabled" SNMP "enabled"
PING WATCH DOG "enabled" or "disabled" IP Address To Ping Ping Interval (seconds) Startup Delay (seconds) Failure Count To Reboot
SSH "enabled"
or "disabled"
service.ntpclient.server service.webserver.https.status service.webserver.https.port service.webserver.http.port service.webserver.session.timeout service.telnet.status service.telnet.port service.syslog.status service.syslog.remote.ip service.syslog.remote.port service.syslog.remote.status service.dynamic-dns.status service.dynamic-dns.hostname service.dynamic-dns.username service.dynamic-dns.password "enabled" SYSLOG "enabled" TELNET "enabled" WEBSERVER "enabled"
or "disabled"
or "disabled" or "disabled"
or "disabled" or "disabled"