Fix issues with select agents modules control
This commit is contained in:
parent
4f52e1192c
commit
9519e00992
|
@ -113,6 +113,7 @@ define('SECONDS_3YEARS', 94608000);
|
|||
// Separator constats.
|
||||
define('SEPARATOR_COLUMN', ';');
|
||||
define('SEPARATOR_ROW', chr(10));
|
||||
define('SEPARATOR_META_MODULE', '|-|-|-|');
|
||||
// Chr(10) is \n.
|
||||
define('SEPARATOR_COLUMN_CSV', '#');
|
||||
define('SEPARATOR_ROW_CSV', "@\n");
|
||||
|
|
|
@ -1555,33 +1555,24 @@ function html_print_select_multiple_modules_filtered(array $data):string
|
|||
);
|
||||
|
||||
if ($data['mAgents'] !== null) {
|
||||
$all_modules = select_modules_for_agent_group(
|
||||
$all_modules = get_modules_agents(
|
||||
$data['mModuleGroup'],
|
||||
explode(',', $data['mAgents']),
|
||||
$data['mShowCommonModules'],
|
||||
false
|
||||
false,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
$all_modules = [];
|
||||
}
|
||||
|
||||
if (isset($data['mShowSelectedOtherGroups']) === true) {
|
||||
$selected_modules_ids = explode(',', $data['mModules']);
|
||||
foreach ($selected_modules_ids as $id) {
|
||||
if (array_key_exists($id, $all_modules) === false) {
|
||||
$module_data = modules_get_agentmodule($id);
|
||||
$all_modules[$id] = $module_data['nombre'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= html_print_input(
|
||||
[
|
||||
'label' => __('Modules'),
|
||||
'type' => 'select',
|
||||
'fields' => $all_modules,
|
||||
'name' => 'filtered-module-modules-'.$uniqId,
|
||||
'selected' => explode(',', $data['mModules']),
|
||||
'selected' => explode((is_metaconsole() === true) ? SEPARATOR_META_MODULE : ',', $data['mModules']),
|
||||
'return' => true,
|
||||
'multiple' => true,
|
||||
'style' => 'min-width: 200px;max-width:200px;',
|
||||
|
|
|
@ -3555,7 +3555,7 @@ function modules_get_agentmodule_mininterval_no_async($id_agent)
|
|||
}
|
||||
|
||||
|
||||
function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true)
|
||||
function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true, $useName=false)
|
||||
{
|
||||
if ((bool) is_metaconsole() === true) {
|
||||
if ($select_mode === true) {
|
||||
|
@ -3675,8 +3675,14 @@ function get_modules_agents($id_module_group, $id_agents, $selection, $select_mo
|
|||
|
||||
$modules = array_reduce(
|
||||
$modules,
|
||||
function ($carry, $item) {
|
||||
$carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre'];
|
||||
function ($carry, $item) use ($useName) {
|
||||
// Only works in select mode.
|
||||
if ($useName === true) {
|
||||
$carry[io_safe_input($item['nombre'])] = io_safe_input($item['nombre']);
|
||||
} else {
|
||||
$carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre'];
|
||||
}
|
||||
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
|
|
|
@ -388,7 +388,7 @@ function initialiceLayout(data) {
|
|||
dashboardId: data.dashboardId,
|
||||
widgetId: widgetId
|
||||
},
|
||||
width: widgetId == 14 || widgetId == 2 ? 750 : 450,
|
||||
width: widgetId == 14 || widgetId == 2 || widgetId == 23 ? 750 : 450,
|
||||
maxHeight: 600,
|
||||
minHeight: 400
|
||||
},
|
||||
|
|
|
@ -35,7 +35,6 @@ use PandoraFMS\Module;
|
|||
*/
|
||||
class AgentModuleWidget extends Widget
|
||||
{
|
||||
const MODULE_SEPARATOR = '|-|-|-|';
|
||||
|
||||
/**
|
||||
* Name widget.
|
||||
|
@ -309,16 +308,12 @@ class AgentModuleWidget extends Widget
|
|||
|
||||
if (is_metaconsole() === true) {
|
||||
$values['mModules'] = implode(
|
||||
self::MODULE_SEPARATOR,
|
||||
SEPARATOR_META_MODULE,
|
||||
array_reduce(
|
||||
$values['mModules'],
|
||||
function ($carry, $item) {
|
||||
$d = explode('|', $item);
|
||||
if (isset($d[1]) === true) {
|
||||
$carry[] = \io_safe_output($d[1]);
|
||||
} else {
|
||||
$carry[] = \io_safe_output($item);
|
||||
}
|
||||
$carry[] = (isset($d[1]) === true) ? $d[1] : $item;
|
||||
|
||||
return $carry;
|
||||
},
|
||||
|
@ -639,7 +634,7 @@ class AgentModuleWidget extends Widget
|
|||
$target_modules = $this->values['mModules'];
|
||||
if (is_metaconsole() === true) {
|
||||
$target_modules = explode(
|
||||
self::MODULE_SEPARATOR,
|
||||
SEPARATOR_META_MODULE,
|
||||
$this->values['mModules']
|
||||
);
|
||||
|
||||
|
@ -674,14 +669,7 @@ class AgentModuleWidget extends Widget
|
|||
if (is_object($item) === true) {
|
||||
$carry[$item->name()] = null;
|
||||
} else {
|
||||
if ((is_metaconsole() === true
|
||||
&& $this->values['mShowCommonModules'] !== '1')
|
||||
|| is_metaconsole() === false
|
||||
) {
|
||||
$carry[$item] = null;
|
||||
}
|
||||
|
||||
$carry[] = $item;
|
||||
$carry[io_safe_output($item)] = null;
|
||||
}
|
||||
|
||||
return $carry;
|
||||
|
@ -721,8 +709,20 @@ class AgentModuleWidget extends Widget
|
|||
) {
|
||||
// MC should connect to nodes and retrieve information
|
||||
// from targets.
|
||||
$reduceAllModules = [];
|
||||
$tmpModules = array_reduce(
|
||||
$target_modules,
|
||||
function ($carry, $item) {
|
||||
// In this case, the modules come with '» ' chain.
|
||||
$tmpCarry = explode('» ', $item);
|
||||
$carry[trim($tmpCarry[1])] = null;
|
||||
|
||||
return $carry;
|
||||
}
|
||||
);
|
||||
|
||||
$modules = $agent->searchModules(
|
||||
['id_agente_modulo' => $target_modules]
|
||||
['nombre' => array_keys($tmpModules)]
|
||||
);
|
||||
|
||||
foreach ($modules as $module) {
|
||||
|
|
Loading…
Reference in New Issue