From d14e250ad80a26b6bdb0294aec2ff2e072aee5a7 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 5 Aug 2015 10:36:35 +0200 Subject: [PATCH] Now the agents retrieved by group can be served with the key serialized when using the metaconsole --- pandora_console/include/ajax/agent.php | 10 +++--- pandora_console/include/functions_agents.php | 37 +++++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index b5cccc894d..22d789694d 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -38,20 +38,22 @@ if ($get_agents_group) { $id_group = (int) get_parameter('id_group', -1); $mode = (string) get_parameter('mode', 'json'); $id_server = (int) get_parameter('id_server', 0); + $serialized = (bool) get_parameter('serialized'); $return = array(); if ($id_group != -1) { $filter = array(); - if (defined('METACONSOLE')) { + if (is_metaconsole() && !empty($id_server)) { $filter['id_server'] = $id_server; } - $return = agents_get_group_agents($id_group, $filter, "none"); + $return = agents_get_group_agents($id_group, $filter, "none", false, false, $serialized); } switch ($mode) { case 'json': + default: echo json_encode($return); break; } @@ -59,7 +61,7 @@ if ($get_agents_group) { return; } -if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) { +if ($search_agents && (!is_metaconsole() || $force_local)) { $id_agent = (int) get_parameter('id_agent'); $string = (string) get_parameter('q'); /* q is what autocomplete plugin gives */ @@ -166,7 +168,7 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) { echo json_encode($data); return; } -elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE')) { +elseif ($search_agents && is_metaconsole()) { $id_agent = (int) get_parameter ('id_agent'); $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */ diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index e7e14668e2..76ede91942 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -757,11 +757,13 @@ function agents_common_modules ($id_agent, $filter = false, $indexed = true, $ge * @param string $case Which case to return the agentname as (lower, upper, none) * @param boolean $noACL jump the ACL test. * @param boolean $childGroups The flag to get agents in the child group of group parent passed. By default false. + * @param boolean $serialized Only in metaconsole. Return the key as . By default false. + * @param string $separator Only in metaconsole. Separator for the serialized data. By default |. * * @return array An array with all agents in the group or an empty array */ function agents_get_group_agents ($id_group = 0, $search = false, - $case = "lower", $noACL = false, $childGroups = false) { + $case = "lower", $noACL = false, $childGroups = false, $serialized = false, $separator = '|') { global $config; @@ -776,8 +778,6 @@ function agents_get_group_agents ($id_group = 0, $search = false, } } - - if ($childGroups) { if (is_array($id_group)) { foreach ($id_group as $parent) { @@ -860,7 +860,7 @@ function agents_get_group_agents ($id_group = 0, $search = false, unset($search['status']); } - if (defined('METACONSOLE') && isset($search['id_server'])) { + if (is_metaconsole() && isset($search['id_server'])) { $filter['id_tmetaconsole_setup'] = $search['id_server']; if ($filter['id_tmetaconsole_setup'] == 0) { @@ -882,41 +882,54 @@ function agents_get_group_agents ($id_group = 0, $search = false, $filter['order'] = 'nombre'; - if (defined('METACONSOLE')) { + if (is_metaconsole()) { $table_name = 'tmetaconsole_agent'; $fields = array( - 'id_tagente AS id_agente', 'nombre' + 'id_tagente AS id_agente', + 'nombre', + 'id_tmetaconsole_setup AS id_server' ); } else { $table_name = 'tagente'; $fields = array( - 'id_agente', 'nombre' + 'id_agente', + 'nombre' ); } $result = db_get_all_rows_filter($table_name, $filter, $fields); - - if ($result === false) return array (); //Return an empty array $agents = array (); foreach ($result as $row) { + if (!isset($row["id_agente"]) || !isset($row["nombre"])) + continue; + + if ($serialized && isset($row["id_server"])) { + $key = $row["id_server"] . $separator . $row["id_agente"]; + } + else { + $key = $row["id_agente"]; + } + switch ($case) { case "lower": - $agents[$row["id_agente"]] = mb_strtolower ($row["nombre"], "UTF-8"); + $value = mb_strtolower ($row["nombre"], "UTF-8"); break; case "upper": - $agents[$row["id_agente"]] = mb_strtoupper ($row["nombre"], "UTF-8"); + $value = mb_strtoupper ($row["nombre"], "UTF-8"); break; default: - $agents[$row["id_agente"]] = $row["nombre"]; + $value = $row["nombre"]; break; } + + $agents[$key] = $value; } return ($agents); }