diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 604a215f5d..0fb09cc885 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,13 @@ +2010-02-24 Pablo de la Concepción + + * lib/PandoraFMS/Core.pm, lib/PandoraFMS/Dataserver.pm: Modified to + update the parent of an agent if in learning mode. + + * man/man3/PandoraFMS::Core.pm.3: Updated manpage with the new + parameter and improved documentation for pandora_update_agent + + * lib/PandoraFMS/Config.pm: Updated build + 2010-02-23 Raúl Mateos * lib/PandoraFMS/*.pm, DEBIAN/make_deb_package.sh, pandora_server_*: diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 80ded92464..7423d8a716 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -38,7 +38,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "3.1-dev"; -my $pandora_build = "100218"; +my $pandora_build = "100224"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 56835830ab..a80b7eaecf 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -862,17 +862,18 @@ sub pandora_update_server ($$$$$;$$) { } ########################################################################## -=head2 C<< pandora_update_agent (I<$pa_config>, I<$agent_timestamp>, I<$agent_id>, I<$os_version>, I<$agent_version>, I<$agent_interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>]) >> +=head2 C<< pandora_update_agent (I<$pa_config>, I<$agent_timestamp>, I<$agent_id>, I<$os_version>, I<$agent_version>, I<$agent_interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>]) [I<$parent_agent_name>]) >> -Update last contact, timezon fields in B and current position (this -can affect B and B). +Update last contact, timezone fields in B and current position (this +can affect B and B). If the I<$parent_agent_name> is +defined and there is an agent with that name, also the parent is updated. =cut ########################################################################## -sub pandora_update_agent ($$$$$$$;$$$$$) { +sub pandora_update_agent ($$$$$$$;$$$$$$) { my ($pa_config, $agent_timestamp, $agent_id, $os_version, $agent_version, $agent_interval, $dbh, $timezone_offset, - $longitude, $latitude, $altitude, $position_description) = @_; + $longitude, $latitude, $altitude, $position_description, $parent_agent_name) = @_; my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); @@ -883,6 +884,17 @@ sub pandora_update_agent ($$$$$$$;$$$$$) { if ($agent_interval != -1){ pandora_access_update ($pa_config, $agent_id, $dbh); } + + # Check if the parent is defined and exist. + my $parent_id = ''; + if (defined ($parent_agent_name)) { + $parent_id = get_agent_id ($dbh, $parent_agent_name); + if ($parent_id < 1) { + logger($pa_config, "Can't set parent: Parent with name '$parent_agent_name' not found",8); + $parent_id = ''; + } + } + # No update for interval, timezone and position fields (some old agents don't support it) if ($agent_interval == -1){ @@ -892,14 +904,29 @@ sub pandora_update_agent ($$$$$$$;$$$$$) { } if ( defined ($timezone_offset)) { - # 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 = ? WHERE id_agente = ?', $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $timezone_offset, $agent_id); + if ($parent_id != '') { + # Update the table tagente with all the new data and set the new parent + db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, + timezone_offset = ?, id_parent = ? WHERE id_agente = ?', $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, + $timezone_offset, $parent_id, $agent_id); + } + else { + # 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 = ? WHERE id_agente = ?', $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $timezone_offset, $agent_id); + } } else { - # 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 = ? WHERE id_agente = ?', - $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); + if ($parent_id != '') { + # Update the table tagente with all the new data and set the new parent + db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ?, id_parent = ? + WHERE id_agente = ?', $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $parent_id, $agent_id); + } + else { + # 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 = ? WHERE id_agente = ?', + $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); + } } my $update_gis_data= get_db_value ($dbh, 'SELECT update_gis_data FROM tagente WHERE id_agente = ?', $agent_id); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 891c678369..aa8928adb5 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -263,17 +263,41 @@ sub process_xml_data ($$$$$) { return; } } + else { # The agent was already created + my $mode = get_db_value($dbh, 'SELECT modo FROM tagente WHERE id_agente = ?', $agent_id); + logger($pa_config,"Parent_agent_name $parent_agent_name",10); + if ($mode == 0) { #The agent is not learning so ignore the parent. + $parent_agent_name = ''; + } + logger($pa_config,"Parent_agent_name $parent_agent_name",10); + } $AgentSem->up (); if ($valid_position_data == 1 && $pa_config->{'activate_gis'} != 0) { - logger($pa_config, "Updating agent $agent_name at long: $longitude lat: $latitude alt: $altitude", 5); - # Update agent information including position information - pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description); + logger($pa_config,"Parent_agent_name $parent_agent_name",10); + if (defined($parent_agent_name) && $parent_agent_name ne '') { + logger($pa_config,"Parent_agent_name $parent_agent_name",10); + logger($pa_config, "Updating agent $agent_name at long: $longitude lat: $latitude alt: $altitude parent: $parent_agent_name", 5); + # Update agent information including position information and the paret + pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, + $longitude, $latitude, $altitude, $position_description, $parent_agent_name); + } + else { + logger($pa_config, "Updating agent $agent_name at long: $longitude lat: $latitude alt: $altitude", 5); + # Update agent information including position information + } pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description); } else { - logger($pa_config, "Updating agent $agent_name", 5); - # Update agent information without position information - pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset); + if (defined($parent_agent_name) && $parent_agent_name ne '') { + logger($pa_config, "Updating agent $agent_name", 5); + # Update agent information including the parent without position information + pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset, undef, undef, undef, undef, $parent_agent_name); + } + else { + logger($pa_config, "Updating agent $agent_name", 5); + # Update agent information without position information ignoring the parent + pandora_update_agent($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh, $timezone_offset); + } } pandora_module_keep_alive ($pa_config, $agent_id, $agent_name, $server_id, $dbh); diff --git a/pandora_server/man/man3/PandoraFMS::Core.pm.3 b/pandora_server/man/man3/PandoraFMS::Core.pm.3 index afbfe84893..c238876027 100644 --- a/pandora_server/man/man3/PandoraFMS::Core.pm.3 +++ b/pandora_server/man/man3/PandoraFMS::Core.pm.3 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PandoraFMS::Core 3" -.TH PandoraFMS::Core 3 "2010-02-22" "perl v5.10.0" "User Contributed Perl Documentation" +.TH PandoraFMS::Core 3 "2010-02-24" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -266,11 +266,12 @@ Update server status: 4 plugin 5 prediction 6 wmi. -.ie n .SS """pandora_update_agent (\fI$pa_config\fP, \fI$agent_timestamp\fP, \fI$agent_id\fP, \fI$os_version\fP, \fI$agent_version\fP, \fI$agent_interval\fP, \fI$dbh\fP, [\fI$timezone_offset\fP], [\fI$longitude\fP], [\fI$latitude\fP], [\fI$altitude\fP], [\fI$position_description\fP])""" -.el .SS "\f(CWpandora_update_agent (\fP\f(CI$pa_config\fP\f(CW, \fP\f(CI$agent_timestamp\fP\f(CW, \fP\f(CI$agent_id\fP\f(CW, \fP\f(CI$os_version\fP\f(CW, \fP\f(CI$agent_version\fP\f(CW, \fP\f(CI$agent_interval\fP\f(CW, \fP\f(CI$dbh\fP\f(CW, [\fP\f(CI$timezone_offset\fP\f(CW], [\fP\f(CI$longitude\fP\f(CW], [\fP\f(CI$latitude\fP\f(CW], [\fP\f(CI$altitude\fP\f(CW], [\fP\f(CI$position_description\fP\f(CW])\fP" -.IX Subsection "pandora_update_agent ($pa_config, $agent_timestamp, $agent_id, $os_version, $agent_version, $agent_interval, $dbh, [$timezone_offset], [$longitude], [$latitude], [$altitude], [$position_description])" -Update last contact, timezon fields in \fBtagente\fR and current position (this -can affect \fBtgis_data_status\fR and \fBtgis_data_history\fR). +.ie n .SS """pandora_update_agent (\fI$pa_config\fP, \fI$agent_timestamp\fP, \fI$agent_id\fP, \fI$os_version\fP, \fI$agent_version\fP, \fI$agent_interval\fP, \fI$dbh\fP, [\fI$timezone_offset\fP], [\fI$longitude\fP], [\fI$latitude\fP], [\fI$altitude\fP], [\fI$position_description\fP]) [\fI$parent_agent_name\fP])""" +.el .SS "\f(CWpandora_update_agent (\fP\f(CI$pa_config\fP\f(CW, \fP\f(CI$agent_timestamp\fP\f(CW, \fP\f(CI$agent_id\fP\f(CW, \fP\f(CI$os_version\fP\f(CW, \fP\f(CI$agent_version\fP\f(CW, \fP\f(CI$agent_interval\fP\f(CW, \fP\f(CI$dbh\fP\f(CW, [\fP\f(CI$timezone_offset\fP\f(CW], [\fP\f(CI$longitude\fP\f(CW], [\fP\f(CI$latitude\fP\f(CW], [\fP\f(CI$altitude\fP\f(CW], [\fP\f(CI$position_description\fP\f(CW]) [\fP\f(CI$parent_agent_name\fP\f(CW])\fP" +.IX Subsection "pandora_update_agent ($pa_config, $agent_timestamp, $agent_id, $os_version, $agent_version, $agent_interval, $dbh, [$timezone_offset], [$longitude], [$latitude], [$altitude], [$position_description]) [$parent_agent_name])" +Update last contact, timezone fields in \fBtagente\fR and current position (this +can affect \fBtgis_data_status\fR and \fBtgis_data_history\fR). If the \fI\f(CI$parent_agent_name\fI\fR is +defined and there is an agent with that name, also the parent is updated. .ie n .SS """pandora_module_keep_alive (\fI$pa_config\fP, \fI$id_agent\fP, \fI$agent_name\fP, \fI$server_id\fP, \fI$dbh\fP)""" .el .SS "\f(CWpandora_module_keep_alive (\fP\f(CI$pa_config\fP\f(CW, \fP\f(CI$id_agent\fP\f(CW, \fP\f(CI$agent_name\fP\f(CW, \fP\f(CI$server_id\fP\f(CW, \fP\f(CI$dbh\fP\f(CW)\fP" .IX Subsection "pandora_module_keep_alive ($pa_config, $id_agent, $agent_name, $server_id, $dbh)"