Siddhi-execution-geo
The siddhi-execution-geo extension is an extension to Siddhi that provides geo data related functionality such as checking whether a given geo coordinate is within a predefined geo-fence, etc. Following are the functions of the Geo extension.
Find some useful links below:
Latest API Docs
Latest API Docs is 5.0.1.
How to use
Using the extension in WSO2 Stream Processor
-
You can use this extension in the latest WSO2 Stream Processor that is a part of WSO2 Analytics offering, with editor, debugger and simulation support.
-
This extension is shipped by default with WSO2 Stream Processor, if you wish to use an alternative version of this extension you can replace the component jar that can be found in the
<STREAM_PROCESSOR_HOME>/lib
directory.
Using the extension as a java library
- This extension can be added as a maven dependency along with other Siddhi dependencies to your project.
<dependency>
<groupId>org.wso2.extension.siddhi.execution.geo</groupId>
<artifactId>siddhi-execution-geo</artifactId>
<version>x.x.x</version>
</dependency>
Jenkins Build Status
Branch | Build Status |
---|---|
master |
Features
- findCityFromIP (Function)
This function returns the city that is related to the given IP address.
- findCountryFromIP (Function)
This function returns the country that is related to the given IP address.
- geocode (Stream Function)
The geo code stream function uses basic details relating to a location (e.g., street name, number,etc.) as the input and returns the longitude, latitude, and the address of that location.
- geocoordinate (Stream Function)
The geocoordinate stream function returns the longitude and latitude values of a location relating to a given IPV4 or IPV6 address.
- reversegeocode (Stream Function)
This extension transforms pairs of latitude and longitude coordinates into precise address information. The output contains string properties including the 'streetNumber', 'neighborhood', 'route', 'administrativeAreaLevelTwo', 'administrativeAreaLevelOne', 'country', 'countryCode', 'postalCode', and the 'formattedAddress' in the given order. However, this information is not available for all the geo coordinates. For example, if the latitude and longitude represent a place in a forest, only the high level information such as the country is returned. In such scenarios, "N/A" is returned as the value for return attributes of which the values cannot be derived.
Dependencies
In order to use the functions supported by this extension, import the latest geo location data to the LOCATION
and BLOCKS
tables as follows:
-
First, create an account in the Maxmind site.
-
Then log in to the Maxmind site using your newly created credentials via the Login Form.
-
Download the
geoip-2-csv-converter
that is compatible with your operating system from the maxmind/geoip2-csv-converter github repository. -
Download and install a database type of your choice. Then start it, and create the required database and tables as follows:
!!!info This example uses MySQL.
-
Create a database named
GEO_LOCATION_DATA
. -
To create the required tables in the database, execute one of the following scripts.
It creates two tables named
BLOCKS
andLOCATION
.!!! info - In this example,
mysql.sql
database script is executed. - To execute the database script, you can use MySQL Workbench. For detailed instructions to run the database script, see MySQL Documentation - The Workbench Scripting Shell.
-
-
Prepare the database entries as follows:
-
Unzip the latest CSV file and the
geoip-2-csv-converter
that you downloaded in the steps above. -
Run the update-geolocation-data.sh file by issuing the following command:
sh update-geolocation-data.sh
-
Enter the path to the extracted
GeoLite2-City-Blocks-IPv4
directory that you downloaded as the response for theEnter path to GeoLite2-City-Blocks-IPv4 directory:
prompt (e.g.,/<PATH_TO>/GeoLite2-City-CSV_20171107
). -
Enter the path to the
geoip2-csv-converter
directory as the response for theEnter path to geoip2-csv-converter home directory:
prompt (e.g.,/<PATH_TO>/geoip2-csv-converter-v1.0.0
).
-
Once the script is executed, you can find the final.csv
file inside your current directory.
-
Import the data as follows:
-
To import the
final.csv
file (which you previously generated) into theBLOCKS
table, issue the following command after logging into the MySQL console.load data local infile '[PATH_TO_FINAL.CSV]/final.csv' into table BLOCKS fields terminated by ',' enclosed by '"' lines terminated by '\n' (network_cidr, network, broadcast, geoname_id, registered_country_geoname_id, represented_country_geoname_id, is_anonymous_proxy, is_satellite_provider, postal_code, latitude, longitude, network_blocks);
-
To import the
GeoLite2-City-Locations-en.csv
file located inside the extractedgeoip-2-csv-converter
directory (e.g.,geoip-2-csv-converterGeoLite2-City-CSV_2017110
) into theLOCATION
table, issue the following command.load data local infile '[PATH_TO_GeoLite2-City-Locations-en]/GeoLite2-City-Locations-en.csv' into table LOCATION fields terminated by ',' enclosed by '"' lines terminated by '\n' (geoname_id, locale_code, continent_code, continent_name, country_iso_code, country_name, subdivision_1_iso_code, subdivision_1_name, subdivision_2_iso_code, subdivision_2_name, city_name, metro_code, time_zone);
-
-
Restart the Streaming Integrator. You have now updated the Geo Location Data Set.
How to Contribute
-
Please report issues at GitHub Issue Tracker.
-
Send your contributions as pull requests to master branch.
Contact us
-
Post your questions with the "Siddhi" tag in Stackoverflow.
-
Siddhi developers can be contacted via the mailing lists:
Developers List : [email protected]
Architecture List : [email protected]
Support
-
We are committed to ensuring support for this extension in production. Our unique approach ensures that all support leverages our open development methodology and is provided by the very same engineers who build the technology.
-
For more details and to take advantage of this unique opportunity contact us via http://wso2.com/support/.