Optimiized monitors view

This commit is contained in:
Calvo 2023-11-03 17:48:15 +01:00
parent a7a3399c8c
commit 92ee718f91
1 changed files with 60 additions and 55 deletions

View File

@ -27,6 +27,7 @@
*/ */
// Begin. // Begin.
use PandoraFMS\Enterprise\Metaconsole\Node;
global $config; global $config;
check_login(); check_login();
@ -188,7 +189,7 @@ $sql_from = ' FROM tagente_modulo
INNER JOIN tagente INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
LEFT JOIN tagent_secondary_group tasg LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent ON tagente_modulo.id_agente = tasg.id_agent
INNER JOIN tagente_estado INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
INNER JOIN tmodule INNER JOIN tmodule
@ -436,12 +437,22 @@ if ($moduletype != '') {
// Freestring selector. // Freestring selector.
if ($ag_freestring != '') { if ($ag_freestring != '') {
$sql_conditions .= ' AND (tagente.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' $sql_conditions .= ' AND EXISTS (
OR tagente.alias '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' SELECT 1
OR tagente_modulo.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' FROM tagente
OR tagente_modulo.descripcion '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\')'; WHERE tagente.id_agente = tagente_modulo.id_agente
AND (
tagente.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' OR tagente.alias '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\'
)
AND (
tagente_modulo.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\'
OR tagente_modulo.descripcion '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\')
)';
} }
// Status selector. // Status selector.
if ($status == AGENT_MODULE_STATUS_NORMAL) { if ($status == AGENT_MODULE_STATUS_NORMAL) {
// Normal. // Normal.
@ -1348,15 +1359,10 @@ $sql = 'SELECT
tagente.nombre AS agent_name, tagente.nombre AS agent_name,
tagente_modulo.nombre AS module_name, tagente_modulo.nombre AS module_name,
tagente_modulo.history_data, tagente_modulo.history_data,
tagente_modulo.flag AS flag,
tagente.id_grupo AS id_group, tagente.id_grupo AS id_group,
tagente.id_agente AS id_agent, tagente.id_agente AS id_agent,
tagente_modulo.id_tipo_modulo AS module_type, tagente_modulo.id_tipo_modulo AS module_type,
tagente_modulo.module_interval, tagente_modulo.module_interval,
tagente_modulo.tcp_send,
tagente_modulo.ip_target,
tagente_modulo.snmp_community,
tagente_modulo.snmp_oid,
tagente_estado.datos, tagente_estado.datos,
tagente_estado.estado, tagente_estado.estado,
tagente_estado.last_status_change, tagente_estado.last_status_change,
@ -1370,13 +1376,12 @@ $sql = 'SELECT
tagente_modulo.extended_info, tagente_modulo.extended_info,
tagente_modulo.critical_inverse, tagente_modulo.critical_inverse,
tagente_modulo.warning_inverse, tagente_modulo.warning_inverse,
tagente_modulo.critical_instructions,
tagente_modulo.warning_instructions,
tagente_modulo.unknown_instructions,
tagente_estado.utimestamp AS utimestamp'.$sql_from.$sql_conditions_all.' tagente_estado.utimestamp AS utimestamp'.$sql_from.$sql_conditions_all.'
GROUP BY tagente_modulo.id_agente_modulo GROUP BY tagente_modulo.id_agente_modulo
ORDER BY '.$order['field'].' '.$order['order'].' ORDER BY '.$order['field'].' '.$order['order'].'
LIMIT '.$offset.','.$limit_sql; LIMIT '.$limit_sql.' OFFSET '.$offset;
hd($sql);
// We do not show the modules until the user searches with the filter. // We do not show the modules until the user searches with the filter.
if ($autosearch) { if ($autosearch) {
@ -1402,53 +1407,53 @@ if ($autosearch) {
$result = []; $result = [];
$count_modules = 0; $count_modules = 0;
foreach ($servers as $server) { foreach ($servers as $server) {
// If connection was good then retrieve all data server. try {
if (metaconsole_connect($server) === NOERR) { $node = new Node((int) $server['id']);
$connection = true; $node->connect();
} else {
$connection = false;
}
$result_server = db_get_all_rows_sql($sql); $result_server = db_get_all_rows_sql($sql);
if (empty($result_server) === false) { if (empty($result_server) === false) {
// Create HASH login info. // Create HASH login info.
$pwd = $server['auth_token']; $pwd = $server['auth_token'];
$auth_serialized = json_decode($pwd, true); $auth_serialized = json_decode($pwd, true);
if (is_array($auth_serialized)) { if (is_array($auth_serialized)) {
$pwd = $auth_serialized['auth_token']; $pwd = $auth_serialized['auth_token'];
$api_password = $auth_serialized['api_password']; $api_password = $auth_serialized['api_password'];
$console_user = $auth_serialized['console_user']; $console_user = $auth_serialized['console_user'];
$console_password = $auth_serialized['console_password']; $console_password = $auth_serialized['console_password'];
}
$user = $config['id_user'];
$user_rot13 = str_rot13($config['id_user']);
$hashdata = $user.$pwd;
$hashdata = md5($hashdata);
foreach ($result_server as $result_element_key => $result_element_value) {
$result_server[$result_element_key]['server_id'] = $server['id'];
$result_server[$result_element_key]['server_name'] = $server['server_name'];
$result_server[$result_element_key]['server_url'] = $server['server_url'].'/';
$result_server[$result_element_key]['hashdata'] = $hashdata;
$result_server[$result_element_key]['user'] = $config['id_user'];
$result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent(
$result_element_value['id_agent'],
$result_element_value['id_group']
);
$count_modules++;
}
$result = array_merge($result, $result_server);
} }
$user = $config['id_user']; usort($result, arrayOutputSorting($sort, $fieldForSorting));
$user_rot13 = str_rot13($config['id_user']); } catch (\Exception $e) {
$hashdata = $user.$pwd; $node->disconnect();
$hashdata = md5($hashdata); return;
$url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13; } finally {
$node->disconnect();
foreach ($result_server as $result_element_key => $result_element_value) {
$result_server[$result_element_key]['server_id'] = $server['id'];
$result_server[$result_element_key]['server_name'] = $server['server_name'];
$result_server[$result_element_key]['server_url'] = $server['server_url'].'/';
$result_server[$result_element_key]['hashdata'] = $hashdata;
$result_server[$result_element_key]['user'] = $config['id_user'];
$result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent(
$result_element_value['id_agent'],
$result_element_value['id_group']
);
$count_modules++;
}
$result = array_merge($result, $result_server);
} }
usort($result, arrayOutputSorting($sort, $fieldForSorting));
metaconsole_restore_db();
} }
if ($count_modules > $config['block_size']) { if ($count_modules > $config['block_size']) {