phpchartjs pandora_enterprise#9554

This commit is contained in:
daniel 2022-12-22 23:03:52 +01:00
parent 2b104ca905
commit 5907d55ec1
12 changed files with 357 additions and 195 deletions

View File

@ -5191,7 +5191,7 @@ function events_get_count_events_validated_by_user($data)
) { ) {
foreach ($fullnames as $value) { foreach ($fullnames as $value) {
if (isset($data_graph_by_user[$value['id_user']]) === true) { if (isset($data_graph_by_user[$value['id_user']]) === true) {
$data_graph_by_user[$value['fullname']] = $data_graph_by_user[$value['id_user']]; $data_graph_by_user[io_safe_output($value['fullname'])] = $data_graph_by_user[$value['id_user']];
unset($data_graph_by_user[$value['id_user']]); unset($data_graph_by_user[$value['id_user']]);
} }
} }

View File

@ -2224,22 +2224,22 @@ function graphic_combined_module(
'id_agente', 'id_agente',
$module_data['id_agente'] $module_data['id_agente']
); );
if ($params['vconsole'] === true) {
if ($width < 250 || $height < 250) {
$label = substr(
io_safe_output($module_data['nombre']),
0,
5
);
} else {
$label = $module_data['nombre'];
}
} else {
$label = $alias.' - '.$module_data['nombre']; $label = $alias.' - '.$module_data['nombre'];
} }
}
$temp[io_safe_output($label)] = round($temp_data, 4); $graph_labels[] = io_safe_output($label);
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
$graph_values[] = [
'y' => io_safe_output($label),
'x' => round($temp_data, 4),
];
} else {
$graph_values[] = [
'x' => io_safe_output($label),
'y' => round($temp_data, 4),
];
}
if (is_metaconsole() === true) { if (is_metaconsole() === true) {
metaconsole_restore_db(); metaconsole_restore_db();
@ -2248,7 +2248,6 @@ function graphic_combined_module(
$i++; $i++;
} }
$graph_values = $temp;
$color = color_graph_array(); $color = color_graph_array();
if ($params['vconsole'] === true) { if ($params['vconsole'] === true) {
@ -2270,6 +2269,7 @@ function graphic_combined_module(
'grid' => ['display' => false], 'grid' => ['display' => false],
], ],
], ],
'labels' => $graph_labels,
]; ];
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) { if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
@ -2313,18 +2313,15 @@ function graphic_combined_module(
'SELECT datos 'SELECT datos
FROM tagente_datos FROM tagente_datos
WHERE id_agente_modulo = %d WHERE id_agente_modulo = %d
AND utimestamp > %d
AND utimestamp < %d AND utimestamp < %d
ORDER BY utimestamp DESC', ORDER BY utimestamp DESC',
$module, $module,
$datelimit,
$params['date'] $params['date']
); );
$temp_data = db_get_value_sql($query_last_value); $temp_data = db_get_value_sql($query_last_value);
if ($temp_data !== false) {
if ($temp_data) { if (is_numeric($temp_data) === true) {
if (is_numeric($temp_data)) {
$value = $temp_data; $value = $temp_data;
} else { } else {
$value = count($value); $value = count($value);
@ -2335,8 +2332,8 @@ function graphic_combined_module(
$total_modules += $value; $total_modules += $value;
if (!empty($params_combined['labels']) if (empty($params_combined['labels']) === false
&& isset($params_combined['labels'][$module]) && isset($params_combined['labels'][$module]) === true
) { ) {
$label = io_safe_output( $label = io_safe_output(
$params_combined['labels'][$module] $params_combined['labels'][$module]
@ -2356,29 +2353,19 @@ function graphic_combined_module(
$label .= ' ('.$value.')'; $label .= ' ('.$value.')';
} }
$temp[$label] = $value; $graph_labels[] = io_safe_output($label);
$graph_values[] = round($temp_data, 4);
if (is_metaconsole() === true) { if (is_metaconsole() === true) {
metaconsole_restore_db(); metaconsole_restore_db();
} }
} }
$graph_values = $temp; if ($params['vconsole'] === true) {
if ($params['vconsole'] === false) {
$width = $width;
$height = 500;
} else {
$water_mark = false; $water_mark = false;
} }
$color = color_graph_array();
$width = null;
$height = null;
$options = [ $options = [
'width' => $width,
'height' => $height,
'waterMark' => $water_mark, 'waterMark' => $water_mark,
'ttl' => $ttl, 'ttl' => $ttl,
'pdf' => $params['pdf'], 'pdf' => $params['pdf'],
@ -2387,6 +2374,7 @@ function graphic_combined_module(
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $graph_labels,
]; ];
if ((bool) $params['pdf'] === true) { if ((bool) $params['pdf'] === true) {
@ -2559,8 +2547,13 @@ function graphic_agentaccess(
$colors = []; $colors = [];
if (isset($data) === true && is_array($data) === true) { if (isset($data) === true && is_array($data) === true) {
foreach ($data as $value) { foreach ($data as $value) {
$time = (date('H:m', $value['utimestamp'])); $time = io_safe_output(date('H:m', $value['utimestamp']));
$data_array[$time] = (int) $value['data']; $labels[] = $time;
$data_array[] = [
'y' => (int) $value['data'],
'x' => $time,
];
$colors[] = '#82b92f'; $colors[] = '#82b92f';
} }
} }
@ -2591,6 +2584,7 @@ function graphic_agentaccess(
], ],
], ],
], ],
'labels' => $labels,
]; ];
return vbar_graph($data_array, $options); return vbar_graph($data_array, $options);
@ -2610,27 +2604,25 @@ function graph_alert_status($defined_alerts, $fired_alerts, $width=300, $height=
{ {
global $config; global $config;
$labels = [
__('Not fired alerts'),
__('Fired alerts'),
];
$data = [ $data = [
__('Not fired alerts') => ($defined_alerts - $fired_alerts), ($defined_alerts - $fired_alerts),
__('Fired alerts') => $fired_alerts, $fired_alerts,
]; ];
$colors = [ $colors = [
COL_NORMAL, COL_NORMAL,
COL_ALERTFIRED, COL_ALERTFIRED,
]; ];
if ($config['fixed_graph'] == false) {
$water_mark = [
'file' => $config['homedir'].'/images/logo_vertical_water.png',
'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false),
];
}
$options = [ $options = [
'width' => $width, 'width' => $width,
'height' => $height, 'height' => $height,
'colors' => $colors, 'colors' => $colors,
'legend' => ['display' => false], 'legend' => ['display' => false],
'labels' => $labels,
]; ];
$out = pie_graph( $out = pie_graph(
@ -2638,7 +2630,7 @@ function graph_alert_status($defined_alerts, $fired_alerts, $width=300, $height=
$options $options
); );
if ($return) { if ($return === true) {
return $out; return $out;
} else { } else {
echo $out; echo $out;
@ -2925,10 +2917,11 @@ function grafico_incidente_prioridad()
$integria_priorities_map_indexed_by_id = array_combine($integria_priorities_map_ids, $integria_priorities_map_names); $integria_priorities_map_indexed_by_id = array_combine($integria_priorities_map_ids, $integria_priorities_map_names);
$data = []; $data = [];
$labels = [];
foreach ($integria_ticket_count_by_priority as $item) { foreach ($integria_ticket_count_by_priority as $item) {
$priority_name = $integria_priorities_map_indexed_by_id[$item['prioridad']]; $priority_name = $integria_priorities_map_indexed_by_id[$item['prioridad']];
$data[__($priority_name)] = $item['n_incidents']; $labels[] = io_safe_output($priority_name);
$data[] = $item['n_incidents'];
} }
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
@ -2947,6 +2940,7 @@ function grafico_incidente_prioridad()
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$output = '<div style="width:inherit;margin: 0 auto;">'; $output = '<div style="width:inherit;margin: 0 auto;">';
@ -2979,10 +2973,11 @@ function graph_incidents_status()
$integria_status_map_indexed_by_id = array_combine($integria_status_map_ids, $integria_status_map_names); $integria_status_map_indexed_by_id = array_combine($integria_status_map_ids, $integria_status_map_names);
$data = []; $data = [];
$labels = [];
foreach ($integria_ticket_count_by_status as $item) { foreach ($integria_ticket_count_by_status as $item) {
$status_name = $integria_status_map_indexed_by_id[$item['estado']]; $status_name = $integria_status_map_indexed_by_id[$item['estado']];
$data[__($status_name)] = $item['n_incidents']; $labels[] = io_safe_output($status_name);
$data[] = $item['n_incidents'];
} }
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
@ -3001,6 +2996,7 @@ function graph_incidents_status()
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$output = '<div style="width:inherit;margin: 0 auto;">'; $output = '<div style="width:inherit;margin: 0 auto;">';
@ -3029,10 +3025,11 @@ function graphic_incident_group()
$integria_group_map = json_decode($integria_group_map_json, true); $integria_group_map = json_decode($integria_group_map_json, true);
$data = []; $data = [];
$labels = [];
foreach ($integria_ticket_count_by_group as $item) { foreach ($integria_ticket_count_by_group as $item) {
$group_name = $integria_group_map[$item['id_grupo']]; $group_name = $integria_group_map[$item['id_grupo']];
$data[__($group_name)] = $item['n_incidents']; $labels[] = io_safe_output($group_name);
$data[] = $item['n_incidents'];
} }
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
@ -3051,6 +3048,7 @@ function graphic_incident_group()
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$output = '<div style="width:inherit;margin: 0 auto;">'; $output = '<div style="width:inherit;margin: 0 auto;">';
@ -3081,9 +3079,10 @@ function graphic_incident_user()
$integria_ticket_count_by_user = json_decode($integria_ticket_count_by_user_json, true); $integria_ticket_count_by_user = json_decode($integria_ticket_count_by_user_json, true);
$data = []; $data = [];
$labels = [];
foreach ($integria_ticket_count_by_user as $item) { foreach ($integria_ticket_count_by_user as $item) {
$data[__($item['id_usuario'])] = $item['n_incidents']; $labels[] = (empty($item['id_usuario']) === false) ? io_safe_output($item['id_usuario']) : '--';
$data[] = $item['n_incidents'];
} }
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
@ -3102,6 +3101,7 @@ function graphic_incident_user()
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$output = '<div style="width:inherit;margin: 0 auto;">'; $output = '<div style="width:inherit;margin: 0 auto;">';
@ -3145,6 +3145,7 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr
// It was urlencoded, so we urldecode it. // It was urlencoded, so we urldecode it.
$url = html_entity_decode(rawurldecode($url), ENT_QUOTES); $url = html_entity_decode(rawurldecode($url), ENT_QUOTES);
$data = []; $data = [];
$labels = [];
$loop = 0; $loop = 0;
define('NUM_PIECES_PIE', 6); define('NUM_PIECES_PIE', 6);
@ -3223,7 +3224,8 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr
} else { } else {
$alias = agents_get_alias($row['id_agente']); $alias = agents_get_alias($row['id_agente']);
$name = mb_substr($alias, 0, 25).' #'.$row['id_agente'].' ('.$row['count'].')'; $name = mb_substr($alias, 0, 25).' #'.$row['id_agente'].' ('.$row['count'].')';
$data[$name] = $row['count']; $labels[] = io_safe_output($name);
$data[] = $row['count'];
} }
} }
@ -3232,7 +3234,8 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr
if ($system_events > 0) { if ($system_events > 0) {
$name = __('SYSTEM').' ('.$system_events.')'; $name = __('SYSTEM').' ('.$system_events.')';
$data[$name] = $system_events; $labels[] = io_safe_output($name);
$data[] = $system_events;
} }
// Sort the data. // Sort the data.
@ -3255,6 +3258,7 @@ function grafico_eventos_grupo($width=300, $height=200, $url='', $noWaterMark=tr
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
return pie_graph( return pie_graph(
@ -3284,8 +3288,7 @@ function grafico_eventos_total($filter='', $width=320, $height=200, $noWaterMark
} }
$data = []; $data = [];
$legend = []; $labels = [];
$total = 0;
$where = 'WHERE 1=1'; $where = 'WHERE 1=1';
if (!users_is_admin()) { if (!users_is_admin()) {
@ -3312,37 +3315,44 @@ function grafico_eventos_total($filter='', $width=320, $height=200, $noWaterMark
foreach ($criticities as $cr) { foreach ($criticities as $cr) {
switch ($cr['criticity']) { switch ($cr['criticity']) {
case EVENT_CRIT_MAINTENANCE: case EVENT_CRIT_MAINTENANCE:
$data[__('Maintenance').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Maintenance').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Maintenance')] = COL_MAINTENANCE; $colors[__('Maintenance')] = COL_MAINTENANCE;
break; break;
case EVENT_CRIT_INFORMATIONAL: case EVENT_CRIT_INFORMATIONAL:
$data[__('Informational').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Informational').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Informational')] = COL_INFORMATIONAL; $colors[__('Informational')] = COL_INFORMATIONAL;
break; break;
case EVENT_CRIT_NORMAL: case EVENT_CRIT_NORMAL:
$data[__('Normal').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Normal').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Normal')] = COL_NORMAL; $colors[__('Normal')] = COL_NORMAL;
break; break;
case EVENT_CRIT_MINOR: case EVENT_CRIT_MINOR:
$data[__('Minor').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Minor').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Minor')] = COL_MINOR; $colors[__('Minor')] = COL_MINOR;
break; break;
case EVENT_CRIT_WARNING: case EVENT_CRIT_WARNING:
$data[__('Warning').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Warning').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Warning')] = COL_WARNING; $colors[__('Warning')] = COL_WARNING;
break; break;
case EVENT_CRIT_MAJOR: case EVENT_CRIT_MAJOR:
$data[__('Major').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Major').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Major')] = COL_MAJOR; $colors[__('Major')] = COL_MAJOR;
break; break;
case EVENT_CRIT_CRITICAL: case EVENT_CRIT_CRITICAL:
$data[__('Critical').' ('.$cr['events'].')'] = $cr['events']; $labels[] = __('Critical').' ('.$cr['events'].')';
$data[] = $cr['events'];
$colors[__('Critical')] = COL_CRITICAL; $colors[__('Critical')] = COL_CRITICAL;
break; break;
@ -3370,6 +3380,7 @@ function grafico_eventos_total($filter='', $width=320, $height=200, $noWaterMark
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
return pie_graph( return pie_graph(
@ -3479,7 +3490,9 @@ function graph_custom_sql_graph(
} }
$data = []; $data = [];
$labels = [];
$count = 0; $count = 0;
$other = 0;
foreach ($data_result as $data_item) { foreach ($data_result as $data_item) {
$count++; $count++;
$value = 0; $value = 0;
@ -3501,18 +3514,52 @@ function graph_custom_sql_graph(
} }
} }
if ((int) $ttl === 2 && $type === 'sql_graph_pie') { $labels_bar[] = $label;
$data[$label.'_'.$count.' ('.$value.')'] = $value; if ($type === 'sql_graph_hbar') {
$data_bar[] = [
'y' => $label,
'x' => $value,
];
} else { } else {
$data[$label.'_'.$count] = $value; $data_bar[] = [
} 'x' => $label,
} else { 'y' => $value,
if (isset($data[__('Other')]) === false) { ];
$data[__('Other')] = 0;
} }
$data[__('Other')] += $value; if ((int) $ttl === 2 && $type === 'sql_graph_pie') {
$labels_pie[] = $label.'_'.$count.' ('.$value.')';
} else {
$labels_pie[] = $label.'_'.$count;
} }
$data_pie[] = $value;
} else {
$other += $value;
}
}
if (empty($other) === false) {
$label = __('Other');
$labels_bar[] = $label;
if ($type === 'sql_graph_hbar') {
$data_bar[] = [
'y' => $label,
'x' => $other,
];
} else {
$data_bar[] = [
'x' => $label,
'y' => $other,
];
}
if ((int) $ttl === 2 && $type === 'sql_graph_pie') {
$label .= ' ('.$other.')';
}
$labels_pie[] = $label;
$data_pie[] = $other;
} }
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
@ -3550,6 +3597,7 @@ function graph_custom_sql_graph(
'grid' => ['display' => false], 'grid' => ['display' => false],
], ],
], ],
'labels' => $labels_bar,
]; ];
if ($type === 'sql_graph_hbar') { if ($type === 'sql_graph_hbar') {
@ -3561,7 +3609,7 @@ function graph_custom_sql_graph(
} }
$output .= vbar_graph( $output .= vbar_graph(
$data, $data_bar,
$options $options
); );
break; break;
@ -3576,6 +3624,7 @@ function graph_custom_sql_graph(
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels_pie,
]; ];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
@ -3590,7 +3639,7 @@ function graph_custom_sql_graph(
// Pie. // Pie.
$output .= pie_graph( $output .= pie_graph(
$data, $data_pie,
$options $options
); );
break; break;
@ -4500,6 +4549,9 @@ function graph_netflow_aggregate_pie($data, $aggregate, $ttl=1, $only_image=fals
$i++; $i++;
} }
$labels = array_keys($values);
$values = array_values($values);
if ($config['fixed_graph'] == false) { if ($config['fixed_graph'] == false) {
$water_mark = [ $water_mark = [
'file' => $config['homedir'].'/images/logo_vertical_water.png', 'file' => $config['homedir'].'/images/logo_vertical_water.png',
@ -4516,6 +4568,7 @@ function graph_netflow_aggregate_pie($data, $aggregate, $ttl=1, $only_image=fals
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$output = ''; $output = '';

View File

@ -1781,7 +1781,9 @@ function reporting_event_top_n(
if ($order_uptodown == 1 || $order_uptodown == 2) { if ($order_uptodown == 1 || $order_uptodown == 2) {
$i = 0; $i = 0;
$data_pie_graph = []; $labels_pie = [];
$labels_hbar = [];
$data_pie = [];
$data_hbar = []; $data_hbar = [];
foreach ($data_top as $key_dt => $dt) { foreach ($data_top as $key_dt => $dt) {
$item_name = ui_print_truncate_text( $item_name = ui_print_truncate_text(
@ -1802,28 +1804,14 @@ function reporting_event_top_n(
'...' '...'
); );
$item_name_key_pie = $item_name; $labels_hbar[] = io_safe_output($item_name);
$exist_key = true; $data_hbar[] = [
while ($exist_key) { 'y' => io_safe_output($item_name),
if (isset($data_pie_graph[$item_name_key_pie])) { 'x' => $dt,
$item_name_key_pie .= ' '; ];
} else {
$exist_key = false;
}
}
$item_name_key_hbar = $item_name; $labels_pie[] = io_safe_output($item_name);
$exist_key = true; $data_pie[] = $dt;
while ($exist_key) {
if (isset($data_hbar[$item_name_key_hbar])) {
$item_name_key_hbar = ' '.$item_name_key_hbar;
} else {
$exist_key = false;
}
}
$data_hbar[$item_name]['g'] = $dt;
$data_pie_graph[$item_name] = $dt;
if ($show_graph == 0 || $show_graph == 1) { if ($show_graph == 0 || $show_graph == 1) {
$data = []; $data = [];
@ -1862,7 +1850,9 @@ function reporting_event_top_n(
} }
} else if ($order_uptodown == 0 || $order_uptodown == 3) { } else if ($order_uptodown == 0 || $order_uptodown == 3) {
$i = 0; $i = 0;
$data_pie_graph = []; $labels_pie = [];
$labels_hbar = [];
$data_pie = [];
$data_hbar = []; $data_hbar = [];
foreach ($agent_name as $key_an => $an) { foreach ($agent_name as $key_an => $an) {
$item_name = ''; $item_name = '';
@ -1882,16 +1872,6 @@ function reporting_event_top_n(
'...' '...'
); );
$item_name_key_pie = $item_name;
$exist_key = true;
while ($exist_key) {
if (isset($data_pie_graph[$item_name_key_pie])) {
$item_name_key_pie .= ' ';
} else {
$exist_key = false;
}
}
$item_name_key_hbar = $item_name; $item_name_key_hbar = $item_name;
$exist_key = true; $exist_key = true;
while ($exist_key) { while ($exist_key) {
@ -1902,14 +1882,18 @@ function reporting_event_top_n(
} }
} }
$data_hbar[io_safe_output($item_name)] = $data_top[$key_an]; $labels_hbar[] = io_safe_output($item_name);
$data_hbar[] = [
'y' => io_safe_output($item_name),
'x' => $data_top[$key_an],
];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
$data_top[$key_an] = (empty($data_top[$key_an]) === false) ? $data_top[$key_an] : 0; $data_top[$key_an] = (empty($data_top[$key_an]) === false) ? $data_top[$key_an] : 0;
$item_name .= ' ('.$data_top[$key_an].')'; $item_name .= ' ('.$data_top[$key_an].')';
} }
$data_pie_graph[$item_name] = $data_top[$key_an]; $labels_pie[] = io_safe_output($item_name);
$data_pie[] = $data_top[$key_an];
$divisor = get_data_multiplier($units[$key_an]); $divisor = get_data_multiplier($units[$key_an]);
@ -1958,6 +1942,7 @@ function reporting_event_top_n(
'align' => 'center', 'align' => 'center',
], ],
'ttl' => $ttl, 'ttl' => $ttl,
'labels' => $labels_pie,
]; ];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
@ -1970,24 +1955,22 @@ function reporting_event_top_n(
]; ];
} }
if ((int) $ttl === 2) {
$return['charts']['pie'] = '<img src="data:image/png;base64,';
} else {
$return['charts']['pie'] = '<div style="margin: 0 auto; width:'.$width.'px;">'; $return['charts']['pie'] = '<div style="margin: 0 auto; width:'.$width.'px;">';
if ((int) $ttl === 2) {
$return['charts']['pie'] .= '<img src="data:image/png;base64,';
} }
arsort($data_pie_graph);
$return['charts']['pie'] .= pie_graph( $return['charts']['pie'] .= pie_graph(
$data_pie_graph, $data_pie,
$options_charts $options_charts
); );
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
$return['charts']['pie'] .= '" />'; $return['charts']['pie'] .= '" />';
} else {
$return['charts']['pie'] .= '</div>';
} }
$return['charts']['pie'] .= '</div>';
$options = [ $options = [
'height' => (count($data_hbar) * 30), 'height' => (count($data_hbar) * 30),
'ttl' => $ttl, 'ttl' => $ttl,
@ -2001,6 +1984,7 @@ function reporting_event_top_n(
'grid' => ['display' => false], 'grid' => ['display' => false],
], ],
], ],
'labels' => $labels_hbar,
]; ];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
@ -2010,10 +1994,9 @@ function reporting_event_top_n(
]; ];
} }
if ((int) $ttl === 2) {
$return['charts']['bars'] = '<img src="data:image/png;base64,';
} else {
$return['charts']['bars'] = '<div style="margin: 0 auto; width:'.$width.'px;">'; $return['charts']['bars'] = '<div style="margin: 0 auto; width:'.$width.'px;">';
if ((int) $ttl === 2) {
$return['charts']['bars'] .= '<img src="data:image/png;base64,';
} }
$return['charts']['bars'] .= vbar_graph( $return['charts']['bars'] .= vbar_graph(
@ -2023,9 +2006,9 @@ function reporting_event_top_n(
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
$return['charts']['bars'] .= '" />'; $return['charts']['bars'] .= '" />';
} else {
$return['charts']['bars'] .= '</div>';
} }
$return['charts']['bars'] .= '</div>';
} }
$return['resume'] = null; $return['resume'] = null;
@ -2256,6 +2239,8 @@ function reporting_event_report_group(
$k = '('.$value['server_name'].') '.$value['alias']; $k = '('.$value['server_name'].') '.$value['alias'];
} }
$k = io_safe_output($k);
if (isset($data_graph_by_agent[$k]) === true) { if (isset($data_graph_by_agent[$k]) === true) {
$data_graph_by_agent[$k]++; $data_graph_by_agent[$k]++;
} else { } else {
@ -2279,8 +2264,9 @@ function reporting_event_report_group(
$return['chart']['by_agent'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['by_agent'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_agent);
$return['chart']['by_agent'] .= pie_graph( $return['chart']['by_agent'] .= pie_graph(
$data_graph_by_agent, array_values($data_graph_by_agent),
$options_charts $options_charts
); );
@ -2308,8 +2294,9 @@ function reporting_event_report_group(
$return['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_user);
$return['chart']['by_user_validator'] .= pie_graph( $return['chart']['by_user_validator'] .= pie_graph(
$data_graph_by_user, array_values($data_graph_by_user),
$options_charts $options_charts
); );
@ -2324,7 +2311,7 @@ function reporting_event_report_group(
$data_graph_by_criticity = []; $data_graph_by_criticity = [];
if (empty($data) === false) { if (empty($data) === false) {
foreach ($data as $value) { foreach ($data as $value) {
$k = get_priority_name($value['criticity']); $k = io_safe_output(get_priority_name($value['criticity']));
if (isset($data_graph_by_criticity[$k]) === true) { if (isset($data_graph_by_criticity[$k]) === true) {
$data_graph_by_criticity[$k]++; $data_graph_by_criticity[$k]++;
} else { } else {
@ -2351,8 +2338,9 @@ function reporting_event_report_group(
$return['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_criticity);
$return['chart']['by_criticity'] .= pie_graph( $return['chart']['by_criticity'] .= pie_graph(
$data_graph_by_criticity, array_values($data_graph_by_criticity),
$options_charts $options_charts
); );
@ -2397,8 +2385,9 @@ function reporting_event_report_group(
$return['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_status);
$return['chart']['validated_vs_unvalidated'] .= pie_graph( $return['chart']['validated_vs_unvalidated'] .= pie_graph(
$data_graph_by_status, array_values($data_graph_by_status),
$options_charts $options_charts
); );
@ -3927,18 +3916,32 @@ function reporting_exception(
$ttl $ttl
); );
$data_pie_graph = []; $data_pie = [];
$labels_pie = [];
$data_hbar = []; $data_hbar = [];
$labels_hbar = [];
$other = 0;
foreach ($items as $key => $item) { foreach ($items as $key => $item) {
if ($show_graph == 1 || $show_graph == 2) { if ($show_graph == 1 || $show_graph == 2) {
if ($key <= 10) {
$label = $item['agent'].' - '.$item['operation']; $label = $item['agent'].' - '.$item['operation'];
$data_hbar[io_safe_output($label)] = $item['value']; $labels_hbar[] = io_safe_output($label);
$data_hbar[] = [
'x' => $item['value'],
'y' => io_safe_output($label),
];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
$item['value'] = (empty($item['value']) === false) ? $item['value'] : 0; $item['value'] = (empty($item['value']) === false) ? $item['value'] : 0;
$label .= ' ('.$item['value'].')'; $label .= ' ('.$item['value'].')';
} }
$data_pie_graph[$label] = $item['value']; $labels_pie[] = io_safe_output($label);
$data_pie[] = $item['value'];
} else {
$other += $item['value'];
}
} }
if ($show_graph == 0 || $show_graph == 1) { if ($show_graph == 0 || $show_graph == 1) {
@ -3952,6 +3955,22 @@ function reporting_exception(
} }
} }
if (empty($other) === false) {
$label = __('Others');
$labels_hbar[] = $label;
$data_hbar[] = [
'x' => $other,
'y' => $label,
];
if ((int) $ttl === 2) {
$label .= ' ('.$other.')';
}
$labels_pie[] = $label;
$data_pie[] = $other;
}
if (!empty($force_width_chart)) { if (!empty($force_width_chart)) {
$width = $force_width_chart; $width = $force_width_chart;
} }
@ -3967,6 +3986,7 @@ function reporting_exception(
'align' => 'center', 'align' => 'center',
], ],
'ttl' => $ttl, 'ttl' => $ttl,
'labels' => $labels_pie,
]; ];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
@ -3985,9 +4005,8 @@ function reporting_exception(
$return['chart']['pie'] = '<div style="margin: 0 auto; width:600px;">'; $return['chart']['pie'] = '<div style="margin: 0 auto; width:600px;">';
} }
arsort($data_pie_graph);
$return['chart']['pie'] .= pie_graph( $return['chart']['pie'] .= pie_graph(
$data_pie_graph, $data_pie,
$options_charts $options_charts
); );
@ -4016,6 +4035,7 @@ function reporting_exception(
'grid' => ['display' => false], 'grid' => ['display' => false],
], ],
], ],
'labels' => $labels_hbar,
]; ];
if ((int) $ttl === 2) { if ((int) $ttl === 2) {
@ -4406,8 +4426,9 @@ function reporting_event_report_agent(
$return['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_user);
$return['chart']['by_user_validator'] .= pie_graph( $return['chart']['by_user_validator'] .= pie_graph(
$data_graph_by_user, array_values($data_graph_by_user),
$options_charts $options_charts
); );
@ -4422,7 +4443,7 @@ function reporting_event_report_agent(
$data_graph_by_criticity = []; $data_graph_by_criticity = [];
if (empty($return['data']) === false) { if (empty($return['data']) === false) {
foreach ($return['data'] as $value) { foreach ($return['data'] as $value) {
$k = get_priority_name($value['criticity']); $k = io_safe_output(get_priority_name($value['criticity']));
if (isset($data_graph_by_criticity[$k]) === true) { if (isset($data_graph_by_criticity[$k]) === true) {
$data_graph_by_criticity[$k]++; $data_graph_by_criticity[$k]++;
} else { } else {
@ -4449,8 +4470,9 @@ function reporting_event_report_agent(
$return['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_criticity);
$return['chart']['by_criticity'] .= pie_graph( $return['chart']['by_criticity'] .= pie_graph(
$data_graph_by_criticity, array_values($data_graph_by_criticity),
$options_charts $options_charts
); );
@ -4495,8 +4517,9 @@ function reporting_event_report_agent(
$return['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $return['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_status);
$return['chart']['validated_vs_unvalidated'] .= pie_graph( $return['chart']['validated_vs_unvalidated'] .= pie_graph(
$data_graph_by_status, array_values($data_graph_by_status),
$options_charts $options_charts
); );
@ -5401,11 +5424,13 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
$data_query, $data_query,
function ($carry, $item) use ($pdf) { function ($carry, $item) use ($pdf) {
if ($pdf === true) { if ($pdf === true) {
$carry[$item['label'].' ('.$item['value'].')'] = $item['value']; $carry['labels'][] = io_safe_output($item['label']).' ('.$item['value'].')';
} else { } else {
$carry[$item['label']] = $item['value']; $carry['labels'][] = io_safe_output($item['label']);
} }
$carry['data'][] = $item['value'];
return $carry; return $carry;
}, },
[] []
@ -5416,8 +5441,9 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
$value_query .= '<img src="data:image/png;base64,'; $value_query .= '<img src="data:image/png;base64,';
} }
$options['labels'] = $data['labels'];
$value_query .= pie_graph( $value_query .= pie_graph(
$data, $data['data'],
$options $options
); );
@ -11100,8 +11126,9 @@ function reporting_get_module_detailed_event(
$event['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $event['chart']['by_user_validator'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_user);
$event['chart']['by_user_validator'] .= pie_graph( $event['chart']['by_user_validator'] .= pie_graph(
$data_graph_by_user, array_values($data_graph_by_user),
$options_charts $options_charts
); );
@ -11116,7 +11143,7 @@ function reporting_get_module_detailed_event(
$data_graph_by_criticity = []; $data_graph_by_criticity = [];
if (empty($event['data']) === false) { if (empty($event['data']) === false) {
foreach ($event['data'] as $value) { foreach ($event['data'] as $value) {
$k = get_priority_name($value['criticity']); $k = io_safe_output(get_priority_name($value['criticity']));
if (isset($data_graph_by_criticity[$k]) === true) { if (isset($data_graph_by_criticity[$k]) === true) {
$data_graph_by_criticity[$k]++; $data_graph_by_criticity[$k]++;
} else { } else {
@ -11143,8 +11170,9 @@ function reporting_get_module_detailed_event(
$event['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $event['chart']['by_criticity'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_criticity);
$event['chart']['by_criticity'] .= pie_graph( $event['chart']['by_criticity'] .= pie_graph(
$data_graph_by_criticity, array_values($data_graph_by_criticity),
$options_charts $options_charts
); );
@ -11189,8 +11217,9 @@ function reporting_get_module_detailed_event(
$event['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">'; $event['chart']['validated_vs_unvalidated'] = '<div style="margin: 0 auto; width:'.$options_charts['width'].'px;">';
} }
$options_charts['labels'] = array_keys($data_graph_by_status);
$event['chart']['validated_vs_unvalidated'] .= pie_graph( $event['chart']['validated_vs_unvalidated'] .= pie_graph(
$data_graph_by_status, array_values($data_graph_by_status),
$options_charts $options_charts
); );

View File

@ -1227,7 +1227,7 @@ function visual_map_print_item(
$module_data = get_bars_module_data( $module_data = get_bars_module_data(
$id_module, $id_module,
($layoutData['type_graph'] !== 'horizontal') $layoutData['type_graph']
); );
$options = []; $options = [];
$options['generals']['rotate'] = true; $options['generals']['rotate'] = true;
@ -2344,7 +2344,7 @@ function get_if_module_is_image($id_module)
} }
function get_bars_module_data($id_module) function get_bars_module_data($id_module, $typeGraph='horizontal')
{ {
// This charts is only serialize graphs. // This charts is only serialize graphs.
// In other string show image no data to show. // In other string show image no data to show.
@ -2364,18 +2364,25 @@ function get_bars_module_data($id_module)
} }
} }
$values_to_return = [];
$index = 0;
$color_index = 0;
$total = 0;
if (!$values) { if (!$values) {
return false; return false;
} }
$values_to_return = [];
foreach ($values as $val) { foreach ($values as $val) {
$data = explode(',', $val); $data = explode(',', $val);
$values_to_return[$data[0]] = $data[1]; $values_to_return['labels'][] = io_safe_output($data[0]);
if ($typeGraph === 'horizontal') {
$values_to_return['data'][] = [
'y' => io_safe_output($data[0]),
'x' => $data[1],
];
} else {
$values_to_return['data'][] = [
'x' => io_safe_output($data[0]),
'y' => $data[1],
];
}
} }
return $values_to_return; return $values_to_return;

View File

@ -398,36 +398,33 @@ function pie_graph(
return graph_nodata_image($options); return graph_nodata_image($options);
} }
// Remove the html_entities.
$temp = [];
foreach ($chart_data as $key => $value) {
$temp[io_safe_output($key)] = $value;
}
$chart_data = $temp;
// Number max elements. // Number max elements.
$max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 9; $max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 15;
if (count($chart_data) > $max_values) { if (count($chart_data) > $max_values) {
$others_str = (isset($options['otherStr']) === true) ? $options['otherStr'] : __('Others'); $others_str = (isset($options['otherStr']) === true) ? $options['otherStr'] : __('Others');
$chart_data_trunc = []; $chart_data_trunc = [];
$n = 1; $n = 1;
foreach ($chart_data as $key => $value) { foreach ($chart_data as $key => $value) {
if ($n < $max_values) { if ($n <= $max_values) {
$chart_data_trunc[$key] = $value; $chart_data_trunc[$key] = $value;
} else { } else {
if (isset($chart_data_trunc[$others_str]) === true) { if (isset($options['labels'][$key]) === true) {
unset($options['labels'][$key]);
}
if (isset($chart_data_trunc[$others_str]) === false) {
$chart_data_trunc[$others_str] = 0; $chart_data_trunc[$others_str] = 0;
} }
if (empty($value) === false) { if (empty($value) === false) {
$chart_data_trunc[$others_str] += $value; $chart_data_trunc[$others_str] += (float) $value;
} }
} }
$n++; $n++;
} }
$options['labels'][$max_values] = $others_str;
$chart_data = $chart_data_trunc; $chart_data = $chart_data_trunc;
} }
@ -804,7 +801,27 @@ function get_build_setup_charts($type, $options, $data)
$dataLabel->setOffset($dataLabelOffset); $dataLabel->setOffset($dataLabelOffset);
switch ($type) {
case 'DOUGHNUT':
case 'PIE':
$dataLabelFormatter = 'formatterDataLabelPie'; $dataLabelFormatter = 'formatterDataLabelPie';
break;
case 'BAR':
if (isset($options['axis']) === true
&& empty($options['axis']) === false
) {
$dataLabelFormatter = 'formatterDataHorizontalBar';
} else {
$dataLabelFormatter = 'formatterDataVerticalBar';
}
break;
default:
// Not possible.
break;
}
if (isset($options['dataLabel']['formatter']) === true) { if (isset($options['dataLabel']['formatter']) === true) {
$dataLabelFormatter = $options['dataLabel']['formatter']; $dataLabelFormatter = $options['dataLabel']['formatter'];
} }
@ -1047,7 +1064,12 @@ function get_build_setup_charts($type, $options, $data)
} }
// Set labels. // Set labels.
$chart->labels()->exchangeArray(array_keys($data)); if (isset($options['labels']) === true
&& empty($options['labels']) === false
&& is_array($options['labels']) === true
) {
$chart->labels()->exchangeArray($options['labels']);
}
// Add Datasets. // Add Datasets.
$setData = $chart->createDataSet(); $setData = $chart->createDataSet();

View File

@ -2202,10 +2202,41 @@ function loadPasswordConfig(id, value) {
var formatterDataLabelPie = function(value, ctx) { var formatterDataLabelPie = function(value, ctx) {
let datasets = ctx.chart.data.datasets; let datasets = ctx.chart.data.datasets;
console.log(datasets[0].data);
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) { if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce((a, b) => parseInt(a) + parseInt(b), 0); let sum = datasets[0].data.reduce((a, b) => parseInt(a) + parseInt(b), 0);
let percentage = ((value * 100) / sum).toFixed(1) + "%"; let percentage = ((value * 100) / sum).toFixed(1) + "%";
return percentage; return percentage;
} }
}; };
var formatterDataHorizontalBar = function(value, ctx) {
let datasets = ctx.chart.data.datasets;
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce(
(a, b) => {
if (a != undefined && b != undefined) {
return { x: parseInt(a.x) + parseInt(b.x) };
}
},
{ x: 0 }
);
let percentage = ((value.x * 100) / sum.x).toFixed(1) + "%";
return percentage;
}
};
var formatterDataVerticalBar = function(value, ctx) {
let datasets = ctx.chart.data.datasets;
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce(
(a, b) => {
if (a != undefined && b != undefined) {
return { y: parseInt(a.y) + parseInt(b.y) };
}
},
{ y: 0 }
);
let percentage = ((value.y * 100) / sum.y).toFixed(1) + "%";
return percentage;
}
};

View File

@ -444,7 +444,7 @@ class TopNWidget extends Widget
metaconsole_restore_db(); metaconsole_restore_db();
} }
} else { } else {
$modules = @db_get_all_rows_sql( $modules = db_get_all_rows_sql(
$sql, $sql,
$search_in_history_db $search_in_history_db
); );
@ -462,6 +462,7 @@ class TopNWidget extends Widget
} }
$data_hbar = []; $data_hbar = [];
$labels = [];
$valueMax = 0; $valueMax = 0;
$valueMin = 0; $valueMin = 0;
$booleanModulesCount = 0; $booleanModulesCount = 0;
@ -476,7 +477,12 @@ class TopNWidget extends Widget
foreach ($modules as $module) { foreach ($modules as $module) {
$module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20, false, true, false); $module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20, false, true, false);
$item_name = $module['aliasAgent'].' - '.$module['nameModule']; $item_name = $module['aliasAgent'].' - '.$module['nameModule'];
$data_hbar[io_safe_output($item_name)] = $module[$display]; $labels[] = io_safe_output($item_name);
$data_hbar[] = [
'x' => $module[$display],
'y' => io_safe_output($item_name),
];
// Calculation of max-min values for show in graph. // Calculation of max-min values for show in graph.
$calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]); $calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]);
// Set of max-min values for graph. // Set of max-min values for graph.
@ -510,6 +516,7 @@ class TopNWidget extends Widget
'grid' => ['display' => false], 'grid' => ['display' => false],
], ],
], ],
'labels' => $labels,
]; ];
$output .= vbar_graph( $output .= vbar_graph(

View File

@ -424,6 +424,7 @@ class TopNEventByGroupWidget extends Widget
return $output; return $output;
} else { } else {
$data_pie = []; $data_pie = [];
$labels = [];
foreach ($result as $row) { foreach ($result as $row) {
if ($row['id_agente'] == 0) { if ($row['id_agente'] == 0) {
$name = __('System'); $name = __('System');
@ -444,7 +445,8 @@ class TopNEventByGroupWidget extends Widget
$name .= ' ('.$row['count'].')'; $name .= ' ('.$row['count'].')';
$data_pie[$name] = $row['count']; $labels[] = io_safe_output($name);
$data_pie[] = $row['count'];
} }
} }
@ -480,6 +482,7 @@ class TopNEventByGroupWidget extends Widget
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
] ]
); );
} }

View File

@ -427,6 +427,7 @@ class TopNEventByModuleWidget extends Widget
$output .= '</div>'; $output .= '</div>';
return $output; return $output;
} else { } else {
$labels = [];
$data_pie = []; $data_pie = [];
foreach ($result as $row) { foreach ($result as $row) {
if ($row['id_agentmodule'] == 0) { if ($row['id_agentmodule'] == 0) {
@ -479,7 +480,8 @@ class TopNEventByModuleWidget extends Widget
); );
} }
$data_pie[$event_name.' [ '.$name.' ] ('.$row['count'].')'] = $row['count']; $labels[] = $event_name.' [ '.$name.' ] ('.$row['count'].')';
$data_pie[] = $row['count'];
} }
} }
@ -515,6 +517,7 @@ class TopNEventByModuleWidget extends Widget
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
] ]
); );
} }

