From 40b8efc532192b39c85381fc351a0503b9d47d43 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 4 May 2016 18:48:54 +0200 Subject: [PATCH] Added the function 'agents_get_agent_custom_field' (cherry picked from commit e515a1d5872504709ed3ca3aa1b7774a36c2ea34) --- pandora_console/include/functions_agents.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4268c41a1a..140309ee3a 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2412,4 +2412,28 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false) return $ni_by_agents; } + +/** + * Returns the value of the custom field for the selected agent. + * + * @param integer Agent id. + * @param string Name of the custom field. + * + * @return mixed The custom field value or false on error. + */ +function agents_get_agent_custom_field ($agent_id, $custom_field_name) { + if (empty($agent_id) && empty($custom_field_name)) { + return false; + } + + $sql = sprintf("SELECT tacd.description AS value + FROM tagent_custom_data tacd + INNER JOIN tagent_custom_fields tacf + ON tacd.id_field = tacf.id_field + AND tacf.name LIKE '%s' + WHERE tacd.id_agent = %d + LIMIT 1", $custom_field_name, $agent_id); + return db_get_value_sql($sql); +} + ?>