2011-06-28 Sergio Martin <sergio.martin@artica.es>

* 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
This commit is contained in:
zarzuelo 2011-06-28 15:41:13 +00:00
parent f2b2c5d588
commit 11ee7f6d05
4 changed files with 53 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2011-06-28 Sergio Martin <sergio.martin@artica.es>
* 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 <sergio.martin@artica.es>
* lib/PandoraFMS/DB.pm

View File

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

View File

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

View File

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