Merge branch 'ent-8409-bug-widget-agent-module-view' into 'develop'

Fix issue with modules

Closes pandora_enterprise#8409

See merge request artica/pandorafms!4616
This commit is contained in:
vgilc 2022-01-25 09:28:12 +00:00
commit 6749090cc6
6 changed files with 79 additions and 61 deletions

View File

@ -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");

View File

@ -1480,7 +1480,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'return' => true,
'nothing' => __('All'),
'nothing_value' => 0,
'script' => 'fmModuleChange(\''.$uniqId.'\')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
]
);
$output .= '</div>';
@ -1533,7 +1533,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
]
);
@ -1550,39 +1550,29 @@ function html_print_select_multiple_modules_filtered(array $data):string
'name' => 'filtered-module-show-common-modules-'.$uniqId,
'selected' => $data['mShowCommonModules'],
'return' => true,
'script' => 'fmModuleChange(\''.$uniqId.'\')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
]
);
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 ($data['mShowSelectedOtherGroups']) {
$selected_modules_ids = explode(',', $data['mModules']);
foreach ($selected_modules_ids as $id) {
if (!array_key_exists($id, $all_modules)) {
$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;',

View File

@ -3556,7 +3556,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) {
@ -3676,8 +3676,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'])] = $item['nombre'];
} else {
$carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre'];
}
return $carry;
},
[]

View File

@ -211,7 +211,7 @@ function fmAgentChange(uniqId) {
}
// eslint-disable-next-line no-unused-vars
function fmModuleChange(uniqId) {
function fmModuleChange(uniqId, isMeta) {
var idModuleGroup = $("#filtered-module-module-group-" + uniqId).val();
var idAgents = $("#filtered-module-agents-" + uniqId).val();
var showCommonModules = $(
@ -230,14 +230,20 @@ function fmModuleChange(uniqId) {
$("#filtered-module-modules-" + uniqId).html("");
if (data) {
jQuery.each(data, function(id, value) {
var option = $("<option></option>")
.attr(
"value",
value["id_node"]
? value["id_node"] + "|" + value["id_agente_modulo"]
: value["id_agente_modulo"]
)
.html(value["nombre"]);
var option = $("<option></option>");
if (isMeta === true) {
option
.attr(
"value",
value["id_node"]
? value["id_node"] + "|" + value["id_agente_modulo"]
: value["id_agente_modulo"]
)
.html(value["nombre"]);
} else {
option.attr("value", value).html(value);
}
$("#filtered-module-modules-" + uniqId).append(option);
});
}

View File

@ -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: 610,
minHeight: 400
},

View File

@ -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']
);
@ -648,8 +643,17 @@ class AgentModuleWidget extends Widget
if (is_array($target_modules) === true
|| is_numeric($target_modules) === true
) {
$target_modules = array_reduce(
$target_modules,
function ($carry, $item) {
$carry[] = io_safe_output($item);
return $carry;
}
);
$all_modules = Module::search(
['id_agente_modulo' => $target_modules]
['nombre' => $target_modules]
);
} else {
// From previous definitions.
@ -660,29 +664,28 @@ class AgentModuleWidget extends Widget
}
if ($all_modules !== null) {
$reduceAllModules = array_reduce(
$all_modules,
function ($carry, $item) {
if ($item === null) {
if (is_metaconsole() === true
&& $this->values['mShowCommonModules'] === '1'
) {
$reduceAllModules = [];
} else {
$reduceAllModules = array_reduce(
$all_modules,
function ($carry, $item) {
if ($item === null) {
return $carry;
}
if (is_object($item) === true) {
$carry[$item->name()] = null;
} else {
$carry[io_safe_output($item)] = null;
}
return $carry;
}
if (is_object($item) === true) {
$carry[$item->name()] = null;
} else {
if ((is_metaconsole() === true
&& $this->values['mShowCommonModules'] !== '1')
|| is_metaconsole() === false
) {
$carry[$item] = null;
}
}
return $carry;
}
);
} else {
$reduceAllModules = [];
);
}
}
$visualData = [];
@ -709,14 +712,26 @@ class AgentModuleWidget extends Widget
$visualData[$agent_id]['agent_status'] = $agent->lastStatus();
$visualData[$agent_id]['agent_name'] = $agent->name();
$visualData[$agent_id]['agent_alias'] = $agent->alias();
$visualData[$agent_id]['modules'] = [];
if (is_metaconsole() === true
&& $this->values['mShowCommonModules'] === '1'
) {
// MC should connect to nodes and retrieve information
// from targets.
$tmpModules = array_reduce(
$target_modules,
function ($carry, $item) {
// In this case, the modules come with '» ' chain.
$tmpCarry = explode('&raquo;&#x20;', $item);
$carry[trim($tmpCarry[1])] = null;
return $carry;
}
);
$modules = $agent->searchModules(
['id_agente_modulo' => $target_modules]
['nombre' => array_keys($tmpModules)]
);
foreach ($modules as $module) {