View File

@ -241,9 +241,10 @@ final class BarsGraph extends Item
} }
} }
$moduleData = \get_bars_module_data($moduleId); $moduleData = \get_bars_module_data($moduleId, $typeGraph);
if ($moduleData !== false && is_array($moduleData) === true) { if ($moduleData !== false && is_array($moduleData) === true) {
array_pop($moduleData); array_pop($moduleData['labels']);
array_pop($moduleData['data']);
} }
$waterMark = [ $waterMark = [
@ -286,7 +287,6 @@ final class BarsGraph extends Item
$options = [ $options = [
'width' => $width, 'width' => $width,
'height' => $height, 'height' => $height,
'background' => $backGroundColor,
'waterMark' => $waterMark, 'waterMark' => $waterMark,
'legend' => ['display' => false], 'legend' => ['display' => false],
'scales' => [ 'scales' => [
@ -309,13 +309,14 @@ final class BarsGraph extends Item
], ],
], ],
], ],
'labels' => $moduleData['labels'],
]; ];
if ($typeGraph === 'horizontal') { if ($typeGraph === 'horizontal') {
$options['axis'] = 'y'; $options['axis'] = 'y';
} }
$graph = vbar_graph($moduleData, $options); $graph = vbar_graph($moduleData['data'], $options);
} }
// Restore connection. // Restore connection.

