Merge remote-tracking branch 'origin/develop' into ent-8290-Crear-nueva-seccion-Operaciones-Masivas-borrado-agentes-en-Metaconsola

This commit is contained in:
Daniel Barbero Martin 2022-01-25 10:34:43 +01:00
commit 9a799a838d
11 changed files with 141 additions and 94 deletions

View File

@ -202,9 +202,7 @@ function extension_api_checker()
echo '</fieldset>';
echo "<div class='right'>";
echo '</div>';
echo '</form>';
echo "<form method='post'>";
echo '<fieldset>';
echo '<legend>'.__('Custom URL').'</legend>';
html_print_table($table3);

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

@ -1157,7 +1157,7 @@ function events_get_all(
}
if ($tags[0] === $id_tag) {
$_tmp .= ' AND ( ';
$_tmp .= ' AND (( ';
} else {
$_tmp .= ' OR ( ';
}
@ -1185,7 +1185,7 @@ function events_get_all(
$_tmp .= ') ';
}
$sql_filters[] = $_tmp;
$sql_filters[] = $_tmp.')';
}
}

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

@ -3231,9 +3231,10 @@ function modules_get_first_date($id_agent_module, $datelimit=0)
{
global $config;
// check datatype string or normal
// Check datatype string or normal.
$table = 'tagente_datos';
$module_type_str = modules_get_agentmodule_type($id_agent_module);
$module_type = modules_get_agentmodule_type($id_agent_module);
$module_type_str = modules_get_type_name($module_type);
if (strstr($module_type_str, 'string') !== false) {
$table = 'tagente_datos_string';
}
@ -3555,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) {
@ -3675,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

@ -683,10 +683,10 @@ function update_link(row_index, id_link) {
temp_link["text_end"] = data["text_end"];
$.each(graph.nodes, function(k, node) {
if (node["id_agent"] == data["id_db_target"]) {
if (node["id_db"] == data["id_db_target"]) {
temp_link["target"] = graph.nodes[k];
}
if (node["id_agent"] == data["id_db_source"]) {
if (node["id_db"] == data["id_db_source"]) {
temp_link["source"] = graph.nodes[k];
}
});
@ -703,9 +703,21 @@ function update_link(row_index, id_link) {
.append("g")
.attr("id", "layer_graph_nodes_" + networkmap_id);
var graph_links_aux = graph.links.filter(function(d, i) {
if (typeof d["source"] === "undefined") {
return false;
}
if (typeof d["target"] === "undefined") {
return false;
}
return d;
});
force
.nodes(graph.nodes)
.links(graph.links)
.links(graph_links_aux)
.start();
window.node = layer_graph_nodes.selectAll(".node");
@ -2353,9 +2365,21 @@ function refresh_holding_area() {
.append("g")
.attr("id", "layer_graph_nodes_" + networkmap_id);
var graph_links_aux = graph.links.filter(function(d, i) {
if (typeof d["source"] === "undefined") {
return false;
}
if (typeof d["target"] === "undefined") {
return false;
}
return d;
});
force
.nodes(graph.nodes)
.links(graph.links)
.links(graph_links_aux)
.start();
window.node = layer_graph_nodes.selectAll(".node");

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) {

View File

@ -1026,12 +1026,12 @@ if (is_ajax() === true) {
// Source_value is id_agente.
$source_text = '';
$source_agent = $interface_source;
$source_type = NODE_AGENT;
$source_type = ($interface_source == 0) ? NODE_PANDORA : NODE_AGENT;
$source_link_value = $source_agent;
}
// Search node id in map.
$child_id = db_get_value_filter(
$parent_id = db_get_value_filter(
'id',
'titem',
[
@ -1073,7 +1073,7 @@ if (is_ajax() === true) {
}
// Search node id in map.
$parent_id = db_get_value_filter(
$child_id = db_get_value_filter(
'id',
'titem',
[
@ -1089,10 +1089,10 @@ if (is_ajax() === true) {
$link['id_item'] = 0;
$link['deleted'] = 0;
$link['id_map'] = $networkmap_id;
$link['parent_type'] = $target_type;
$link['id_parent_source_data'] = $target_link_value;
$link['child_type'] = $source_type;
$link['id_child_source_data'] = $source_link_value;
$link['parent_type'] = $source_type;
$link['id_parent_source_data'] = $source_link_value;
$link['child_type'] = $target_type;
$link['id_child_source_data'] = $target_link_value;
$insert_result = db_process_sql_insert('trel_item', $link);
@ -1123,8 +1123,8 @@ if (is_ajax() === true) {
$return['text_start'] = $source_text;
$return['text_end'] = $target_text;
$return['id_db_link'] = $insert_result;
$return['id_db_source'] = $source_agent;
$return['id_db_target'] = $target_agent;
$return['id_db_source'] = $parent_id;
$return['id_db_target'] = $child_id;
$return['type_source'] = $source_type;
$return['type_target'] = $target_type;
} else {

View File

@ -454,20 +454,26 @@ if ($view_graph) {
data['threshold'] = 1;
}
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "html",
data: data,
success: function (data) {
document.getElementById("div-container").innerHTML = "";
$("#spinner_loading").hide();
$("#div-container").append(data);
},
error: function (data) {
console.error("Fatal error")
}
});
(function (stacked) {
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "html",
data: data,
success: function (data) {
if (stacked === "<?php echo CUSTOM_GRAPH_VBARS; ?>") {
document.getElementById("div-container").classList.add('w100p', 'height_600px');
}
document.getElementById("div-container").innerHTML = "";
$("#spinner_loading").hide();
$("#div-container").append(data);
},
error: function (data) {
console.error("Fatal error")
}
});
})(data['stacked']);
});