Merge branch 'ent-11460-top-n-events-by-agent-y-by-module-en-metaconsola-no-toman-en-cuenta-los-top-n-de-los-nodos' into 'develop'

Ent 11460 top n events by agent y by module en metaconsola no toman en cuenta los top n de los nodos

See merge request artica/pandorafms!6036
This commit is contained in:
Gorka Sanchez 2023-07-03 07:37:28 +00:00
commit 029cb77068
2 changed files with 186 additions and 67 deletions

View File

@ -385,33 +385,81 @@ class TopNEventByGroupWidget extends Widget
$all_group = true;
}
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente, COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente, COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
if (is_metaconsole() === true) {
$servers = metaconsole_get_connection_names();
$result = [];
foreach ($servers as $key => $server) {
$connection = metaconsole_get_connection($server);
if (metaconsole_connect($connection) != NOERR) {
continue;
}
$result = db_get_all_rows_sql($sql);
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente,
COUNT(*) AS count,
"'.$connection['id'].'" AS id_server
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente,
COUNT(*) AS count,
"'.$connection['id'].'" AS id_server
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
$rows = db_get_all_rows_sql($sql);
if ($rows !== false) {
$result = array_merge($result, $rows);
}
metaconsole_restore_db();
}
} else {
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente, COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente, COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agente
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
$result = db_get_all_rows_sql($sql);
}
if (empty($result) === true) {
$output .= '<div class="container-center">';
@ -430,11 +478,13 @@ class TopNEventByGroupWidget extends Widget
$name = __('System');
} else {
if (is_metaconsole() === true) {
$name = (string) db_get_value(
$name = (string) db_get_value_filter(
'alias',
'tmetaconsole_agent',
'id_tagente',
(int) $row['id_agente']
[
'id_tagente' => $row['id_agente'],
'id_tmetaconsole_setup' => $row['id_server'],
]
);
} else {
$name = io_safe_output(

View File

@ -383,39 +383,91 @@ class TopNEventByModuleWidget extends Widget
$all_group = true;
}
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
if (is_metaconsole() === true) {
$servers = metaconsole_get_connection_names();
$result = [];
foreach ($servers as $key => $server) {
$connection = metaconsole_get_connection($server);
if (metaconsole_connect($connection) != NOERR) {
continue;
}
$result = db_get_all_rows_sql($sql);
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
"'.$server.'" AS name_server,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
"'.$server.'" AS name_server,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
$rows = db_get_all_rows_sql($sql);
if ($rows !== false) {
$result = array_merge($result, $rows);
}
metaconsole_restore_db();
}
} else {
if ($all_group === false) {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
AND id_grupo IN (%s)
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
implode(',', $this->values['groupId']),
$this->values['amountShow']
);
} else {
$sql = sprintf(
'SELECT id_agente,
id_agentmodule,
event_type,
COUNT(*) AS count
FROM tevento
WHERE utimestamp >= %d
GROUP BY id_agentmodule, event_type
ORDER BY count DESC
LIMIT %d',
$timestamp,
$this->values['amountShow']
);
}
$result = db_get_all_rows_sql($sql);
}
if (empty($result) === true) {
$output = '<div class="container-center">';
@ -433,13 +485,30 @@ class TopNEventByModuleWidget extends Widget
if ($row['id_agentmodule'] == 0) {
$name = __('System');
} else {
$name_agent = io_safe_output(
agents_get_alias($row['id_agente'])
);
if (is_metaconsole() === true) {
$connection = metaconsole_get_connection($row['name_server']);
if (metaconsole_connect($connection) != NOERR) {
continue;
}
$name_agent = io_safe_output(
agents_get_alias($row['id_agente'])
);
$name_module = io_safe_output(
modules_get_agentmodule_name($row['id_agentmodule'])
);
metaconsole_restore_db();
} else {
$name_agent = io_safe_output(
agents_get_alias($row['id_agente'])
);
$name_module = io_safe_output(
modules_get_agentmodule_name($row['id_agentmodule'])
);
}
$name_module = io_safe_output(
modules_get_agentmodule_name($row['id_agentmodule'])
);
if ($size['width'] < 400) {
$name_agent = ui_print_truncate_text(
$name_agent,