2012-11-15 Sergio Martin <sergio.martin@artica.es>

* lib/PandoraFMS/Core.pm
	lib/PandoraFMS/DataServer.pm: Added support for new agent data in
	the XML as custom_id, url_address and custom fields



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7150 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-11-15 15:20:48 +00:00
parent 42ad30cf11
commit ed19ee8843
3 changed files with 64 additions and 15 deletions

View File

@ -1,3 +1,9 @@
2012-11-15 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/Core.pm
lib/PandoraFMS/DataServer.pm: Added support for new agent data in
the XML as custom_id, url_address and custom fields
2012-11-15 Ramon Novoa <rnovoa@artica.es>
* util/pandora_db.pl: Try to update module status count for all agents.

View File

@ -1869,7 +1869,7 @@ 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>]) [I<$parent_agent_name>]) >>
=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, timezone fields in B<tagente> and current position (this
can affect B<tgis_data_status> and B<tgis_data_history>). If the I<$parent_agent_id> is
@ -2235,17 +2235,26 @@ sub pandora_create_group ($$$$$$$$$) {
}
##########################################################################
=head2 C<< pandora_create_agent (I<$pa_config>, I<$server_name>, I<$agent_name>, I<$address>, I<$group_id>, I<$parent_id>, I<$os_id>, I<$description>, I<$interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>]) >>
=head2 C<< pandora_create_agent (I<$pa_config>, I<$server_name>, I<$agent_name>, I<$address>, I<$group_id>, I<$parent_id>, I<$os_id>, I<$description>, I<$interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>], [I<$custom_id>], [I<$url_address>]) >>
Create a new entry in B<tagente> optionaly with position information
=cut
##########################################################################
sub pandora_create_agent ($$$$$$$$$$;$$$$$) {
sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) {
my ($pa_config, $server_name, $agent_name, $address,
$group_id, $parent_id, $os_id,
$description, $interval, $dbh, $timezone_offset,
$longitude, $latitude, $altitude, $position_description) = @_;
$longitude, $latitude, $altitude, $position_description,
$custom_id, $url_address) = @_;
if (!defined($custom_id)) {
$custom_id = '';
}
if (!defined($url_address)) {
$url_address = '';
}
if (!defined($group_id)) {
@ -2257,13 +2266,13 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$) {
my $agent_id;
# Test if the optional positional parameters are defined or GIS is disabled
if (!defined ($timezone_offset) ) {
$agent_id = db_insert ($dbh, 'id_agente', 'INSERT INTO tagente (nombre, direccion, comentarios, id_grupo, id_os, server_name, intervalo, id_parent, modo)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', safe_input($agent_name), $address, $description, $group_id, $os_id, $server_name, $interval, $parent_id);
$agent_id = db_insert ($dbh, 'id_agente', 'INSERT INTO tagente (nombre, direccion, comentarios, id_grupo, id_os, server_name, intervalo, id_parent, modo, custom_id, url_address)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)', safe_input($agent_name), $address, $description, $group_id, $os_id, $server_name, $interval, $parent_id, $custom_id, $url_address);
}
else {
$agent_id = db_insert ($dbh, 'id_agente', 'INSERT INTO tagente (nombre, direccion, comentarios, id_grupo, id_os, server_name, intervalo, id_parent,
timezone_offset, modo ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1)', safe_input($agent_name), $address,
$description, $group_id, $os_id, $server_name, $interval, $parent_id, $timezone_offset);
timezone_offset, modo, custom_id, url_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)', safe_input($agent_name), $address,
$description, $group_id, $os_id, $server_name, $interval, $parent_id, $timezone_offset, $custom_id, $url_address);
}
if (defined ($longitude) && defined ($latitude ) && $pa_config->{'activate_gis'} == 1 ) {
if (!defined($altitude)) {

View File

@ -179,9 +179,10 @@ sub data_consumer ($$) {
sub process_xml_data ($$$$$) {
my ($pa_config, $file_name, $data, $server_id, $dbh) = @_;
my ($agent_name, $agent_version, $timestamp, $interval, $os_version, $timezone_offset) =
my ($agent_name, $agent_version, $timestamp, $interval, $os_version, $timezone_offset, $custom_id, $url_address) =
($data->{'agent_name'}, $data->{'version'}, $data->{'timestamp'},
$data->{'interval'}, $data->{'os_version'}, $data->{'timezone_offset'});
$data->{'interval'}, $data->{'os_version'}, $data->{'timezone_offset'},
$data->{'custom_id'}, $data->{'url_address'});
# Timezone offset must be an integer beween -12 and +12
if (!defined($timezone_offset) || $timezone_offset !~ /[-+]?[0-9,11,12]/) {
@ -330,18 +331,51 @@ sub process_xml_data ($$$$$) {
# Create the agent
if ($valid_position_data == 1 && $pa_config->{'activate_gis'} != 0 ) {
logger($pa_config, "Creating agent $agent_name at long: $longitude lat: $latitude alt: $altitude", 5);
$agent_id = pandora_create_agent($pa_config, $pa_config->{'servername'}, $agent_name, $address, $group_id, $parent_id, $os,
$description, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description);
}
else { # Ignore agent positional data
logger($pa_config, "Creating agent $agent_name", 5);
$agent_id = pandora_create_agent($pa_config, $pa_config->{'servername'}, $agent_name, $address, $group_id, $parent_id, $os,
$description, $interval, $dbh, $timezone_offset);
$longitude = undef;
$latitude = undef;
$altitude = undef;
$position_description = undef;
}
$agent_id = pandora_create_agent($pa_config, $pa_config->{'servername'}, $agent_name, $address, $group_id, $parent_id, $os,
$description, $interval, $dbh, $timezone_offset, $longitude, $latitude, $altitude, $position_description, $custom_id, $url_address);
if (! defined ($agent_id)) {
$AgentSem->up ();
return;
}
# Process custom fields
if(defined($data->{'custom_fields'})) {
foreach my $custom_fields (@{$data->{'custom_fields'}}) {
foreach my $custom_field (@{$custom_fields->{'field'}}) {
my $cf_name = get_tag_value ($custom_field, 'name', '');
logger($pa_config, "Processing custom field '" . $cf_name . "'", 10);
# Check if the custom field exists
my $custom_field_info = get_db_single_row ($dbh, 'SELECT * FROM tagent_custom_fields WHERE name = ?', safe_input($cf_name));
# If it exists add the value to the agent
if (defined ($custom_field_info)) {
my $cf_value = get_tag_value ($custom_field, 'value', '');
my $field_agent;
$field_agent->{'id_agent'} = $agent_id;
$field_agent->{'id_field'} = $custom_field_info->{'id_field'};
$field_agent->{'description'} = $cf_value;
db_process_insert($dbh, 'id_field', 'tagent_custom_data', $field_agent);
}
else {
logger($pa_config, "The custom field '" . $cf_name . "' does not exist. Discarded from XML", 5);
}
}
}
}
}
$AgentSem->up ();