2011-03-09 Sancho Lerena <slerena@artica.es>

* conf/pandora_server.conf
        lib/PandoraFMS/Config.pm
        lib/PandoraFMS/DataServer.pm: Added support for Openstreetmaps
        API for reverse geolocation. 




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4073 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2011-03-09 13:49:30 +00:00
parent d3701182d0
commit e12de5ca51
4 changed files with 42 additions and 9 deletions

View File

@ -1,3 +1,10 @@
2011-03-09 Sancho Lerena <slerena@artica.es>
* conf/pandora_server.conf
lib/PandoraFMS/Config.pm
lib/PandoraFMS/DataServer.pm: Added support for Openstreetmaps API for
reverse geolocation.
2011-02-28 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DataServer.pm: Fixed a typo. Thanks to Kikuchi Koichiro.

View File

@ -225,7 +225,7 @@ max_log_size 65536
# When server have more than max_queue_files in incoming directory, skips the read
# the directory to avoid filesystem overhead.
max_queue_files 250
max_queue_files 500
# Use the XML file last modification time as timestamp.
# use_xml_timestamp 1
@ -277,6 +277,13 @@ max_queue_files 250
# This enable realtime reverse geocoding using Google Maps public api.
# This requires internet access, and could have performance penalties processing GIS
# information due the connetion needed to resolve all GIS input.
#
# NOTE: If you dont pay the service to google, they will ban your IP in a few days.
# google_maps_description 1
# This enable realtime reverse geocoding using Openstreet Maps public api.
# This requires internet access, and could have performance penalties processing GIS
# information due the connetion needed to resolve all GIS input.
# You can alter the code to use a local (your own) openstreet maps server.
# openstreetmaps_description 1

View File

@ -231,9 +231,10 @@ sub pandora_load_config {
$pa_config->{"recon_reverse_geolocation_file"} = '/usr/local/share/GeoIP/GeoIPCity.dat'; # 3.1
$pa_config->{"recon_location_scatter_radius"} = 50; # 3.1
$pa_config->{"update_parent"} = 0; # 3.1
$pa_config->{"google_maps_description"} = 0;
$pa_config->{"google_maps_description"} = 0;
$pa_config->{'openstreetmaps_description'} = 0;
$pa_config->{"max_queue_files"} = 250;
$pa_config->{"max_queue_files"} = 500;
# Internal MTA for alerts, each server need its own config.
$pa_config->{"mta_address"} = '127.0.0.1'; # Introduced on 2.0
@ -548,9 +549,12 @@ sub pandora_load_config {
elsif ($parametro =~ m/^restart\s+([0-1])/i) {
$pa_config->{'restart'} = clean_blank($1);
}
elsif ($parametro =~ m/^google_maps_description\s+([0-1])/i) {
$pa_config->{'google_maps_description'} = clean_blank($1);
}
elsif ($parametro =~ m/^google_maps_description\s+([0-1])/i) {
$pa_config->{'google_maps_description'} = clean_blank($1);
}
elsif ($parametro =~ m/^openstreetmaps_description\s+([0-1])/i) {
$pa_config->{'openstreetmaps_description'} = clean_blank($1);
}
elsif ($parametro =~ m/^activate_gis\s+([0-1])/i) {
$pa_config->{'activate_gis'} = clean_blank($1);
}

View File

@ -231,16 +231,30 @@ sub process_xml_data ($$$$$) {
$valid_position_data = 0;
}
if (!defined($position_description) ) { #FIXME: Validate the data with a regexp
if ((!defined($position_description)) && ($latitude != '')) { #FIXME: Validate the data with a regexp
# This code gets description (Reverse Geocoding) from a current GPS coordinates using Google maps API
# This requires a connection to internet and could be very slow and have a huge impact in performance.
# Other methods for reverse geocoding will be supplied in the future (openstreetmaps in a local server)
# Other methods for reverse geocoding are OpenStreetmaps, in nternet or in a local server
if ($pa_config->{'google_maps_description'}){
my $content = get ('http://maps.google.com/maps/geo?q='.$latitude.','.$longitude.'&output=csv&sensor=false');
my @address = split (/\"/,$content);
$position_description = $address[1];
}
elsif ($pa_config->{'openstreetmaps_description'}){
# Sample Query: http://nominatim.openstreetmap.org/reverse?format=csv&lat=40.43197&lon=-3.6993818&zoom=18&addressdetails=1&email=info@pandorafms.org
# Email address is sent by courtesy to OpenStreetmaps people.
# I read the API :-), thanks guys for your work.
# Change here URL to make request to a local openstreetmap server
my $content = get ('http://nominatim.openstreetmap.org/reverse?format=csv&lat='.$latitude.'&lon='.$longitude.'&zoom=18&addressdetails=1&email=info@pandorafms.org');
# Yep, I need to parse the XML output.
my $xs1 = XML::Simple->new();
my $doc = $xs1->XMLin($content);
$position_description = safe_input ($doc->{result}{content});
} else {
$position_description = ''; # Default value
}
@ -248,6 +262,7 @@ sub process_xml_data ($$$$$) {
logger($pa_config, "Getting GIS Data=timezone_offset=$timezone_offset longitude=$longitude latitude=$latitude altitude=$altitude position_description=$position_description", 8);
}
# Unknown agent!
if (! defined ($agent_name) || $agent_name eq '') {
logger($pa_config, "$file_name has data from an unnamed agent", 3);