From 11ee7f6d0564ba5f1f63fb14af240d26382202bb Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 28 Jun 2011 15:41:13 +0000 Subject: [PATCH] 2011-06-28 Sergio Martin * lib/PandoraFMS/DB.pm lib/PandoraFMS/Core.pm lib/PandoraFMS/DataServer.pm: Improved the token ip implantation adding the ip to the secondary agent ips git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4496 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 ++++++ pandora_server/lib/PandoraFMS/Core.pm | 28 +++++++++++++++++++++ pandora_server/lib/PandoraFMS/DB.pm | 14 +++++++++++ pandora_server/lib/PandoraFMS/DataServer.pm | 5 +++- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 94ca6275af..36f91b6cd4 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2011-06-28 Sergio Martin + + * lib/PandoraFMS/DB.pm + lib/PandoraFMS/Core.pm + lib/PandoraFMS/DataServer.pm: Improved the token ip + implantation adding the ip to the secondary agent ips + 2011-06-28 Sergio Martin * lib/PandoraFMS/DB.pm diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 19a372002c..5db431fdab 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -127,6 +127,7 @@ our @ISA = ("Exporter"); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( + pandora_add_agent_address pandora_audit pandora_create_agent pandora_create_incident @@ -1383,6 +1384,33 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$) { return $agent_id; } +########################################################################## +# Add an address if not exists and add this address to taddress_agent if not exists +########################################################################## +sub pandora_add_agent_address ($$$$) { + my ($pa_config, $agent_id, $addr, $dbh) = @_; + + my $agent_name = get_agent_name($dbh, $agent_id); + + # Add the new address if it does not exist + my $addr_id = get_addr_id ($dbh, $addr); + + if($addr_id <= 0) { + logger($pa_config, 'Adding address ' . $addr . ' to the address list', 10); + $addr_id = add_address ($dbh, $addr); + } + + if ($addr_id <= 0) { + logger($pa_config, "Could not add address '$addr' for host '$agent_name'", 3); + } + + my $agent_address = is_agent_address($dbh, $agent_id, $addr_id); + if($agent_address == 0) { + logger($pa_config, 'Updating address for agent ' . $agent_name . ' (' . $addr . ') in his address list', 10); + add_new_address_agent ($dbh, $addr_id, $agent_id) + } +} + ########################################################################## ## Delete an agent given its id. ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index b34a429827..1d0e8c74cb 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -65,6 +65,7 @@ our @EXPORT = qw( get_server_id get_template_id get_template_module_id + is_agent_address is_group_disabled ); @@ -555,6 +556,19 @@ sub db_do ($$;@) { $dbh->do($query, undef, @values); } +########################################################################## +# Return the ID of the taddress agent with the given IP. +########################################################################## +sub is_agent_address ($$$) { + my ($dbh, $id_agent, $id_addr) = @_; + + my $id_ag = get_db_value ($dbh, 'SELECT id_ag FROM taddress_agent + WHERE id_a = ? + AND id_agent = ?', $id_addr, $id_agent); + + return (defined ($id_ag)) ? $id_ag : 0; +} + ########################################################################## ## Escape the given reserved word. ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index fa66f5e293..0566552ede 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -350,7 +350,10 @@ sub process_xml_data ($$$$$) { } else { # Update agent address if necessary if ($address ne '' && $address ne $agent->{'direccion'}) { + # Update the main address pandora_update_agent_address ($pa_config, $agent_id, $agent_name, $address, $dbh); + # Update the addres list if necessary + pandora_add_agent_address($pa_config, $agent_id, $address, $dbh); } } @@ -384,7 +387,7 @@ sub process_xml_data ($$$$$) { } } pandora_module_keep_alive ($pa_config, $agent_id, $agent_name, $server_id, $dbh); - + # Process modules foreach my $module_data (@{$data->{'module'}}) {