2013-02-28 Dario Rodriguez <dario@artica.es>

* lib/PandoraFMS/DataServer.pm: Added feature to update custom
        * field
        on every XML process only with learning mode enabled.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7753 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2013-02-28 15:38:23 +00:00
parent 1df7b829e7
commit b923a055dc
2 changed files with 48 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2013-02-28 Dario Rodriguez <dario@artica.es>
* lib/PandoraFMS/DataServer.pm: Added feature to update custom field
on every XML process only with learning mode enabled.
2013-02-28 Sancho Lerena <slerena@artica.es>
* lib/PandoraFMS/PluginServer.pm: Removed several "Use of uninitialized i

View File

@ -111,7 +111,7 @@ sub data_producer ($) {
push (@files, $file);
$file_count++;
print "QUEUING $file\n";
# Do not queue more than max_queue_files files
if ($file_count >= $pa_config->{"max_queue_files"}) {
last;
@ -436,6 +436,48 @@ sub process_xml_data ($$$$$) {
else {
$parent_id = $agent->{'id_parent'};
}
# Process custom fields for update
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 $custom_field_data = get_db_single_row($dbh, 'SELECT * FROM tagent_custom_data WHERE id_field = ? AND id_agent = ?',
$custom_field_info->{"id_field"}, $agent->{"id_agente"});
my $cf_value = get_tag_value ($custom_field, 'value', '');
#If not defined we must create if defined just updated
if(!defined($custom_field_data)) {
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 {
db_update ($dbh, "UPDATE tagent_custom_data SET description = ? WHERE id_field = ? AND id_agent = ?",
$cf_value ,$custom_field_info->{"id_field"}, $agent->{'id_agente'});
}
}
else {
logger($pa_config, "The custom field '" . $cf_name . "' does not exist. Discarded from XML", 5);
}
}
}
}
}
# Update GIS data only if is allowed and is valid position