mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Fix group report metaconsole
This commit is contained in:
parent
deb1b0d88b
commit
da35e8e346
@ -26,6 +26,7 @@
|
|||||||
* GNU General Public License for more details.
|
* 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.php';
|
||||||
require_once $config['homedir'].'/include/functions_db.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->colspan['group_report']['cell'] = 3;
|
||||||
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
|
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
|
||||||
$metaconsole_connected = false;
|
$metaconsole_connected = false;
|
||||||
if (is_metaconsole() === true) {
|
if (is_metaconsole() === true && $item['server_name'] != '0') {
|
||||||
$connection = metaconsole_get_connection($item['server_name']);
|
$connection = metaconsole_get_connection($item['server_name']);
|
||||||
if (metaconsole_connect($connection) == NOERR) {
|
if (metaconsole_connect($connection) == NOERR) {
|
||||||
$metaconsole_connected = true;
|
$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 ($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 = [];
|
$group_id = [];
|
||||||
$all_group_id = db_get_all_rows_sql('SELECT id_grupo FROM tgrupo');
|
|
||||||
|
|
||||||
foreach ($all_group_id as $group) {
|
foreach ($all_group_id as $group) {
|
||||||
$group_id[] = $group['id_grupo'];
|
$group_id[] = $group['id_grupo'];
|
||||||
@ -2599,61 +2656,108 @@ function reporting_html_group_report($table, $item, $pdf=0)
|
|||||||
|
|
||||||
$description = __('Data view of all groups');
|
$description = __('Data view of all groups');
|
||||||
$icon = '';
|
$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 {
|
} else {
|
||||||
$group_id = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']);
|
$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);
|
if (is_metaconsole() === true && $item['server_name'] === 'all') {
|
||||||
$total_agents = db_get_all_rows_sql('SELECT COUNT(id_agente) as total FROM tagente where id_grupo = '.$group_id);
|
$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']) {
|
$group_id_node = db_get_value('id_grupo', 'tgrupo', 'nombre', $item['subtitle']);
|
||||||
$array_group_id = [];
|
$description = db_get_value('description', 'tgrupo', 'id_grupo', $group_id_node);
|
||||||
$array_group_id[] = $group_id;
|
$icon_url = db_get_value('icon', 'tgrupo', 'id_grupo', $group_id_node);
|
||||||
foreach ($childrens as $group) {
|
$icon = html_print_image(
|
||||||
$array_group_id[] = $group['id_grupo'];
|
'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;
|
$group_events = db_get_all_rows_sql(
|
||||||
$explode_group_id = implode(',', $group_id);
|
'SELECT COUNT(te.id_evento) as count_events, ta.alias
|
||||||
} else {
|
FROM tevento as te
|
||||||
$explode_group_id = $group_id;
|
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) {
|
if ($metaconsole_connected === true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user