blob: b6009180cd1a9c57c1d24dc8efe6053b93e0e91a [file] [log] [blame]
Willy Tarreau29b25312016-11-08 14:57:29 +01001DeviceAtlas Device Detection
2----------------------------
3
4In order to add DeviceAtlas Device Detection support, you would need to download
David Carlier019dbd72021-02-16 11:37:45 +00005the API source code from https://deviceatlas.com/deviceatlas-haproxy-module.
6The build supports the USE_PCRE and USE_PCRE2 options. Once extracted :
Willy Tarreau29b25312016-11-08 14:57:29 +01007
David Carliere0724582021-02-19 12:01:38 +00008 $ make TARGET=<target> USE_PCRE=1 (or USE_PCRE2=1) USE_DEVICEATLAS=1 DEVICEATLAS_SRC=<path to the API root folder>
Willy Tarreau29b25312016-11-08 14:57:29 +01009
10Optionally DEVICEATLAS_INC and DEVICEATLAS_LIB may be set to override the path
11to the include files and libraries respectively if they're not in the source
David Carlierb81483c2022-01-27 18:13:54 +000012directory. However, if the API had been installed beforehand, DEVICEATLAS_SRC
13can be omitted. Note that the DeviceAtlas C API version supported is the 2.4.0
14at minimum.
Willy Tarreau29b25312016-11-08 14:57:29 +010015
Michael Prokop4438c602019-05-24 10:25:45 +020016For HAProxy developers who need to verify that their changes didn't accidentally
David Carlier0470d702019-04-26 12:02:28 +000017break the DeviceAtlas code, it is possible to build a dummy library provided in
Willy Tarreauf8d9ec52021-04-02 16:19:39 +020018the addons/deviceatlas/dummy directory and to use it as an alternative for the
19full library. This will not provide the full functionalities, it will just allow
David Carlier0470d702019-04-26 12:02:28 +000020haproxy to start with a deviceatlas configuration, which generally is enough to
21validate API changes :
22
Willy Tarreauf8d9ec52021-04-02 16:19:39 +020023 $ make TARGET=<target> USE_PCRE=1 USE_DEVICEATLAS=1 DEVICEATLAS_SRC=$PWD/addons/deviceatlas/dummy
David Carlier0470d702019-04-26 12:02:28 +000024
Willy Tarreau29b25312016-11-08 14:57:29 +010025These are supported DeviceAtlas directives (see doc/configuration.txt) :
26 - deviceatlas-json-file <path to the DeviceAtlas JSON data file>.
27 - deviceatlas-log-level <number> (0 to 3, level of information returned by
28 the API, 0 by default).
29 - deviceatlas-property-separator <character> (character used to separate the
30 properties produced by the API, | by default).
31
32Sample configuration :
33
34 global
35 deviceatlas-json-file <path to json file>
36
37 ...
38 frontend
39 bind *:8881
40 default_backend servers
41
42There are two distinct methods available, one which leverages all HTTP headers
43and one which uses only a single HTTP header for the detection. The former
44method is highly recommended and more accurate. There are several possible use
45cases.
46
47# To transmit the DeviceAtlas data downstream to the target application
48
49All HTTP headers via the sample / fetch
50
51 http-request set-header X-DeviceAtlas-Data %[da-csv-fetch(primaryHardwareType,osName,osVersion,browserName,browserVersion,browserRenderingEngine)]
52
Michael Prokop4438c602019-05-24 10:25:45 +020053Single HTTP header (e.g. User-Agent) via the converter
Willy Tarreau29b25312016-11-08 14:57:29 +010054
55 http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv-conv(primaryHardwareType,osName,osVersion,browserName,browserVersion,browserRenderingEngine)]
56
57# Mobile content switching with ACL
58
59All HTTP headers
60
61 acl is_mobile da-csv-fetch(mobileDevice) 1
62
63Single HTTP header
64
65 acl device_type_tablet req.fhdr(User-Agent),da-csv-conv(primaryHardwareType) "Tablet"
66
David Carlierb81483c2022-01-27 18:13:54 +000067Optionally a JSON download scheduler is provided to allow a data file being
68fetched automatically in a daily basis without restarting HAProxy :
69
70 $ cd addons/deviceatlas && make [DEVICEATLAS_SRC=<path to the API root folder>]
71
72Similarly, if the DeviceAtlas API is installed, DEVICEATLAS_SRC can be omitted.
73
74 $ ./dadwsch -u JSON data file URL e.g. "https://deviceatlas.com/getJSON?licencekey=<your licence key>&format=zip&data=my&index=web" \
75 [-p download directory path /tmp by default] \
76 [-d scheduled hour of download, hour when the service is launched by default]
77
78Noted it needs to be started before HAProxy.
79
Willy Tarreau29b25312016-11-08 14:57:29 +010080
David Carlierb81483c2022-01-27 18:13:54 +000081Please find more information about DeviceAtlas and the detection methods at
82https://deviceatlas.com/resources .