2010-01-12 Pablo de la Concepcipón <pablo.concepcion@artica.es>

* 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
This commit is contained in:
pabloconcepcion 2010-01-12 17:22:14 +00:00
parent f6b2717be1
commit 2b660b4862
9 changed files with 102 additions and 14 deletions

View File

@ -1,3 +1,19 @@
2010-01-12 Pablo de la Concepcipón <pablo.concepcion@artica.es>
* 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 <slerena@artica.es>
* lib/PandoraFMS/Core.pm: Fixed problem generating events with

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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 = "<?xml version='$xml_version' encoding='$encoding'?>\n";
$xml_data .= "<agent_data os_name='$os_name' os_version='$os_version' interval='$interval' version='$os_version' timestamp='$timestamp' agent_name='$agent_name'>\n";
$xml_data .= "<agent_data os_name='$os_name' os_version='$os_version' interval='$interval' version='$os_version' timestamp='$timestamp' agent_name='$agent_name' timezone_offset='$ag_timezone_offset' longitude='$ag_longitude' latitude='$ag_latitude' altitude='$ag_altitude' />\n";
foreach my $module (@{$modules}) {
# Skip unnamed modules