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) {
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']]);
}
}

View File

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

View File

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

View File

@ -1227,7 +1227,7 @@ function visual_map_print_item(
$module_data = get_bars_module_data(
$id_module,
($layoutData['type_graph'] !== 'horizontal')
$layoutData['type_graph']
);
$options = [];
$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.
// 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) {
return false;
}
$values_to_return = [];
foreach ($values as $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;

View File

@ -398,36 +398,33 @@ function pie_graph(
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.
$max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 9;
$max_values = (isset($options['maxValues']) === true) ? $options['maxValues'] : 15;
if (count($chart_data) > $max_values) {
$others_str = (isset($options['otherStr']) === true) ? $options['otherStr'] : __('Others');
$chart_data_trunc = [];
$n = 1;
foreach ($chart_data as $key => $value) {
if ($n < $max_values) {
if ($n <= $max_values) {
$chart_data_trunc[$key] = $value;
} 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;
}
if (empty($value) === false) {
$chart_data_trunc[$others_str] += $value;
$chart_data_trunc[$others_str] += (float) $value;
}
}
$n++;
}
$options['labels'][$max_values] = $others_str;
$chart_data = $chart_data_trunc;
}
@ -804,7 +801,27 @@ function get_build_setup_charts($type, $options, $data)
$dataLabel->setOffset($dataLabelOffset);
$dataLabelFormatter = 'formatterDataLabelPie';
switch ($type) {
case 'DOUGHNUT':
case 'PIE':
$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) {
$dataLabelFormatter = $options['dataLabel']['formatter'];
}
@ -1047,7 +1064,12 @@ function get_build_setup_charts($type, $options, $data)
}
// 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.
$setData = $chart->createDataSet();

View File

@ -2202,10 +2202,41 @@ function loadPasswordConfig(id, value) {
var formatterDataLabelPie = function(value, ctx) {
let datasets = ctx.chart.data.datasets;
console.log(datasets[0].data);
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce((a, b) => parseInt(a) + parseInt(b), 0);
let percentage = ((value * 100) / sum).toFixed(1) + "%";
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();
}
} else {
$modules = @db_get_all_rows_sql(
$modules = db_get_all_rows_sql(
$sql,
$search_in_history_db
);
@ -462,6 +462,7 @@ class TopNWidget extends Widget
}
$data_hbar = [];
$labels = [];
$valueMax = 0;
$valueMin = 0;
$booleanModulesCount = 0;
@ -476,7 +477,12 @@ class TopNWidget extends Widget
foreach ($modules as $module) {
$module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20, false, true, false);
$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.
$calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]);
// Set of max-min values for graph.
@ -510,6 +516,7 @@ class TopNWidget extends Widget
'grid' => ['display' => false],
],
],
'labels' => $labels,
];
$output .= vbar_graph(

View File

@ -424,6 +424,7 @@ class TopNEventByGroupWidget extends Widget
return $output;
} else {
$data_pie = [];
$labels = [];
foreach ($result as $row) {
if ($row['id_agente'] == 0) {
$name = __('System');
@ -444,7 +445,8 @@ class TopNEventByGroupWidget extends Widget
$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',
'align' => 'center',
],
'labels' => $labels,
]
);
}

View File

@ -427,6 +427,7 @@ class TopNEventByModuleWidget extends Widget
$output .= '</div>';
return $output;
} else {
$labels = [];
$data_pie = [];
foreach ($result as $row) {
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',
'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) {
array_pop($moduleData);
array_pop($moduleData['labels']);
array_pop($moduleData['data']);
}
$waterMark = [
@ -284,12 +285,11 @@ final class BarsGraph extends Item
}
$options = [
'width' => $width,
'height' => $height,
'background' => $backGroundColor,
'waterMark' => $waterMark,
'legend' => ['display' => false],
'scales' => [
'width' => $width,
'height' => $height,
'waterMark' => $waterMark,
'legend' => ['display' => false],
'scales' => [
'x' => [
'grid' => [
'display' => true,
@ -309,13 +309,14 @@ final class BarsGraph extends Item
],
],
],
'labels' => $moduleData['labels'],
];
if ($typeGraph === 'horizontal') {
$options['axis'] = 'y';
}
$graph = vbar_graph($moduleData, $options);
$graph = vbar_graph($moduleData['data'], $options);
}
// Restore connection.

View File

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

View File

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