Fix group report metaconsole

This commit is contained in:
Calvo 2023-09-05 13:13:16 +02:00
parent deb1b0d88b
commit da35e8e346
1 changed files with 154 additions and 50 deletions

View File

@ -26,6 +26,7 @@
* GNU General Public License for more details.
* ============================================================================
*/
use PandoraFMS\Enterprise\Metaconsole\Node;
require_once $config['homedir'].'/include/functions.php';
require_once $config['homedir'].'/include/functions_db.php';
@ -2582,16 +2583,72 @@ function reporting_html_group_report($table, $item, $pdf=0)
$table->colspan['group_report']['cell'] = 3;
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
$metaconsole_connected = false;
if (is_metaconsole() === true) {
if (is_metaconsole() === true && $item['server_name'] != '0') {
$connection = metaconsole_get_connection($item['server_name']);
if (metaconsole_connect($connection) == NOERR) {
$metaconsole_connected = true;
}
}
if (is_metaconsole() && $item['server_name'] === '0') {
$table_agent = 'tmetaconsole_agent';
} else {
$table_agent = 'tagente';
}
$all_group_id = [];
$group_events = [];
$group_os = [];
if ($item['subtitle'] === 'All') {
if (is_metaconsole() === true && $item['server_name'] === 'all') {
$nodes = metaconsole_get_connections();
foreach ($nodes as $node) {
try {
$nd = new Node($node['id']);
$nd->connect();
$all_group_id_node = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo');
$group_events_node = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN tagente as ta ON te.id_agente = ta.id_agente
GROUP BY te.id_agente'
);
$group_os_node = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN tagente as ta ON ta.id_os = os.id_os GROUP by os.name'
);
$all_group_id = array_merge($all_group_id, $all_group_id_node);
$group_events = array_merge($group_events, $group_events_node);
$group_os = array_merge($group_os, $group_os_node);
} catch (\Exception $e) {
$nd->disconnect();
$modules_regex_node = [];
} finally {
$nd->disconnect();
}
}
} else {
$all_group_id = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo');
$group_events = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN '.$table_agent.' as ta ON te.id_agente = ta.id_agente
GROUP BY te.id_agente'
);
$group_os = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN '.$table_agent.' as ta ON ta.id_os = os.id_os GROUP by os.name'
);
}
$group_id = [];
$all_group_id = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo');
foreach ($all_group_id as $group) {
$group_id[] = $group['id_grupo'];
@ -2599,61 +2656,108 @@ function reporting_html_group_report($table, $item, $pdf=0)
$description = __('Data view of all groups');
$icon = '';
$group_events = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN tagente as ta ON te.id_agente = ta.id_agente
GROUP BY te.id_agente'
);
$group_os = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN tagente as ta ON ta.id_os = os.id_os GROUP by os.name'
);
} else {
$group_id = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']);
$description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id);
$icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id);
$icon = html_print_image(
'images/'.$icon_url,
true,
[
'title' => $item['subtitle'],
'class' => 'main_menu_icon invert_filter',
]
);
$childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id);
$total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id);
if (is_metaconsole() === true && $item['server_name'] === 'all') {
$nodes = metaconsole_get_connections();
foreach ($nodes as $node) {
try {
$nd = new Node($node['id']);
$nd->connect();
if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) {
$array_group_id = [];
$array_group_id[] = $group_id;
foreach ($childrens as $group) {
$array_group_id[] = $group['id_grupo'];
$group_id_node = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']);
$description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id_node);
$icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id_node);
$icon = html_print_image(
'images/'.$icon_url,
true,
[
'title' => $item['subtitle'],
'class' => 'main_menu_icon invert_filter',
]
);
$childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id_node);
$total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id_node);
if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) {
$array_group_id = [];
$array_group_id[] = $group_id_node;
foreach ($childrens as $group) {
$array_group_id[] = $group['id_grupo'];
}
$group_id_node = $array_group_id;
$explode_group_id = implode(',', $group_id_node);
} else {
$explode_group_id = $group_id_node;
}
$group_events_node = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN tagente as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.')
GROUP BY te.id_agente'
);
$group_os_node = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN tagente as ta ON ta.id_os = os.id_os
WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name'
);
$group_events = array_merge($group_events, $group_events_node);
$group_os = array_merge($group_os, $group_os_node);
} catch (\Exception $e) {
$nd->disconnect();
} finally {
$nd->disconnect();
}
}
} else {
$description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id);
$icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id);
$icon = html_print_image(
'images/'.$icon_url,
true,
[
'title' => $item['subtitle'],
'class' => 'main_menu_icon invert_filter',
]
);
$childrens = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo WHERE parent = '.$group_id);
$total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM '.$table_agent.' where id_grupo = '.$group_id);
if ($childrens !== false && (int) $total_agents[0]['total'] !== $item['data']['group_stats']['total_agents']) {
$array_group_id = [];
$array_group_id[] = $group_id;
foreach ($childrens as $group) {
$array_group_id[] = $group['id_grupo'];
}
$group_id = $array_group_id;
$explode_group_id = implode(',', $group_id);
} else {
$explode_group_id = $group_id;
}
$group_id = $array_group_id;
$explode_group_id = implode(',', $group_id);
} else {
$explode_group_id = $group_id;
$group_events = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN '.$table_agent.' as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.')
GROUP BY te.id_agente'
);
$group_os = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN '.$table_agent.' as ta ON ta.id_os = os.id_os
WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name'
);
}
$group_events = db_get_all_rows_sql(
'SELECT COUNT(te.id_evento) as count_events, ta.alias
FROM tevento as te
INNER JOIN tagente as ta ON te.id_agente = ta.id_agente WHERE te.id_grupo IN ('.$explode_group_id.')
GROUP BY te.id_agente'
);
$group_os = db_get_all_rows_sql(
'SELECT COUNT(os.name) as count_os, os.name as name_os, ta.id_grupo
FROM tconfig_os as os
INNER JOIN tagente as ta ON ta.id_os = os.id_os
WHERE ta.id_grupo IN ('.$explode_group_id.') GROUP by os.name'
);
}
if ($metaconsole_connected === true) {