x-forwarded-for
header with the relevant IP in the API request.Note that this document uses MySQL as an example for configuring the GEO_LOCATION_DATA database.
- Use the Geolocation dataset that you created here.
Unzip the file you downloaded.
Create required tables in
GEO_LOCATION_DATA
database by executing one of the scripts in theGeolocation Data/dbscripts
directory. In this example,mysql.sql
is executed.This can be done using the MySQL Workbench.
For detailed instructions to run the database script, see MySQL Documentation - The Workbench Scripting Shell.
Restore data to the BLOCKS and LOCATION tables by importing data from the BLOCKS.csv and LOCATION.csv from the
.Geolocation Data/data
directory of the extracted zip using the commands given below.Importing Geolocation Data/data/
LOCATION
.csvmysqlimport -u root -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <path_to_folder_location>/GeolocationData/data/LOCATION.csv
Importing Geolocation Data/data/BLOCKS.csv
mysqlimport -u root -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <Extracted_location>/GeolocationData/data/BLOCKS.csv
For more information, see MySQL Documentation - Data Export and Import.
Check whether your imported dataset is working properly by executing the following query in the MySQL Command Line.
SELECT loc.country_name,loc.subdivision_1_name FROM BLOCKS block , LOCATION loc WHERE block.network_blocks = '<Network_part_of_ipv4>' AND
<Long_value_of_publilc_IP> BETWEEN block.network AND block.broadcast AND block.geoname_id=loc.geoname_id;
Example query:
SELECT loc.country_name,loc.subdivision_1_name FROM BLOCKS block , LOCATION loc WHERE block.network_blocks = '221.192' AND 3720398641
BETWEEN block.network AND block.broadcast AND block.geoname_id=loc.geoname_id;
- Download a JDBC provider depending on the database you are using (MySQL, in this example), and copy it to the
<APIM_ANALYTICS_HOME>/lib
directory. Configure the datasource for the Geo location.
A default datasource for Geo location is packed by default in the<APIM_ANALYTICS_HOME>/conf/worker/deployment.yaml
file under data sources.
You can edit the following data source to point to his own db and import the geo location data.- name: GEO_LOCATION_DATA description: "The data source used for geo location database" jndiConfig: name: jdbc/GEO_LOCATION_DATA definition: type: RDBMS configuration: jdbcUrl: 'jdbc:h2:${sys:carbon.home}/wso2/worker/database/GEO_LOCATION_DATA;AUTO_SERVER=TRUE' username: wso2carbon password: wso2carbon driverClassName: org.h2.Driver maxPoolSize: 50 idleTimeout: 60000 validationTimeout: 30000 isAutoCommit: false
For information on how to configure alerts, see Configuring Alerts.