mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 08:45:12 +02:00
MC dashboards agent_module fixes
This commit is contained in:
parent
38a6d65f60
commit
55e272c360
@ -1084,6 +1084,7 @@ function agents_common_modules($id_agent, $filter=false, $indexed=true, $get_not
|
||||
* @param string $separator Only in metaconsole. Separator for the serialized data. By default |.
|
||||
* @param boolean $add_alert_bulk_op //TODO documentation
|
||||
* @param boolean $force_serialized. If the agent has not id_server (typically in node) put 0 as <server_id>.
|
||||
* @param boolean $meta_fields If true, then id_agente is returned instead id_tagente.
|
||||
*
|
||||
* @return array An array with all agents in the group or an empty array
|
||||
*/
|
||||
@ -1096,7 +1097,8 @@ function agents_get_group_agents(
|
||||
$serialized=false,
|
||||
$separator='|',
|
||||
$add_alert_bulk_op=false,
|
||||
$force_serialized=false
|
||||
$force_serialized=false,
|
||||
$meta_fields=false
|
||||
) {
|
||||
global $config;
|
||||
|
||||
@ -1268,11 +1270,19 @@ function agents_get_group_agents(
|
||||
if (is_metaconsole()) {
|
||||
$table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
|
||||
|
||||
if ($meta_fields === true) {
|
||||
$fields = [
|
||||
'id_agente',
|
||||
'alias',
|
||||
'ta.id_tmetaconsole_setup AS id_server',
|
||||
];
|
||||
} else {
|
||||
$fields = [
|
||||
'ta.id_tagente AS id_agente',
|
||||
'alias',
|
||||
'ta.id_tmetaconsole_setup AS id_server',
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$table_name = 'tagente LEFT JOIN tagent_secondary_group ON id_agente=id_agent';
|
||||
|
||||
@ -3253,6 +3263,7 @@ function agents_get_agent_custom_field($agent_id, $custom_field_name)
|
||||
* @param boolean $selection Show common (false) or all modules (true).
|
||||
* @param boolean $return Return (false) or dump to output (true).
|
||||
* @param boolean $index_by_name Use module name as key.
|
||||
* @param boolean $pure_return Return as retrieved from DB.
|
||||
*
|
||||
* @return array With modules or null if error.
|
||||
*/
|
||||
@ -3261,7 +3272,8 @@ function select_modules_for_agent_group(
|
||||
$id_agents,
|
||||
$selection,
|
||||
$return=true,
|
||||
$index_by_name=false
|
||||
$index_by_name=false,
|
||||
$pure_return=false
|
||||
) {
|
||||
global $config;
|
||||
$agents = (empty($id_agents)) ? [] : implode(',', $id_agents);
|
||||
@ -3341,6 +3353,10 @@ function select_modules_for_agent_group(
|
||||
return;
|
||||
}
|
||||
|
||||
if ($pure_return === true) {
|
||||
return $modules;
|
||||
}
|
||||
|
||||
$modules_array = [];
|
||||
foreach ($modules as $value) {
|
||||
if ($index_by_name) {
|
||||
|
@ -1351,7 +1351,29 @@ function html_print_select_multiple_modules_filtered(array $data):string
|
||||
|
||||
$output .= '<div>';
|
||||
// Agent.
|
||||
$agents = agents_get_group_agents($data['mGroup']);
|
||||
$agents = agents_get_group_agents(
|
||||
// Id_group.
|
||||
$data['mGroup'],
|
||||
// Search.
|
||||
false,
|
||||
// Case.
|
||||
'lower',
|
||||
// NoACL.
|
||||
false,
|
||||
// ChildGroups.
|
||||
false,
|
||||
// Serialized.
|
||||
false,
|
||||
// Separator.
|
||||
'|',
|
||||
// Add_alert_bulk_op.
|
||||
false,
|
||||
// Force_serialized.
|
||||
false,
|
||||
// Meta_fields.
|
||||
$data['mMetaFields']
|
||||
);
|
||||
|
||||
if ((empty($agents)) === true || $agents == -1) {
|
||||
$agents = [];
|
||||
}
|
||||
|
@ -266,6 +266,7 @@ class AgentModuleWidget extends Widget
|
||||
'mModules' => $this->values['mModules'],
|
||||
'mShowSelectedOtherGroups' => true,
|
||||
'mReturnAllGroup' => $return_all_group,
|
||||
'mMetaFields' => ((bool) is_metaconsole()),
|
||||
],
|
||||
];
|
||||
|
||||
@ -351,7 +352,10 @@ class AgentModuleWidget extends Widget
|
||||
|
||||
$agent_modules = db_get_all_rows_sql($sql);
|
||||
|
||||
$agent_modules = array_combine(array_column($agent_modules, 'id_agente_modulo'), array_column($agent_modules, 'nombre'));
|
||||
$agent_modules = array_combine(
|
||||
array_column($agent_modules, 'id_agente_modulo'),
|
||||
array_column($agent_modules, 'nombre')
|
||||
);
|
||||
|
||||
$row['modules'] = [];
|
||||
foreach ($modules_by_name as $module) {
|
||||
@ -449,6 +453,10 @@ class AgentModuleWidget extends Widget
|
||||
$table_data .= $file_name;
|
||||
$table_data .= '</td>';
|
||||
|
||||
if ($row['modules'] === null) {
|
||||
$row['modules'] = [];
|
||||
}
|
||||
|
||||
foreach ($row['modules'] as $module_name => $module) {
|
||||
if ($module === null) {
|
||||
if (in_array($module_name, $allModules) === true) {
|
||||
@ -591,6 +599,7 @@ class AgentModuleWidget extends Widget
|
||||
{
|
||||
global $config;
|
||||
|
||||
$output = '';
|
||||
if (check_acl($config['id_user'], 0, 'AR') === 0) {
|
||||
$output .= '<div class="container-center">';
|
||||
$output .= ui_print_error_message(
|
||||
@ -602,11 +611,12 @@ class AgentModuleWidget extends Widget
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Estract info all modules selected.
|
||||
// Extract info all modules selected.
|
||||
$target_modules = explode(',', $this->values['mModules']);
|
||||
$all_modules = Module::search(
|
||||
['id_agente_modulo' => $target_modules]
|
||||
);
|
||||
if ($all_modules !== null) {
|
||||
$reduceAllModules = array_reduce(
|
||||
$all_modules,
|
||||
function ($carry, $item) {
|
||||
@ -614,15 +624,31 @@ class AgentModuleWidget extends Widget
|
||||
return $carry;
|
||||
}
|
||||
);
|
||||
|
||||
\ksort($reduceAllModules);
|
||||
} else {
|
||||
$reduceAllModules = [];
|
||||
}
|
||||
|
||||
$visualData = [];
|
||||
// Estract info agents selected.
|
||||
// Extract info agents selected.
|
||||
$target_agents = explode(',', $this->values['mAgents']);
|
||||
foreach ($target_agents as $agent_id) {
|
||||
try {
|
||||
$agent = new Agent($agent_id);
|
||||
$id_agente = $agent_id;
|
||||
if ((bool) is_metaconsole() === true) {
|
||||
$tmeta_agent = db_get_row_filter(
|
||||
'tmetaconsole_agent',
|
||||
[ 'id_agente' => $id_agente ]
|
||||
);
|
||||
|
||||
$id_agente = $tmeta_agent['id_tagente'];
|
||||
$tserver = $tmeta_agent['id_tmetaconsole_setup'];
|
||||
|
||||
if (metaconsole_connect(null, $tserver) !== NOERR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$agent = new Agent((int) $id_agente);
|
||||
$visualData[$agent_id]['agent_status'] = $agent->lastStatus();
|
||||
$visualData[$agent_id]['agent_name'] = $agent->name();
|
||||
$visualData[$agent_id]['agent_alias'] = $agent->alias();
|
||||
@ -633,14 +659,27 @@ class AgentModuleWidget extends Widget
|
||||
|
||||
$visualData[$agent_id]['modules'] = $reduceAllModules;
|
||||
foreach ($modules as $module) {
|
||||
if ((bool) is_metaconsole() === true) {
|
||||
$reduceAllModules[$module->name()] = null;
|
||||
}
|
||||
|
||||
$visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'Error: '.$e->getMessage();
|
||||
|
||||
if ((bool) is_metaconsole() === true) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo 'Error: ['.$agent_id.']'.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
ksort($reduceAllModules);
|
||||
$allModules = array_keys($reduceAllModules);
|
||||
if ($allModules === null) {
|
||||
$allModules = [];
|
||||
}
|
||||
|
||||
$output = $this->generateViewAgentModule(
|
||||
$visualData,
|
||||
$allModules
|
||||
|
@ -88,7 +88,7 @@ class Module extends Entity
|
||||
* @param array $params Search parameters (fields from tagente_modulo).
|
||||
* @param integer $limit Limit results to N rows.
|
||||
*
|
||||
* @return PandoraFMS\Module found or null if not found.
|
||||
* @return array|null of PandoraFMS\Module found or null if not found.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public static function search(
|
||||
|
@ -163,7 +163,9 @@ if (is_ajax()) {
|
||||
// Add_alert_bulk_op.
|
||||
$cluster_mode,
|
||||
// Force_serialized.
|
||||
false
|
||||
false,
|
||||
// Meta fields.
|
||||
(bool) is_metaconsole()
|
||||
);
|
||||
|
||||
if (empty($agents)) {
|
||||
@ -192,8 +194,94 @@ if (is_ajax()) {
|
||||
$id_agents = get_parameter('id_agents');
|
||||
$selection = get_parameter('selection');
|
||||
|
||||
if ((bool) is_metaconsole() === true) {
|
||||
if (count($id_agents) > 0) {
|
||||
$rows = db_get_all_rows_sql(
|
||||
sprintf(
|
||||
'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup`
|
||||
FROM `tmetaconsole_agent`
|
||||
WHERE `id_agente` IN (%s)',
|
||||
implode(',', $id_agents)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$rows = [];
|
||||
}
|
||||
|
||||
$agents = array_reduce(
|
||||
$rows,
|
||||
function ($carry, $item) {
|
||||
if ($carry[$item['id_tmetaconsole_setup']] === null) {
|
||||
$carry[$item['id_tmetaconsole_setup']] = [];
|
||||
}
|
||||
|
||||
$carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente'];
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$modules = [];
|
||||
|
||||
foreach ($agents as $tserver => $id_agents) {
|
||||
if (metaconsole_connect(null, $tserver) == NOERR) {
|
||||
$modules[$tserver] = select_modules_for_agent_group(
|
||||
$id_group,
|
||||
$id_agents,
|
||||
$selection,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$selection) {
|
||||
// Common modules.
|
||||
$final_modules = [];
|
||||
$nodes_consulted = count($modules);
|
||||
|
||||
foreach ($modules as $tserver => $mods) {
|
||||
foreach ($mods as $module) {
|
||||
if ($final_modules[$module['nombre']] === null) {
|
||||
$final_modules[$module['nombre']] = 0;
|
||||
}
|
||||
|
||||
$final_modules[$module['nombre']]++;
|
||||
}
|
||||
}
|
||||
|
||||
$modules = [];
|
||||
$i = 1;
|
||||
foreach ($final_modules as $module_name => $occurrences) {
|
||||
if ($occurrences === $nodes_consulted) {
|
||||
// Module already present in ALL nodes.
|
||||
$modules[] = [
|
||||
'id_agente_modulo' => ($i++),
|
||||
'nombre' => $module_name,
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// All modules.
|
||||
$modules = array_reduce(
|
||||
$modules[$tserver],
|
||||
function ($carry, $item) {
|
||||
$carry[] = $item;
|
||||
return $carry;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($modules);
|
||||
} else {
|
||||
select_modules_for_agent_group($id_group, $id_agents, $selection);
|
||||
}
|
||||
}
|
||||
|
||||
if ($get_modules_group_value_name_json) {
|
||||
$id_agents = get_parameter('id_agents');
|
||||
|
Loading…
x
Reference in New Issue
Block a user