2010-01-29 Pablo de la Concepción <pablo.concepcion@artica.es>
* conf/pandora_server.conf, lib/PandoraFMS/Config.pm: Added location_error parameter * lib/PandoraFMS/Core.pm: Fixed bugs in the creation and update of the agent that where messing with the locations. Fixed distance on the earth formula. Use of the location_error parameter to decide if an agent has moved or not. * util/pandora_xml_stress.pl, util/pandora_xml_stress.README: added parameter timezone_offset_range to let the timezone be random in the range given, and added the code to use it. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2332 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a8d699af88
commit
41088ccf74
|
@ -1,3 +1,17 @@
|
||||||
|
2010-01-29 Pablo de la Concepción <pablo.concepcion@artica.es>
|
||||||
|
|
||||||
|
* conf/pandora_server.conf, lib/PandoraFMS/Config.pm: Added
|
||||||
|
location_error parameter
|
||||||
|
|
||||||
|
* lib/PandoraFMS/Core.pm: Fixed bugs in the creation and update of
|
||||||
|
the agent that where messing with the locations. Fixed distance on the
|
||||||
|
earth formula. Use of the location_error parameter to decide if an
|
||||||
|
agent has moved or not.
|
||||||
|
|
||||||
|
* util/pandora_xml_stress.pl, util/pandora_xml_stress.README: added
|
||||||
|
parameter timezone_offset_range to let the timezone be random in the
|
||||||
|
range given, and added the code to use it.
|
||||||
|
|
||||||
2010-01-29 Pablo de la Concepción <pablo.concepcion@artica.es>
|
2010-01-29 Pablo de la Concepción <pablo.concepcion@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/DataServer.pm: Improved timezone_offset management.
|
* lib/PandoraFMS/DataServer.pm: Improved timezone_offset management.
|
||||||
|
|
|
@ -236,3 +236,7 @@ max_queue_files 250
|
||||||
|
|
||||||
# Flag to activate GIS (positional infomration for agents and maps) by default it is desactivated
|
# Flag to activate GIS (positional infomration for agents and maps) by default it is desactivated
|
||||||
# activate_gis 0
|
# activate_gis 0
|
||||||
|
|
||||||
|
|
||||||
|
# Radius of the Error in meters to consider two gis locations as the same location.
|
||||||
|
# location_error 50
|
||||||
|
|
|
@ -186,6 +186,7 @@ sub pandora_load_config {
|
||||||
$pa_config->{"export_threads"} = 1; # 3.0
|
$pa_config->{"export_threads"} = 1; # 3.0
|
||||||
$pa_config->{"web_threads"} = 1; # 3.0
|
$pa_config->{"web_threads"} = 1; # 3.0
|
||||||
$pa_config->{"activate_gis"} = 0; # 3.1
|
$pa_config->{"activate_gis"} = 0; # 3.1
|
||||||
|
$pa_config->{"location_error"} = 50; # 3.1
|
||||||
|
|
||||||
$pa_config->{"max_queue_files"} = 250;
|
$pa_config->{"max_queue_files"} = 250;
|
||||||
|
|
||||||
|
@ -514,6 +515,9 @@ sub pandora_load_config {
|
||||||
elsif ($parametro =~ m/^activate_gis\s+([0-1])/i) {
|
elsif ($parametro =~ m/^activate_gis\s+([0-1])/i) {
|
||||||
$pa_config->{'activate_gis'} = clean_blank($1);
|
$pa_config->{'activate_gis'} = clean_blank($1);
|
||||||
}
|
}
|
||||||
|
elsif ($parametro =~ m/^location_error\s+(\d+)/i) {
|
||||||
|
$pa_config->{'location_error'} = clean_blank($1);
|
||||||
|
}
|
||||||
} # end of loop for parameter #
|
} # end of loop for parameter #
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -757,28 +757,33 @@ sub pandora_update_agent ($$$$$$$;$$$$) {
|
||||||
|
|
||||||
logger($pa_config, "Old Agent data: last-longitude = ". $last_agent_info->{'last_longitude'}. " ID: $agent_id ", 10);
|
logger($pa_config, "Old Agent data: last-longitude = ". $last_agent_info->{'last_longitude'}. " ID: $agent_id ", 10);
|
||||||
|
|
||||||
# If the agent has moved outside the range stablised as
|
# If the agent has moved outside the range stablised as location error
|
||||||
if (distance_moved($pa_config, $last_agent_info->{'last_longitude'}, $last_agent_info->{'last_latitude'}, $last_agent_info->{'last_altitude'}, $longitude, $latitude, $altitude) > 10 ){
|
if (distance_moved($pa_config, $last_agent_info->{'last_longitude'}, $last_agent_info->{'last_latitude'}, $last_agent_info->{'last_altitude'}, $longitude, $latitude, $altitude) > $pa_config->{'location_error'}){
|
||||||
# Save the agent data in the agent table
|
# Save the agent data in the agent table
|
||||||
save_agent_position($pa_config, $timestamp, $last_agent_info->{'last_longitude'},$last_agent_info->{'last_latitude'}, $last_agent_info->{'last_altitude'}, $agent_id, $dbh);
|
save_agent_position($pa_config, $timestamp, $last_agent_info->{'last_longitude'},$last_agent_info->{'last_latitude'}, $last_agent_info->{'last_altitude'}, $agent_id, $dbh);
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Update the end timestamp for the agent
|
|
||||||
update_agent_position($pa_config, $timestamp, $agent_id, $dbh);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Update the table tagente with all the new data
|
# Update the table tagente with all the new data
|
||||||
db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, timezone_offset = ?,
|
db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, timezone_offset = ?,
|
||||||
last_longitude = ?, last_latitude =?, last_altitude = ? WHERE id_agente = ?',
|
last_longitude = ?, last_latitude =?, last_altitude = ? WHERE id_agente = ?',
|
||||||
$agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $timezone_offset, $longitude, $latitude, $altitude, $agent_id);
|
$agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $timezone_offset, $longitude, $latitude, $altitude, $agent_id);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
# Update the end timestamp for the agent
|
||||||
|
update_agent_position($pa_config, $timestamp, $agent_id, $dbh);
|
||||||
|
# Update the table tagente with all the new data but the location
|
||||||
|
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, $timezone_offset, $agent_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Measures the distance taking in acount the earth curvature
|
# Measures the distance taking in acount the earth curvature
|
||||||
# The distance is based on Havesine formula
|
# The distance is based on Havesine formula
|
||||||
# Refferences:
|
# Refferences (Theory):
|
||||||
# * http://franchu.net/2007/11/16/gis-calculo-de-distancias-sobre-la-tierra/
|
# * http://franchu.net/2007/11/16/gis-calculo-de-distancias-sobre-la-tierra/
|
||||||
# * http://en.wikipedia.org/wiki/Haversine_formula
|
# * http://en.wikipedia.org/wiki/Haversine_formula
|
||||||
|
# References (C implementation):
|
||||||
|
# * http://blog.julien.cayzac.name/2008/10/arc-and-distance-between-two-points-on.html
|
||||||
##########################################################################
|
##########################################################################
|
||||||
sub distance_moved ($$$$$$$) {
|
sub distance_moved ($$$$$$$) {
|
||||||
my ($pa_config, $last_longitude, $last_latitude, $last_altitude, $longitude, $latitude, $altitude) = @_;
|
my ($pa_config, $last_longitude, $last_latitude, $last_altitude, $longitude, $latitude, $altitude) = @_;
|
||||||
|
@ -788,7 +793,7 @@ sub distance_moved ($$$$$$$) {
|
||||||
|
|
||||||
my $long_difference = $last_longitude - $longitude;
|
my $long_difference = $last_longitude - $longitude;
|
||||||
my $lat_difference = $last_latitude - $latitude;
|
my $lat_difference = $last_latitude - $latitude;
|
||||||
my $alt_difference = $last_altitude - $altitude;
|
#my $alt_difference = $last_altitude - $altitude;
|
||||||
|
|
||||||
my $to_radians= $pi/180;
|
my $to_radians= $pi/180;
|
||||||
my $to_half_radians= $pi/360;
|
my $to_half_radians= $pi/360;
|
||||||
|
@ -798,10 +803,11 @@ sub distance_moved ($$$$$$$) {
|
||||||
$long_aux *= $long_aux;
|
$long_aux *= $long_aux;
|
||||||
$lat_aux *= $lat_aux;
|
$lat_aux *= $lat_aux;
|
||||||
# Temporary value to make sorter the asin formula.
|
# Temporary value to make sorter the asin formula.
|
||||||
my $asinaux = ($lat_aux + cos($last_latitude*$to_radians) * cos($latitude*$to_radians) * $long_aux );
|
my $asinaux = sqrt($lat_aux + cos($last_latitude*$to_radians) * cos($latitude*$to_radians) * $long_aux );
|
||||||
# Assure the aux value is not greater than 1
|
# Assure the aux value is not greater than 1
|
||||||
if ($asinaux > 1) { $asinaux = 1; }
|
if ($asinaux > 1) { $asinaux = 1; }
|
||||||
my $dist_in_rad = 2 * atan2($asinaux, sqrt (1 - $asinaux * $asinaux));
|
# We use: asin(x) = atan2(x, sqrt(1-x*x))
|
||||||
|
my $dist_in_rad = 2.0 * atan2($asinaux, sqrt (1 - $asinaux * $asinaux));
|
||||||
my $dist_in_meters = $earth_radius_in_meters * $dist_in_rad;
|
my $dist_in_meters = $earth_radius_in_meters * $dist_in_rad;
|
||||||
|
|
||||||
logger($pa_config, "Distance moved:" . $dist_in_meters ." meters", 10);
|
logger($pa_config, "Distance moved:" . $dist_in_meters ." meters", 10);
|
||||||
|
@ -909,6 +915,7 @@ sub pandora_create_agent ($$$$$$$$$$$;$$$$) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger ($pa_config, "Server '$server_name' CREATED agent '$agent_name' address '$address'.", 10);
|
logger ($pa_config, "Server '$server_name' CREATED agent '$agent_name' address '$address'.", 10);
|
||||||
|
# FIXME: use $group_id instead of $pa_config->{'autocreate_group'} ????
|
||||||
pandora_event ($pa_config, "Agent [$agent_name] created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh);
|
pandora_event ($pa_config, "Agent [$agent_name] created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh);
|
||||||
return $agent_id;
|
return $agent_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,11 @@ startup_delay 2
|
||||||
# Timezone offset: Difference with the server timezone
|
# Timezone offset: Difference with the server timezone
|
||||||
timezone_offset 0
|
timezone_offset 0
|
||||||
|
|
||||||
|
# Timezone offset range (to set a randomnuber of hours of difference with the
|
||||||
|
# server so timezone_offset can go from timezone_offset-timezone_offset_range
|
||||||
|
# to timezone_offset+timezone_offset_range
|
||||||
|
timezone_offset_range 0
|
||||||
|
|
||||||
# Agent position paramters
|
# Agent position paramters
|
||||||
# Those parameters define the center and the zone where the agents will be
|
# Those parameters define the center and the zone where the agents will be
|
||||||
# randomly located.
|
# randomly located.
|
||||||
|
|
|
@ -91,6 +91,7 @@ sub generate_xml_files ($$$$$) {
|
||||||
my $temporal = get_conf_token ($conf, 'temporal', '/tmp');
|
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 $ag_timezone_offset = get_conf_token ($conf, 'timezone_offset', '0');
|
||||||
|
my $ag_timezone_offset_range = get_conf_token ($conf, 'timezone_offset_range', '0');
|
||||||
my $latitude_base = get_conf_token ($conf, 'latitude_base', '40.42056');
|
my $latitude_base = get_conf_token ($conf, 'latitude_base', '40.42056');
|
||||||
my $longitude_base = get_conf_token ($conf, 'longitude_base', '-3.708187');
|
my $longitude_base = get_conf_token ($conf, 'longitude_base', '-3.708187');
|
||||||
my $altitude_base = get_conf_token ($conf, 'altitude_base', '0');
|
my $altitude_base = get_conf_token ($conf, 'altitude_base', '0');
|
||||||
|
@ -123,6 +124,8 @@ sub generate_xml_files ($$$$$) {
|
||||||
# XML header
|
# XML header
|
||||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
|
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
|
||||||
my $xml_data = "<?xml version='$xml_version' encoding='$encoding'?>\n";
|
my $xml_data = "<?xml version='$xml_version' encoding='$encoding'?>\n";
|
||||||
|
my $sign = int rand(2);
|
||||||
|
$ag_timezone_offset += ($sign*(-1)+(1-$sign)) * int rand($ag_timezone_offset_range);
|
||||||
$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";
|
$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}) {
|
foreach my $module (@{$modules}) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue