From 2b660b4862e1a096c9f3759df154f5caad7455fa Mon Sep 17 00:00:00 2001 From: pabloconcepcion Date: Tue, 12 Jan 2010 17:22:14 +0000 Subject: [PATCH] =?UTF-8?q?2010-01-12=20=20Pablo=20de=20la=20Concepcip?= =?UTF-8?q?=C3=B3n=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/PandoraFMS/DataServer.pm: Updated to process GIS information from the .data (altitude, latitude, longitude and timezone_offset). * lib/PandoraFMS/Core.pm: Added pandora_update_position function, to store GIS information on the databse. * lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Updated to send timezone_offset to pandora_update_agent function. * util/pandora_xml_stress.pl, util/pandora_xml_stress.README: Updated to generate agents with GIS information (altitude, latitude, longitude and timezone_offset). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2262 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 16 ++++++++++ pandora_server/lib/PandoraFMS/Core.pm | 30 +++++++++++++++---- pandora_server/lib/PandoraFMS/DataServer.pm | 28 ++++++++++++++++- .../lib/PandoraFMS/NetworkServer.pm | 2 +- pandora_server/lib/PandoraFMS/PluginServer.pm | 2 +- .../lib/PandoraFMS/PredictionServer.pm | 2 +- pandora_server/lib/PandoraFMS/WMIServer.pm | 2 +- pandora_server/util/pandora_xml_stress.README | 19 ++++++++++++ pandora_server/util/pandora_xml_stress.pl | 15 ++++++++-- 9 files changed, 102 insertions(+), 14 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 691ff432eb..3bc86328c3 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,19 @@ +2010-01-12 Pablo de la ConcepcipĆ³n + + * lib/PandoraFMS/DataServer.pm: Updated to process GIS information from + the .data (altitude, latitude, longitude and timezone_offset). + + * lib/PandoraFMS/Core.pm: Added pandora_update_position function, to + store GIS information on the databse. + + * lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm, + lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Updated + to send timezone_offset to pandora_update_agent function. + + * util/pandora_xml_stress.pl, util/pandora_xml_stress.README: Updated + to generate agents with GIS information (altitude, latitude, longitude + and timezone_offset). + 2009-12-29 Sancho Lerena * lib/PandoraFMS/Core.pm: Fixed problem generating events with diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 992693bff3..b2071d439c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -61,6 +61,7 @@ our @EXPORT = qw( pandora_update_agent pandora_update_module_on_error pandora_update_server + pandora_update_position @ServerTypes ); @@ -710,23 +711,23 @@ sub pandora_update_server ($$$$$;$$) { ########################################################################## # Update last contact field in agent table ########################################################################## -sub pandora_update_agent ($$$$$$$) { +sub pandora_update_agent ($$$$$$$$) { my ($pa_config, $agent_timestamp, $agent_id, $os_version, - $agent_version, $agent_interval, $dbh) = @_; + $agent_version, $agent_interval, $timezone_offset, $dbh) = @_; my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); pandora_access_update ($pa_config, $agent_id, $dbh); - # No update for interval field (some old agents don't support it) + # No update for interval nor timezone field (some old agents don't support it if ($agent_interval == -1){ - db_do($dbh, 'UPDATE tagente SET agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ? WHERE id_agente = ?', + db_do($dbh, 'UPDATE tagente SET agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, WHERE id_agente = ?', $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); return; } - db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ? WHERE id_agente = ?', - $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); + db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, timezone_offset = ? WHERE id_agente = ?', + $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id, $timezone_offset); } ########################################################################## @@ -1273,6 +1274,23 @@ sub pandora_inhibit_alerts ($$$) { return 0; } + +########################################################################## +# Sets the new position of an agent in the tgis_data table +########################################################################## +sub pandora_update_position($$$$$$) { + my ($pa_config, $agent_id, $latitude, $longitude, $altitude, $dbh) = @_; + + my $utimestamp = time (); + my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); + + logger($pa_config, "Updating agent position: timestamp=$timestamp latitude=$latitude longitude=$longitude altitude=$altitude", 10); + + db_insert($dbh, 'INSERT INTO tgis_data (`longitude`, `latitude`, `altitude`, `tagente_id_agente`, `start_timestamp`, `end_timestamp`) VALUES (?, ?, ?, ?, ?, ?)', + "".$longitude, "".$latitude, $altitude, $agent_id, $timestamp, $timestamp); + +} + # End of function declaration # End of defined Code diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index d6df74a9a2..98185779e4 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -157,6 +157,30 @@ sub process_xml_data ($$$$$) { ($data->{'agent_name'}, $data->{'version'}, $data->{'timestamp'}, $data->{'interval'}, $data->{'os_version'}); + # Get GIS information + my ($timezone_offset, $latitude, $longitude, $altitude) = ($data->{'timezone_offset'}, + $data->{'latitude'}, $data->{'longitude'}, $data->{'altitude'}); + + # Validate the GIS informtation + # Timezone offset must be an integer beween -12 and +12 + if ($timezone_offset !~ /[-+]?[0-9,11,12]/) { + $timezone_offset = 0; # Default value + } + # Longitude must be a real number + if ($longitude !~ /[-+]?[0-9]*\.?[0-9]+/) { + $longitude = 0.0; # Default value + } + # Latitude must be a real number + if ($latitude !~ /[-+]?[0-9]*\.?[0-9]+/) { + $latitude = 0.0; # Default value + } + # Altitude must be a real number + if ($altitude !~ /[-+]?[0-9]*\.?[0-9]+/) { + $altitude = 0.0; # Default value + } + + logger($pa_config, "Getting GIS Data=timezone_offset=$timezone_offset latitude=$latitude longitude=$longitude altitude=$altitude", 10); + # Unknown agent! if (! defined ($agent_name) || $agent_name eq '') { logger($pa_config, "$file_name has data from an unnamed agent", 3); @@ -199,7 +223,9 @@ sub process_xml_data ($$$$$) { } $AgentSem->up (); - pandora_update_agent ($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh); + pandora_update_agent ($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $timezone_offset, $dbh); + # TODO: Check if it's needed to update the position + pandora_update_position($pa_config, $agent_id, $latitude, $longitude, $altitude, $dbh); pandora_module_keep_alive ($pa_config, $agent_id, $agent_name, $server_id, $dbh); # Process modules diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index 5e2e36e567..1bd8bc94d3 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -379,7 +379,7 @@ sub exec_network_module ($$$$) { pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $server_id, $dbh); # Update agent last contact using Pandora version as agent version - pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, $dbh); + pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, 0, $dbh); } else { # Modules who cannot connect or something go bad, update last_execution_try field diff --git a/pandora_server/lib/PandoraFMS/PluginServer.pm b/pandora_server/lib/PandoraFMS/PluginServer.pm index b1e818927c..e32409c39e 100644 --- a/pandora_server/lib/PandoraFMS/PluginServer.pm +++ b/pandora_server/lib/PandoraFMS/PluginServer.pm @@ -207,7 +207,7 @@ sub data_consumer ($$) { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh); - pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, $dbh); + pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, 0, $dbh); } 1; diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index 373bbb06ce..8e8d156128 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -236,7 +236,7 @@ sub exec_prediction_module ($$$$) { } pandora_process_module ($pa_config, $module_data, undef, $agent_module, undef, $timestamp, $utimestamp, $server_id, $dbh); - pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, $dbh); + pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, 0,$dbh); } 1; diff --git a/pandora_server/lib/PandoraFMS/WMIServer.pm b/pandora_server/lib/PandoraFMS/WMIServer.pm index b5234d9aab..c4e3ba8c96 100644 --- a/pandora_server/lib/PandoraFMS/WMIServer.pm +++ b/pandora_server/lib/PandoraFMS/WMIServer.pm @@ -193,7 +193,7 @@ sub data_consumer ($$) { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); pandora_process_module ($pa_config, $module_data, undef, $module, undef, $timestamp, $utimestamp, $self->getServerID (), $dbh); - pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, $dbh); + pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, 0,$dbh); } 1; diff --git a/pandora_server/util/pandora_xml_stress.README b/pandora_server/util/pandora_xml_stress.README index 1bc872644c..8a0f8f8d9c 100644 --- a/pandora_server/util/pandora_xml_stress.README +++ b/pandora_server/util/pandora_xml_stress.README @@ -55,6 +55,25 @@ time_to 2009-06-05 00:00:00 # race conditions when auto-creating the agent, by default 2. startup_delay 2 +# Timezone offset: Difference with the server timezone +timezone_offset 0 + +# Agent position paramters +# Those parameters define the center and the zone where the agents will be +# randomly located. +# The base parameters define the central point of the sistem and the radius +# defines how far from that point the agents will be placed in any direction + +# Base latitude reference for all agents +latitude_base 40.42056 +# Base longitude reference for all agents +longitude_base -3.708187 +# Base altitude reference for all agents +altitude_base 0 +# This amount divided by 100 defines how far from each reference coordinate +# the agents will go +position_radius 10 + # Address of the Tentacle server where XML files will be sent (optional). # server_ip 192.168.50.1 diff --git a/pandora_server/util/pandora_xml_stress.pl b/pandora_server/util/pandora_xml_stress.pl index 7a409199ba..8ec6ed1d3b 100755 --- a/pandora_server/util/pandora_xml_stress.pl +++ b/pandora_server/util/pandora_xml_stress.pl @@ -89,7 +89,12 @@ sub generate_xml_files ($$$$$) { my $os_name = get_conf_token ($conf, 'os_name', 'Linux'); my $os_version = get_conf_token ($conf, 'os_version', '2.6'); my $temporal = get_conf_token ($conf, 'temporal', '/tmp'); - my $startup_delay = get_conf_token ($conf, 'startup_delay', '5'); + my $startup_delay = get_conf_token ($conf, 'startup_delay', '5') + my $ag_timezone_offset = get_conf_token ($conf, 'timezone_offset', '0') + my $latitude_base = get_conf_token ($conf, 'latitude_base', '40.42056'); + my $longitude_base = get_conf_token ($conf, 'longitude_base', '-3.708187'); + my $altitude_base = get_conf_token ($conf, 'altitude_base', '0'); + my $position_radius = get_conf_token ($conf, 'position_radius', '10'); # Get time_from my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ()); @@ -110,11 +115,15 @@ sub generate_xml_files ($$$$$) { # Get the name of the agent last unless defined ($agents->[$i]); my $agent_name = $agents->[$i]; - + # Agent random position + my $ag_latitude = $latitude_base + (rand ($position_radius) - $position_radius/2)/100; + my $ag_longitude = $longitude_base + (rand ($position_radius) - $position_radius/2)/100; + my $ag_altitude = $altitude_base + (rand ($position_radius) - $position_radius/2)/100; + # XML header my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); my $xml_data = "\n"; - $xml_data .= "\n"; + $xml_data .= "\n"; foreach my $module (@{$modules}) { # Skip unnamed modules