From b923a055dc6996e69b6def4d3d2e0fa5d7d4a726 Mon Sep 17 00:00:00 2001 From: darode Date: Thu, 28 Feb 2013 15:38:23 +0000 Subject: [PATCH] 2013-02-28 Dario Rodriguez * 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 --- pandora_server/ChangeLog | 5 +++ pandora_server/lib/PandoraFMS/DataServer.pm | 44 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 1b6e534315..d2c81bb8b4 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-02-28 Dario Rodriguez + + * lib/PandoraFMS/DataServer.pm: Added feature to update custom field + on every XML process only with learning mode enabled. + 2013-02-28 Sancho Lerena * lib/PandoraFMS/PluginServer.pm: Removed several "Use of uninitialized i diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 5965f91047..1bd3813ab8 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -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