Merge branch 'ent-10637-mejora-informe-grupo' into 'develop'

Ent 10637 mejora informe grupo

See merge request artica/pandorafms!6206
This commit is contained in:
Gorka Sanchez 2023-08-31 06:47:57 +00:00
commit 66eaf39645
5 changed files with 268 additions and 27 deletions

View File

@ -2648,14 +2648,16 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig
*
* @return string Html
*/
function tactical_groups_get_agents_and_monitoring($id_groups)
function tactical_groups_get_agents_and_monitoring($id_groups, $data='')
{
global $config;
$data = [
'total_agents' => groups_agents_total_counters($id_groups, false)['total'],
'monitor_total' => groups_get_total_monitors($id_groups, [], [], false, false, false, false),
];
if ($data === '') {
$data = [
'total_agents' => groups_agents_total_counters($id_groups, false)['total'],
'monitor_total' => groups_get_total_monitors($id_groups, [], [], false, false, false, false),
];
}
// Link URLS
$urls = [];
@ -2703,16 +2705,18 @@ function tactical_groups_get_agents_and_monitoring($id_groups)
* @param [type] $id_groups
* @return string Html.
*/
function tactical_groups_get_stats_alerts($id_groups)
function tactical_groups_get_stats_alerts($id_groups, $data='')
{
global $config;
$alerts = groups_monitor_alerts_total_counters($id_groups, false);
$data = [
'monitor_alerts' => $alerts['total'],
'monitor_alerts_fired' => $alerts['fired'],
if ($data === '') {
$alerts = groups_monitor_alerts_total_counters($id_groups, false);
$data = [
'monitor_alerts' => $alerts['total'],
'monitor_alerts_fired' => $alerts['fired'],
];
];
}
$urls = [];
$urls['monitor_alerts'] = $config['homeurl'].'index.php?sec=estado&sec2=operation/agentes/alerts_status&refr=60&ag_group='.$id_groups[0];
@ -2780,17 +2784,19 @@ function tactical_groups_get_stats_alerts($id_groups)
* @param boolean $data_agents
* @return void
*/
function groups_get_stats_modules_status($id_groups, $graph_width=250, $graph_height=150, $links=false, $data_agents=false)
function groups_get_stats_modules_status($id_groups, $graph_width=250, $graph_height=150, $links=false, $data_agents=false, $data='')
{
global $config;
$data = [
'monitor_critical' => groups_get_critical_monitors($id_groups, [], [], false, false, false, false),
'monitor_warning' => groups_get_warning_monitors($id_groups, [], [], false, false, false, false),
'monitor_ok' => groups_get_normal_monitors($id_groups, [], [], false, false, false, false),
'monitor_unknown' => groups_get_unknown_monitors($id_groups, [], [], false, false, false, false),
'monitor_not_init' => groups_get_not_init_monitors($id_groups, [], [], false, false, false, false),
];
if ($data === '') {
$data = [
'monitor_critical' => groups_get_critical_monitors($id_groups, [], [], false, false, false, false),
'monitor_warning' => groups_get_warning_monitors($id_groups, [], [], false, false, false, false),
'monitor_ok' => groups_get_normal_monitors($id_groups, [], [], false, false, false, false),
'monitor_unknown' => groups_get_unknown_monitors($id_groups, [], [], false, false, false, false),
'monitor_not_init' => groups_get_not_init_monitors($id_groups, [], [], false, false, false, false),
];
}
// Link URLS.
if ($links === false) {

View File

@ -2581,7 +2581,237 @@ function reporting_html_group_report($table, $item, $pdf=0)
$table->colspan['group_report']['cell'] = 3;
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
$data = "<table class='info_table' width='100%'>
$metaconsole_connected = false;
if (is_metaconsole() === true) {
$connection = metaconsole_get_connection($item['server_name']);
if (metaconsole_connect($connection) == NOERR) {
$metaconsole_connected = true;
}
}
if ($item['subtitle'] === 'All') {
$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'];
}
$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 ($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_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) {
metaconsole_restore_db();
}
$graph_width = 280;
$graph_height = 250;
$out = '<table width="100%" class="info_table">';
$out .= '<tbody>';
$out .= '<tr>';
$out .= '<td>';
$out .= '<fieldset class="databox tactical_set" id="group_view_'.$item['subtitle'].'">
<legend>'.$item['subtitle'].'&nbsp; &nbsp;'.$icon.'</legend>';
$out .= '<table class="info_table group_view_table">';
$out .= '<tr>';
$out .= '<td style="word-wrap:break-word; text-align: left;">
<fieldset>
<legend>'.__('Group Description').'</legend> &nbsp;'.$description.'</fieldset>
</td>';
$out .= '<td>';
$data = [
'monitor_alerts' => $item['data']['group_stats']['monitor_alerts'],
'monitor_alerts_fired' => $item['data']['group_stats']['monitor_alerts_fired'],
];
$out .= tactical_groups_get_stats_alerts($group_id, $data);
$out .= '</td>';
$out .= '</tr>';
$out .= '<tr>';
$out .= '<td>';
$data = [
'total_agents' => $item['data']['group_stats']['total_agents'],
'monitor_total' => $item['data']['group_stats']['monitor_checks'],
];
$out .= tactical_groups_get_agents_and_monitoring($group_id, $data);
$out .= '</td>';
$out .= '<td>';
$data = [
'monitor_critical' => $item['data']['group_stats']['monitor_critical'],
'monitor_warning' => $item['data']['group_stats']['monitor_warning'],
'monitor_ok' => $item['data']['group_stats']['monitor_ok'],
'monitor_unknown' => $item['data']['group_stats']['monitor_unknown'],
'monitor_not_init' => $item['data']['group_stats']['monitor_not_init'],
];
$out .= groups_get_stats_modules_status($group_id, 250, 150, false, false, $data);
$out .= '</td>';
$out .= '</tr>';
$out .= '<tr>';
$out .= '</td>';
$out .= '<td><fieldset><legend>'.__('Events per agent').'</legend>';
$data = [];
$options = [];
$labels = [];
foreach ($group_events as $value) {
$data[$value['alias']] = $value['count_events'];
$labels[] = io_safe_output($value['alias']);
}
if ($pdf !== 0) {
$ttl = 2;
} else {
$ttl = 0;
}
$options = [
'width' => $graph_width,
'height' => $graph_height,
'legend' => ['display' => false],
'labels' => $labels,
'ttl' => $ttl,
'legend' => [
'display' => true,
'position' => 'top',
'align' => 'center',
],
];
$out .= '<div id="events_per_agent_pie" style="height: '.$graph_height.'px">';
if ((int) $ttl === 2) {
$out .= '<img src="data:image/png;base64,';
} else {
$out .= '<div id="status_pie" style="margin: auto; width: '.$graph_width.'px;">';
}
$out .= pie_graph($data, $options);
if ((int) $ttl === 2) {
$out .= '" />';
} else {
$out .= '</div>';
}
$out .= '</div>';
$out .= '</fieldset>';
$out .= '</td>';
$out .= '<td><fieldset><legend>'.__('Distribution by OS').'</legend>';
$data = [];
$options = [];
$labels = [];
foreach ($group_os as $value) {
$data[$value['name_os']] = $value['count_os'];
$labels[] = io_safe_output($value['name_os']);
}
$options = [
'width' => $graph_width,
'height' => $graph_height,
'legend' => ['display' => false],
'labels' => $labels,
'ttl' => $ttl,
'legend' => [
'display' => true,
'position' => 'top',
'align' => 'center',
],
];
$out .= '<div id="group_os_pie" style="height: '.$graph_height.'px">';
if ((int) $ttl === 2) {
$out .= '<img src="data:image/png;base64,';
} else {
$out .= '<div id="status_pie" style="margin: auto; width: '.$graph_width.'px;">';
}
$out .= pie_graph($data, $options);
if ((int) $ttl === 2) {
$out .= '" />';
} else {
$out .= '</div>';
}
$out .= '</div>';
$out .= '</fieldset>';
$out .= '</td>';
$out .= '</tr>';
$out .= '</table>';
$out .= '</fieldset>';
$out .= '</td>';
$out .= '<td>';
$out .= '</td>';
$out .= '</td>';
$out .= '</tr>';
$out .= '</tbody>';
$out .= '</table>';
/*
$data = "<table class='info_table' width='100%'>
<tbody><tr>
<td></td>
<td colspan='3' class='cellBold cellCenter'>".__('Total')."</td>
@ -2624,12 +2854,12 @@ function reporting_html_group_report($table, $item, $pdf=0)
<td class='cellBold cellCenter'>".__('Events (not validated)')."</td>
<td colspan='6' class='cellBold cellCenter cellWhite cellBorder1 cellBig'>".$item['data']['count_events'].'</td>
</tr></tbody>
</table>';
</table>';*/
$table->data['group_report']['cell'] = $data;
$table->data['group_report']['cell'] = $out;
if ($pdf !== 0) {
return $data;
return $out;
}
}

View File

@ -12362,6 +12362,10 @@ tr[id^="network_component-plugin-snmp-fields-dynamicMacroRow-"] input {
width: 100% !important;
}
.group_view_table > tbody > tr > td {
width: 350px !important;
}
.notificaion_menu_container {
display: flex;
padding-top: 10px;

View File

@ -8,7 +8,7 @@
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|

View File

@ -4,7 +4,7 @@ pandoraPluginTools is a library that aims to help the creation of scripts and th
[PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
The package includes the following modules. Each one has different functions that facilitate and automate the data integration in Pandora FMS:
The package includes the following modules. Each one has different functions that facilitate and automate the data integration in Pandora FMS:
**general**
Module containing general purpose functions, useful in the creation of plugins for PandoraFMS.
@ -27,9 +27,9 @@ Module containing functions oriented to the creation of Pandora FMS discovery pl
**http**
Module containing functions oriented to HTTP API calls.
## Example
## Example
``` python
```python
import pandoraPluginTools as ppt
## Define agent
@ -65,6 +65,7 @@ ppt.transfer_xml(
```
The package has the following dependencies:
- Hashlib
- datetime.datetime
- hashlib