Merge branch 'ent-11953-informe-group-report-en-meta-no-muestra-mas-nodos-que-el-1' into 'develop'

Ent 11953 informe group report en meta no muestra mas nodos que el 1

See merge request artica/pandorafms!6408
This commit is contained in:
Rafael Ameijeiras 2023-09-08 07:25:04 +00:00
commit 885ed9747b
3 changed files with 205 additions and 77 deletions

View File

@ -1272,36 +1272,58 @@ $class = 'databox filters';
}
?>
<?php
if (is_metaconsole() === true) {
?>
<tr id="row_servers_all" class="datos">
<td class="bolder"><?php echo __('Server'); ?></td>
<td >
<?php
if ($meta) {
?>
html_print_select(
$servers,
'combo_server_all',
$server_name,
'',
__('All nodes'),
'all'
);
?>
</td>
</tr>
<?php
}
?>
<?php
if ($meta) {
?>
<tr id="row_multiple_servers" class="datos">
<td class="bolder"><?php echo __('Server'); ?></td>
<td >
<?php
$server_ids = [];
$server_ids[0] = __('Local metaconsole');
$get_servers = metaconsole_get_servers();
foreach ($get_servers as $key => $server) {
$server_ids[$server['id']] = $server['server_name'];
}
<?php
$server_ids = [];
$server_ids[0] = __('Local metaconsole');
$get_servers = metaconsole_get_servers();
foreach ($get_servers as $key => $server) {
$server_ids[$server['id']] = $server['server_name'];
}
html_print_select(
$server_ids,
'server_multiple[]',
$server_multiple,
'',
'',
0,
false,
true
);
?>
html_print_select(
$server_ids,
'server_multiple[]',
$server_multiple,
'',
'',
0,
false,
true
);
?>
</td>
</tr>
<?php
}
?>
}
?>
<tr id="row_label" class="datos">
<td class="bolder">
@ -6545,6 +6567,7 @@ function chooseType() {
$("#row_alert_actions").hide();
$("#row_servers").hide();
$("#row_servers_all_opt").hide();
$("#row_servers_all").hide();
$("#row_multiple_servers").hide();
$("#row_sort").hide();
$("#row_date").hide();
@ -7109,7 +7132,7 @@ function chooseType() {
case 'group_report':
$("#row_group").show();
$("#row_servers_all_opt").show();
$("#row_servers_all").show();
$("#row_description").show();
$("#row_historical_db_check").hide();
break;

View File

@ -1986,7 +1986,7 @@ switch ($action) {
break;
case 'group_report':
$values['server_name'] = get_parameter('combo_server');
$values['server_name'] = get_parameter('combo_server_all');
$good_format = true;
break;
@ -2862,7 +2862,7 @@ switch ($action) {
break;
case 'group_report':
$values['server_name'] = get_parameter('combo_server');
$values['server_name'] = get_parameter('combo_server_all');
$good_format = true;
break;

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,66 @@ 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;
}
}
$all_group_id = [];
$group_events = [];
$group_os = [];
if ($item['subtitle'] === 'All') {
if (is_metaconsole() === true && $item['server_name'] === 'all' || $item['server_name'] === '0') {
$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 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'
);
}
$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 +2650,113 @@ 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' || $item['server_name'] === '0') {
$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'
);
if (is_array($group_events_node) === true) {
$group_events = array_merge($group_events, $group_events_node);
}
if (is_array($group_os_node) === true) {
$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 tagente 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 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'
);
}
$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) {
@ -2764,8 +2867,10 @@ function reporting_html_group_report($table, $item, $pdf=0)
$options = [];
$labels = [];
foreach ($group_os as $value) {
$data[$value['name_os']] = $value['count_os'];
$labels[] = io_safe_output($value['name_os']);
$data[$value['name_os']] += $value['count_os'];
if (array_search($value['name_os'], $labels) === false) {
$labels[] = io_safe_output($value['name_os']);
}
}
$options = [