From e12de5ca51447277b7c277ab393edabb03f1cbc3 Mon Sep 17 00:00:00 2001 From: slerena Date: Wed, 9 Mar 2011 13:49:30 +0000 Subject: [PATCH] 2011-03-09 Sancho Lerena * 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 --- pandora_server/ChangeLog | 7 +++++++ pandora_server/conf/pandora_server.conf | 11 +++++++++-- pandora_server/lib/PandoraFMS/Config.pm | 14 +++++++++----- pandora_server/lib/PandoraFMS/DataServer.pm | 19 +++++++++++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 4e3f443e6e..d1d8eefbbb 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2011-03-09 Sancho Lerena + + * 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 * lib/PandoraFMS/DataServer.pm: Fixed a typo. Thanks to Kikuchi Koichiro. diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index 02bff4c6f6..d460fb85f0 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -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 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index fae3a3626d..01104f5c8f 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -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); } diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 05114a9c6a..a5ba2fe8c2 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -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);