View File

@ -269,6 +269,7 @@ if (!empty($main_value)) {
// Print the data and build the chart. // Print the data and build the chart.
$table->data = []; $table->data = [];
$chart_data = []; $chart_data = [];
$labels = [];
$hide_filter = !empty($main_value) && ($action === 'udp' || $action === 'tcp'); $hide_filter = !empty($main_value) && ($action === 'udp' || $action === 'tcp');
foreach ($data as $item) { foreach ($data as $item) {
$row = []; $row = [];
@ -294,19 +295,20 @@ foreach ($data as $item) {
$table->data[] = $row; $table->data[] = $row;
$labels[] = io_safe_output($item['host']);
// Build the pie graph data structure. // Build the pie graph data structure.
switch ($order_by) { switch ($order_by) {
case 'pkts': case 'pkts':
$chart_data[$item['host']] = $item['sum_bytes']; $chart_data[] = $item['sum_bytes'];
break; break;
case 'flows': case 'flows':
$chart_data[$item['host']] = $item['sum_flows']; $chart_data[] = $item['sum_flows'];
break; break;
case 'bytes': case 'bytes':
default: default:
$chart_data[$item['host']] = $item['sum_bytes']; $chart_data[] = $item['sum_bytes'];
break; break;
} }
} }
@ -324,6 +326,7 @@ if (empty($data)) {
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
// Print the graph. // Print the graph.

View File

@ -184,7 +184,7 @@ $table_source_data->head['num'] = __('Number');
$table_source_data->data = []; $table_source_data->data = [];
$table_source_graph_data = []; $table_source_graph_data = [];
$labels = [];
foreach ($traps_generated_by_source as $trap) { foreach ($traps_generated_by_source as $trap) {
$row = []; $row = [];
@ -202,7 +202,8 @@ foreach ($traps_generated_by_source as $trap) {
$table_source_data->data[] = $row; $table_source_data->data[] = $row;
$table_source_graph_data[$trap['source']] = (int) $trap['num']; $labels[] = io_safe_output($trap['source']);
$table_source_graph_data[] = (int) $trap['num'];
} }
$table_source_row['table'] = html_print_table($table_source_data, true); $table_source_row['table'] = html_print_table($table_source_data, true);
@ -219,6 +220,7 @@ if (empty($table_source_graph_data)) {
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$table_source_graph = pie_graph( $table_source_graph = pie_graph(
@ -255,14 +257,14 @@ $table_oid_data->head['num'] = __('Number');
$table_oid_data->data = []; $table_oid_data->data = [];
$table_oid_graph_data = []; $table_oid_graph_data = [];
$labels = [];
foreach ($traps_generated_by_oid as $trap) { foreach ($traps_generated_by_oid as $trap) {
$table_oid_data->data[] = [ $table_oid_data->data[] = [
'oid' => $trap['oid'], 'oid' => $trap['oid'],
'num' => (int) $trap['num'], 'num' => (int) $trap['num'],
]; ];
$labels[] = io_safe_output($trap['oid']);
$table_oid_graph_data[$trap['oid']] = (int) $trap['num']; $table_oid_graph_data[] = (int) $trap['num'];
} }
$table_oid_row['table'] = html_print_table($table_oid_data, true); $table_oid_row['table'] = html_print_table($table_oid_data, true);
@ -279,6 +281,7 @@ if (empty($table_oid_graph_data)) {
'position' => 'right', 'position' => 'right',
'align' => 'center', 'align' => 'center',
], ],
'labels' => $labels,
]; ];
$table_oid_graph = pie_graph( $table_oid_graph = pie_graph(