(int) $agent_module_id,
"utimestamp > '".$date_array['start_date']."'",
"utimestamp < '".$date_array['final_date']."'",
'group' => "ROUND(utimestamp / $data_slice)",
'order' => 'utimestamp ASC'
],
[
'count(*) as datos',
'min(utimestamp) as utimestamp',
],
'AND',
$data_module_graph['history_db']
);
} else {
// all points(data) and boolean
if ($data_module_graph['id_module_type'] == 2
|| $data_module_graph['id_module_type'] == 6
|| $data_module_graph['id_module_type'] == 21
|| $data_module_graph['id_module_type'] == 18
|| $data_module_graph['id_module_type'] == 9
|| $data_module_graph['id_module_type'] == 31
|| $data_module_graph['id_module_type'] == 100
) {
$data = db_get_all_rows_filter(
'tagente_datos',
['id_agente_modulo' => (int) $agent_module_id,
"utimestamp > '".$date_array['start_date']."'",
"utimestamp < '".$date_array['final_date']."'",
'order' => 'utimestamp ASC'
],
[
'datos',
'utimestamp',
],
'AND',
$data_module_graph['history_db']
);
}
}
if ($data === false) {
$data = [];
}
// Get previous data.
$previous_data = modules_get_previous_data(
$agent_module_id,
$date_array['start_date']
);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $date_array['start_date'];
unset($previous_data['id_agente_modulo']);
array_unshift($data, $previous_data);
}
// Get next data.
$nextData = modules_get_next_data(
$agent_module_id,
$date_array['final_date']
);
if ($nextData !== false) {
unset($nextData['id_agente_modulo']);
array_push($data, $nextData);
} else if (count($data) > 0) {
// Propagate the last known data to the end of the interval.
$nextData = [
'datos' => $data[(count($data) - 1)]['datos'],
'utimestamp' => $date_array['final_date'],
];
array_push($data, $nextData);
}
// Check available data.
if (count($data) < 1) {
return false;
}
$array_data = [];
$min_value = (PHP_INT_MAX - 1);
$max_value = (PHP_INT_MIN + 1);
$array_percentil = [];
foreach ($data as $k => $v) {
// Convert array.
if ($params['flag_overlapped']) {
$array_data['sum'.$series_suffix]['data'][$k] = [
(($v['utimestamp'] + $date_array['period'] ) * 1000),
$v['datos'],
];
} else {
$array_data['sum'.$series_suffix]['data'][$k] = [
($v['utimestamp'] * 1000),
$v['datos'],
];
}
// Min.
if ($min_value > $v['datos']) {
$min_value = $v['datos'];
}
// Max.
if ($max_value < $v['datos']) {
$max_value = $v['datos'];
}
// Avg.
$sum_data += $v['datos'];
$count_data++;
// Percentil.
if (!isset($params['percentil']) && $params['percentil']) {
$array_percentil[] = $v['datos'];
}
}
$array_data['sum'.$series_suffix]['min'] = $min_value;
$array_data['sum'.$series_suffix]['max'] = $max_value;
$array_data['sum'.$series_suffix]['avg'] = ($sum_data / $count_data);
$array_data['sum'.$series_suffix]['agent_module_id'] = $agent_module_id;
$array_data['sum'.$series_suffix]['id_module_type'] = $data_module_graph['id_module_type'];
$array_data['sum'.$series_suffix]['agent_name'] = $data_module_graph['agent_name'];
$array_data['sum'.$series_suffix]['module_name'] = $data_module_graph['module_name'];
$array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias'];
if (!isset($params['percentil'])
&& $params['percentil']
&& !$params['flag_overlapped']
) {
$percentil_result = get_percentile(
$params['percentil'],
$array_percentil
);
$array_data['percentil'.$series_suffix]['data'][0] = [
($date_array['start_date'] * 1000),
$percentil_result,
];
$array_data['percentil'.$series_suffix]['data'][1] = [
($date_array['final_date'] * 1000),
$percentil_result,
];
$array_data['percentil'.$series_suffix]['agent_module_id'] = $agent_module_id;
}
return $array_data;
}
/**
* Prepare data for send to function js paint charts.
*
* @param integer $agent_module_id ID.
* @param array $date_array Date stasrt finish and period.
* @param array $data_module_graph Data module.
* @param array $params Params graphs.
* @param integer $series_suffix Int.
*
* @return array Prepare data to paint js.
*/
function grafico_modulo_sparse_data(
$agent_module_id,
$date_array,
$data_module_graph,
$params,
$series_suffix
) {
global $config;
global $array_events_alerts;
if ($params['fullscale']) {
$array_data = fullscale_data(
$agent_module_id,
$date_array,
$params['show_unknown'],
$params['percentil'],
$series_suffix,
$params['flag_overlapped'],
false,
$params['type_mode_graph']
);
} else {
// Uncompress data except boolean and string.
if ($data_module_graph['id_module_type'] == 23
|| $data_module_graph['id_module_type'] == 3
|| $data_module_graph['id_module_type'] == 17
|| $data_module_graph['id_module_type'] == 10
|| $data_module_graph['id_module_type'] == 33
|| $data_module_graph['id_module_type'] == 2
|| $data_module_graph['id_module_type'] == 6
|| $data_module_graph['id_module_type'] == 21
|| $data_module_graph['id_module_type'] == 18
|| $data_module_graph['id_module_type'] == 9
|| $data_module_graph['id_module_type'] == 31
|| $data_module_graph['id_module_type'] == 100
) {
$array_data = grafico_modulo_sparse_data_chart(
$agent_module_id,
$date_array,
$data_module_graph,
$params,
$series_suffix
);
} else {
$data_slice = ($date_array['period'] / (250 * $params['zoom']) + 100);
$array_data = fullscale_data(
$agent_module_id,
$date_array,
$params['show_unknown'],
$params['percentil'],
$series_suffix,
$params['flag_overlapped'],
$data_slice,
$params['type_mode_graph']
);
}
}
if (empty($array_data) === true) {
return [];
}
if ($array_data === false && (!$params['graph_combined']
&& !isset($array_data['sum1']['data'][0][1]) && !$params['baseline'])
) {
return false;
}
if ((int) $params['type_mode_graph'] !== 2
&& (int) $params['type_mode_graph'] !== 3
) {
$array_data = series_suffix_leyend(
'sum',
$series_suffix,
$agent_module_id,
$data_module_graph,
$array_data
);
}
if ($params['percentil']) {
$array_data = series_suffix_leyend(
'percentil',
$series_suffix,
$agent_module_id,
$data_module_graph,
$array_data
);
}
if ($params['type_mode_graph'] > 0) {
if ((int) $params['type_mode_graph'] === 1
|| (int) $params['type_mode_graph'] === 3
) {
$array_data = series_suffix_leyend(
'min',
$series_suffix,
$agent_module_id,
$data_module_graph,
$array_data
);
}
if ((int) $params['type_mode_graph'] === 1
|| (int) $params['type_mode_graph'] === 2
) {
$array_data = series_suffix_leyend(
'max',
$series_suffix,
$agent_module_id,
$data_module_graph,
$array_data
);
}
}
// This is for a specific type of report that consists in passing
// an interval and doing the average sum and avg.
if ($params['force_interval'] != '') {
$period_time_interval = ($date_array['period'] * 1000);
$start_period = ($date_array['start_date'] * 1000);
$i = 0;
$sum_data = 0;
$count_data = 0;
$data_last_acum = $array_data['sum1']['data'][0][1];
$array_data_only = [];
while ($period_time_interval > 0) {
foreach ($array_data['sum1']['data'] as $key => $value) {
if ($value[0] >= $start_period
&& $value[0] < ($start_period + $params['time_interval'] * 1000)
) {
$sum_data = $value[1];
$array_data_only[] = $value[1];
$count_data++;
unset($array_data['sum1']['data'][$key]);
} else {
if ($params['force_interval'] == 'max_only') {
$acum_array_data[$i][0] = $start_period;
if (is_array($array_data_only)
&& count($array_data_only) > 0
) {
$acum_array_data[$i][1] = max($array_data_only);
$data_last_acum = $array_data_only[(count($array_data_only) - 1)];
} else {
$acum_array_data[$i][1] = $data_last_acum;
}
}
if ($params['force_interval'] == 'min_only') {
$acum_array_data[$i][0] = $start_period;
if (is_array($array_data_only)
&& count($array_data_only) > 0
) {
$acum_array_data[$i][1] = min($array_data_only);
$data_last_acum = $array_data_only[(count($array_data_only) - 1)];
} else {
$acum_array_data[$i][1] = $data_last_acum;
}
}
if ($params['force_interval'] == 'avg_only') {
$acum_array_data[$i][0] = $start_period;
if (is_array($array_data_only)
&& count($array_data_only) > 0
) {
$acum_array_data[$i][1] = ($sum_data / $count_data);
} else {
$acum_array_data[$i][1] = $data_last_acum;
}
}
$start_period = ($start_period + $params['time_interval'] * 1000);
$array_data_only = [];
$sum_data = 0;
$count_data = 0;
$i++;
break;
}
}
$period_time_interval = ($period_time_interval - $params['time_interval']);
}
// Drag the last value to paint the graph correctly.
$acum_array_data[] = [
0 => $start_period,
1 => $acum_array_data[($i - 1)][1],
];
$array_data['sum1']['data'] = $acum_array_data;
}
$events = [];
if (isset($array_data['sum'.$series_suffix]['max'])) {
$max = $array_data['sum'.$series_suffix]['max'];
$min = $array_data['sum'.$series_suffix]['min'];
$avg = $array_data['sum'.$series_suffix]['avg'];
}
if (!$params['flag_overlapped']) {
if ($params['fullscale']) {
if ($params['show_unknown']
&& isset($array_data['unknown'.$series_suffix])
&& is_array($array_data['unknown'.$series_suffix]['data'])
) {
foreach ($array_data['unknown'.$series_suffix]['data'] as $key => $s_date) {
if ($s_date[1] == 1) {
$array_data['unknown'.$series_suffix]['data'][$key] = [
$s_date[0],
($max * 1.05),
];
}
}
}
} else {
if ($params['show_unknown']) {
$unknown_events = db_get_module_ranges_unknown(
$agent_module_id,
$date_array['start_date'],
$date_array['final_date'],
$data_module_graph['history_db'],
1
);
if ($unknown_events !== false) {
foreach ($unknown_events as $key => $s_date) {
if (isset($s_date['time_from'])) {
$array_data['unknown'.$series_suffix]['data'][] = [
(($s_date['time_from'] - 1) * 1000),
0,
];
$array_data['unknown'.$series_suffix]['data'][] = [
($s_date['time_from'] * 1000),
($max * 1.05),
];
} else {
$array_data['unknown'.$series_suffix]['data'][] = [
($date_array['start_date'] * 1000),
($max * 1.05),
];
}
if (isset($s_date['time_to'])) {
$array_data['unknown'.$series_suffix]['data'][] = [
($s_date['time_to'] * 1000),
($max * 1.05),
];
$array_data['unknown'.$series_suffix]['data'][] = [
(($s_date['time_to'] + 1) * 1000),
0,
];
} else {
$array_data['unknown'.$series_suffix]['data'][] = [
($date_array['final_date'] * 1000),
($max * 1.05),
];
}
}
}
}
}
if ($params['show_events']
|| $params['show_alerts']
) {
$events = db_get_all_rows_filter(
'tevento',
['id_agentmodule' => $agent_module_id,
'utimestamp > '.$date_array['start_date'],
'utimestamp < '.$date_array['final_date'],
'order' => 'utimestamp ASC'
],
false,
'AND',
$data_module_graph['history_db']
);
$alerts_array = [];
$events_array = [];
if ($events && is_array($events)) {
$count_events = 0;
$count_alerts = 0;
foreach ($events as $k => $v) {
if (strpos($v['event_type'], 'alert') !== false) {
if ($params['flag_overlapped']) {
$alerts_array['data'][$count_alerts] = [
($v['utimestamp'] + $date_array['period'] * 1000),
($max * 1.10),
];
} else {
$alerts_array['data'][$count_alerts] = [
($v['utimestamp'] * 1000),
($max * 1.10),
];
}
$count_alerts++;
} else {
if ($params['flag_overlapped']) {
if (( strstr($v['event_type'], 'going_up') )
|| ( strstr($v['event_type'], 'going_down') )
) {
$events_array['data'][$count_events] = [
(($v['utimestamp'] + 1 + $date_array['period']) * 1000),
($max * 1.15),
];
} else {
$events_array['data'][$count_events] = [
($v['utimestamp'] + $date_array['period'] * 1000),
($max * 1.15),
];
}
} else {
if (( strstr($v['event_type'], 'going_up') )
|| ( strstr($v['event_type'], 'going_down') )
) {
$events_array['data'][$count_events] = [
(($v['utimestamp'] + 1) * 1000),
($max * 1.15),
];
} else {
$events_array['data'][$count_events] = [
($v['utimestamp'] * 1000),
($max * 1.15),
];
}
}
$count_events++;
}
}
}
}
if ($params['show_events']) {
$array_data['event'.$series_suffix] = $events_array;
}
if ($params['show_alerts']) {
$array_data['alert'.$series_suffix] = $alerts_array;
}
}
if ($params['return_data'] == 1) {
return $array_data;
}
$array_events_alerts[$series_suffix] = $events;
return $array_data;
}
/**
* Functions to create graphs.
*
* @param array $params Details builds graphs. For example:
* 'agent_module_id' => $agent_module_id,
* 'period' => $period,
* 'show_events' => false,
* 'width' => $width,
* 'height' => $height,
* 'title' => '',
* 'unit_name' => null,
* 'show_alerts' => false,
* 'date' => 0,
* 'unit' => '',
* 'baseline' => 0,
* 'return_data' => 0,
* 'show_title' => true,
* 'only_image' => false,
* 'homeurl' => $config['homeurl'],
* 'ttl' => 1,
* 'adapt_key' => '',
* 'compare' => false,
* 'show_unknown' => false,
* 'menu' => true,
* 'backgroundColor' => 'white',
* 'percentil' => null,
* 'dashboard' => false,
* 'vconsole' => false,
* 'type_graph' => 'area',
* 'fullscale' => false,
* 'id_widget_dashboard' => false,
* 'force_interval' => '',
* 'time_interval' => 300,
* 'array_data_create' => 0,
* 'show_legend' => true,
* 'show_overview' => true,
* 'return_img_base_64' => false,
* 'image_threshold' => false,
* 'graph_combined' => false,
* 'graph_render' => 0,
* 'zoom' => 1,
* 'server_id' => null,
* 'stacked' => 0
* 'maximum_y_axis' => 0.
*
* @return string html Content graphs.
*/
function grafico_modulo_sparse($params)
{
global $config;
if (isset($params) === false || is_array($params) === false) {
return false;
}
if (isset($params['period']) === false) {
return false;
}
if (isset($params['show_events']) === false) {
$params['show_events'] = false;
}
if (isset($params['width']) === false) {
$params['width'] = '90%';
}
if (isset($params['height']) === false) {
$params['height'] = 450;
}
if (isset($params['title']) === false) {
$params['title'] = '';
}
if (isset($params['unit_name']) === false) {
$params['unit_name'] = null;
}
if (isset($params['show_alerts']) === false) {
$params['show_alerts'] = false;
}
if (isset($params['date']) === false || !$params['date']) {
$params['date'] = get_system_time();
}
if (isset($params['unit']) === false) {
$params['unit'] = '';
}
if (isset($params['baseline']) === false) {
$params['baseline'] = 0;
}
if (isset($params['return_data']) === false) {
$params['return_data'] = 0;
}
if (isset($params['show_title']) === false) {
$show_title = true;
}
if (isset($params['only_image']) === false) {
$params['only_image'] = false;
}
if (isset($params['homeurl']) === false) {
$params['homeurl'] = $config['homeurl'];
}
if (isset($params['ttl']) === false) {
$params['ttl'] = 1;
}
if (isset($params['adapt_key']) === false) {
$params['adapt_key'] = '';
}
if (isset($params['compare']) === false) {
$params['compare'] = false;
}
if (isset($params['show_unknown']) === false) {
$params['show_unknown'] = false;
}
if (isset($params['menu']) === false) {
$params['menu'] = true;
}
if (isset($params['show_legend']) === false) {
$params['show_legend'] = true;
}
if (isset($params['show_overview']) === false) {
$params['show_overview'] = true;
}
if (isset($params['show_export_csv']) === false) {
$params['show_export_csv'] = true;
}
if (isset($params['backgroundColor']) === false) {
$params['backgroundColor'] = 'white';
}
if (isset($params['only_image']) === true && $params['vconsole'] !== true) {
$params['backgroundColor'] = 'transparent';
}
if (isset($params['percentil']) === false) {
$params['percentil'] = null;
}
if (isset($params['dashboard']) === false) {
$params['dashboard'] = false;
}
if (isset($params['vconsole']) === false || $params['vconsole'] == false) {
$params['vconsole'] = false;
} else {
$params['menu'] = false;
}
if (isset($params['type_graph']) === false) {
$params['type_graph'] = $config['type_module_charts'];
}
if (isset($params['fullscale']) === false) {
$params['fullscale'] = false;
}
if (isset($params['id_widget_dashboard']) === false) {
$params['id_widget_dashboard'] = false;
}
if (isset($params['force_interval']) === false) {
$params['force_interval'] = '';
}
if (isset($params['time_interval']) === false) {
$params['time_interval'] = 300;
}
if (isset($params['array_data_create']) === false) {
$params['array_data_create'] = 0;
}
if (isset($params['return_img_base_64']) === false) {
$params['return_img_base_64'] = false;
}
if (isset($params['image_threshold']) === false) {
$params['image_threshold'] = false;
}
if (isset($params['graph_combined']) === false) {
$params['graph_combined'] = false;
}
if (isset($params['zoom']) === false) {
$params['zoom'] = ($config['zoom_graph']) ? $config['zoom_graph'] : 1;
}
if (isset($params['type_mode_graph']) === false) {
$params['type_mode_graph'] = ($config['type_mode_graph'] ?? null);
if (isset($params['graph_render']) === true) {
$params['type_mode_graph'] = $params['graph_render'];
}
}
if (isset($params['maximum_y_axis']) === false) {
$params['maximum_y_axis'] = $config['maximum_y_axis'];
}
if (isset($params['projection']) === false) {
$params['projection'] = false;
}
if (isset($params['pdf']) === false) {
$params['pdf'] = false;
}
if (isset($params['agent_module_id']) === false) {
return graph_nodata_image($params);
} else {
$agent_module_id = $params['agent_module_id'];
}
if (isset($params['stacked']) === false) {
$params['stacked'] = 0;
}
if (isset($params['graph_font_size']) === true) {
$font_size = $params['graph_font_size'];
} else {
$font_size = $config['font_size'];
}
if (isset($params['basic_chart']) === false) {
$params['basic_chart'] = false;
}
if (isset($params['array_colors']) === false) {
$params['array_colors'] = false;
}
// If is metaconsole set 10pt size value.
if (is_metaconsole()) {
$font_size = '10';
}
$params['grid_color'] = '#C1C1C1';
$params['legend_color'] = '#636363';
$params['font'] = 'lato';
$params['font_size'] = $font_size;
$params['short_data'] = $config['short_module_graph_data'];
if ($params['only_image']) {
return generator_chart_to_pdf('sparse', $params);
}
global $graphic_type;
global $array_events_alerts;
$array_data = [];
$legend = [];
$array_events_alerts = [];
$date_array = [];
$date_array['period'] = $params['period'];
$date_array['final_date'] = $params['date'];
$date_array['start_date'] = ($params['date'] - $params['period']);
if ($agent_module_id) {
$module_data = db_get_row_sql(
'SELECT * FROM tagente_modulo
WHERE id_agente_modulo = '.$agent_module_id
);
$data_module_graph = [];
$data_module_graph['history_db'] = db_search_in_history_db(
$date_array['start_date']
);
$data_module_graph['agent_name'] = modules_get_agentmodule_agent_name(
$agent_module_id
);
$data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias(
$agent_module_id
);
$data_module_graph['agent_id'] = $module_data['id_agente'];
$data_module_graph['module_name'] = $module_data['nombre'];
$data_module_graph['id_module_type'] = $module_data['id_tipo_modulo'];
$data_module_graph['module_type'] = modules_get_moduletype_name(
$data_module_graph['id_module_type']
);
$data_module_graph['uncompressed'] = is_module_uncompressed(
$data_module_graph['module_type']
);
$data_module_graph['w_min'] = $module_data['min_warning'];
$data_module_graph['w_max'] = $module_data['max_warning'];
$data_module_graph['w_inv'] = $module_data['warning_inverse'];
$data_module_graph['c_min'] = $module_data['min_critical'];
$data_module_graph['c_max'] = $module_data['max_critical'];
$data_module_graph['c_inv'] = $module_data['critical_inverse'];
$data_module_graph['unit'] = $module_data['unit'];
} else {
$data_module_graph = false;
}
// Format of the graph.
if (empty($params['unit']) === true) {
$params['unit'] = $module_data['unit'];
if (modules_is_unit_macro($params['unit'])) {
$params['unit'] = '';
}
}
if (empty($params['divisor']) === true) {
$params['divisor'] = get_data_multiplier($params['unit']);
}
if (!$params['array_data_create']) {
if ($params['baseline']) {
$array_data = get_baseline_data(
$agent_module_id,
$date_array,
$data_module_graph,
$params
);
} else {
if ($params['compare'] !== false) {
$series_suffix = 2;
$date_array_prev['final_date'] = $date_array['start_date'];
$date_array_prev['start_date'] = ($date_array['start_date'] - $date_array['period']);
$date_array_prev['period'] = $date_array['period'];
if ($params['compare'] === 'overlapped') {
$params['flag_overlapped'] = 1;
} else {
$params['flag_overlapped'] = 0;
}
$array_data = grafico_modulo_sparse_data(
$agent_module_id,
$date_array_prev,
$data_module_graph,
$params,
$series_suffix
);
switch ($params['compare']) {
case 'separated':
case 'overlapped':
// Store the chart calculated.
$array_data_prev = $array_data;
$legend_prev = $legend;
break;
default:
// Not defined.
break;
}
}
$series_suffix = 1;
$params['flag_overlapped'] = 0;
$array_data = grafico_modulo_sparse_data(
$agent_module_id,
$date_array,
$data_module_graph,
$params,
$series_suffix
);
if ($params['compare']) {
if ($params['compare'] === 'overlapped') {
$array_data = array_merge($array_data, $array_data_prev);
$legend = array_merge($legend, $legend_prev);
}
}
}
} else {
$array_data = $params['array_data_create'];
}
if ($params['return_data']) {
return $array_data;
}
$series_type_array = series_type_graph_array(
$array_data,
$params
);
$series_type = $series_type_array['series_type'];
$legend = $series_type_array['legend'];
$color = $series_type_array['color'];
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
),
];
}
if ($data_module_graph === false) {
$data_module_graph = [];
}
$data_module_graph['series_suffix'] = $series_suffix;
// Check available data.
if ($params['compare'] === 'separated') {
if (empty($array_data) === false) {
$return = area_graph(
$agent_module_id,
$array_data,
$legend,
$series_type,
$color,
$date_array,
$data_module_graph,
$params,
$water_mark,
$array_events_alerts
);
} else {
$return = graph_nodata_image($params);
}
$return .= '
';
if (empty($array_data_prev) === false) {
$series_type_array = series_type_graph_array(
$array_data_prev,
$params
);
$series_type = $series_type_array['series_type'];
$legend = $series_type_array['legend'];
$color = $series_type_array['color'];
$return .= area_graph(
$agent_module_id,
$array_data_prev,
$legend,
$series_type,
$color,
$date_array_prev,
$data_module_graph,
$params,
$water_mark,
$array_events_alerts
);
} else {
$return = graph_nodata_image($params);
}
} else {
if (empty($array_data) === false) {
$return = area_graph(
$agent_module_id,
$array_data,
$legend,
$series_type,
$color,
$date_array,
$data_module_graph,
$params,
$water_mark,
$array_events_alerts
);
} else {
$return = graph_nodata_image($params);
}
}
return $return;
}
/**
* Functions tu create graphs.
*
* @param array $module_list Array modules.
* @param array $params Details builds graphs. For example:
* 'period' => $period,
* 'show_events' => false,
* 'width' => $width,
* 'height' => $height,
* 'title' => '',
* 'unit_name' => null,
* 'show_alerts' => false,
* 'date' => 0,
* 'unit' => '',
* 'only_image' => false,
* 'homeurl' => '',
* 'ttl' => 1,
* 'percentil' => null,
* 'dashboard' => false,
* 'vconsole' => false,
* 'fullscale' => false,
* 'id_widget_dashboard' => false.
* @param array $params_combined Details builds graphs. For example:
* 'weight_list' => array(),
* 'stacked' => 0,
* 'projection' => false,
* 'labels' => array(),
* 'from_interface' => false,
* 'summatory' => 0,
* 'average' => 0,
* 'modules_series' => 0,
* 'id_graph' => 0,
* 'return' => 1.
*
* @return string html Content graphs.
*/
function graphic_combined_module(
$module_list,
$params,
$params_combined
) {
global $config;
if (isset($params_combined['from_interface']) === false) {
$params_combined['from_interface'] = false;
}
if (isset($params_combined['stacked']) === false) {
if ($params_combined['from_interface']) {
if ($config['type_interface_charts'] == 'line') {
$params_combined['stacked'] = CUSTOM_GRAPH_LINE;
} else {
$params_combined['stacked'] = CUSTOM_GRAPH_AREA;
}
} else {
if ($params_combined['id_graph'] == 0) {
$params_combined['stacked'] = CUSTOM_GRAPH_AREA;
} else {
$params_combined['stacked'] = db_get_row(
'tgraph',
'id_graph',
$params_combined['id_graph']
);
}
}
}
$params['stacked'] = $params_combined['stacked'];
if (isset($params_combined['projection']) === false
|| $params_combined['projection'] == false
) {
$params_combined['projection'] = false;
} else {
$params['stacked'] = 'area';
$params['projection'] = true;
}
if (isset($params_combined['labels']) === false) {
$params_combined['labels'] = [];
}
if (isset($params_combined['summatory']) === false) {
$params_combined['summatory'] = 0;
}
if (isset($params_combined['average']) === false) {
$params_combined['average'] = 0;
}
if (isset($params_combined['modules_series']) === false) {
$params_combined['modules_series'] = 0;
}
if (isset($params_combined['return']) === false) {
$params_combined['return'] = 1;
}
if (isset($params_combined['id_graph']) === false) {
$params_combined['id_graph'] = 0;
}
if (isset($params_combined['type_report']) === false) {
$params_combined['type_report'] = '';
}
if (isset($params['percentil']) === false) {
$params_combined['percentil'] = null;
} else {
$params_combined['percentil'] = $params['percentil'];
}
if (isset($params['period']) === false) {
return false;
}
if (isset($params['width']) === false) {
$params['width'] = '90%';
}
if (isset($params['height']) === false) {
$params['height'] = 450;
}
if (isset($params['title']) === false) {
$params['title'] = '';
}
if (isset($params['unit_name']) === false) {
$params['unit_name'] = null;
}
if (isset($params['show_alerts']) === false) {
$params['show_alerts'] = false;
}
if (isset($params['date']) === false || !$params['date']) {
$params['date'] = get_system_time();
}
if (isset($params['only_image']) === false) {
$params['only_image'] = false;
}
if (isset($params['ttl']) === false) {
$params['ttl'] = 1;
}
if (isset($params['backgroundColor']) === false) {
$params['backgroundColor'] = 'white';
}
if (isset($params['dashboard']) === false) {
$params['dashboard'] = false;
}
if (isset($params['menu']) === false
|| $params['only_image']
) {
$params['menu'] = true;
} else {
$params['menu'] = false;
}
if (isset($params['vconsole']) === false
|| $params['vconsole'] == false
) {
$params['vconsole'] = false;
} else {
$params['menu'] = false;
}
if (isset($params['type_graph']) === false) {
$params['type_graph'] = $config['type_module_charts'];
}
if (isset($params['percentil']) === false) {
$params['percentil'] = null;
}
if (isset($params['fullscale']) === false) {
$params['fullscale'] = false;
}
if (isset($params['id_widget_dashboard']) === false) {
$params['id_widget_dashboard'] = false;
}
if (isset($params['homeurl']) === false) {
$params['homeurl'] = ui_get_full_url(false, false, false, false);
}
if (isset($params['show_legend']) === false) {
$params['show_legend'] = true;
}
if (isset($params['show_overview']) === false) {
$params['show_overview'] = true;
}
if (isset($params['show_export_csv']) === false) {
$params['show_export_csv'] = true;
}
if (isset($params['return_img_base_64']) === false) {
$params['return_img_base_64'] = false;
}
if (isset($params['image_threshold']) === false) {
$params['image_threshold'] = false;
}
if (isset($params['show_unknown']) === false) {
$params['show_unknown'] = false;
}
if (isset($params['type_mode_graph']) === false) {
$params['type_mode_graph'] = 0;
if (isset($params['graph_render']) === true) {
$params['type_mode_graph'] = $params['graph_render'];
$params_combined['type_mode_graph'] = $params['graph_render'];
}
}
if (isset($params['fullscale']) === false) {
$params_combined['fullscale'] = false;
} else {
$params_combined['fullscale'] = $params['fullscale'];
}
if (isset($params['maximum_y_axis']) === false) {
$params['maximum_y_axis'] = $config['maximum_y_axis'];
}
$params['graph_combined'] = true;
$params_combined['graph_combined'] = true;
if ($params['only_image']) {
return generator_chart_to_pdf(
'combined',
$params,
$params_combined,
$module_list
);
}
if (isset($params['zoom']) === false) {
$params['zoom'] = 1;
}
$params['grid_color'] = '#C1C1C1';
$params['legend_color'] = '#636363';
$params['font'] = 'lato';
$params['font_size'] = $config['font_size'];
$params['short_data'] = $config['short_module_graph_data'];
global $config;
global $graphic_type;
$sources = false;
if ((int) $params_combined['id_graph'] === 0) {
$count_modules = count($module_list);
if (!$params_combined['weight_list']) {
$weights = array_fill(0, $count_modules, 1);
}
if ($count_modules > 0) {
foreach ($module_list as $key => $value) {
$sources[$key]['id_server'] = (isset($value['id_server']) === true) ? $value['id_server'] : $params['server_id'];
$sources[$key]['id_agent_module'] = (isset($value['module']) === true) ? $value['module'] : $value;
$sources[$key]['weight'] = $weights[$key];
$sources[$key]['label'] = $params_combined['labels'];
}
}
} else {
if (is_metaconsole()) {
metaconsole_restore_db();
$server = metaconsole_get_connection_by_id($params['server_id']);
if (metaconsole_connect($server) != NOERR) {
return false;
}
}
$sources = db_get_all_rows_field_filter(
'tgraph_source',
'id_graph',
$params_combined['id_graph'],
'field_order'
);
if (is_metaconsole()) {
if (isset($sources) && is_array($sources)) {
foreach ($sources as $key => $value) {
$sources[$key]['id_server'] = $params['server_id'];
}
}
}
$series = db_get_all_rows_sql(
'SELECT summatory_series,
average_series,
modules_series
FROM tgraph
WHERE id_graph = '.$params_combined['id_graph']
);
$summatory = $series[0]['summatory_series'];
$average = $series[0]['average_series'];
$modules_series = $series[0]['modules_series'];
if (is_metaconsole()) {
metaconsole_restore_db();
}
}
if (isset($sources) === true && is_array($sources) === true) {
$weights = [];
$labels = [];
$modules = [];
foreach ($sources as $source) {
if (is_metaconsole() === true) {
metaconsole_restore_db();
$server = metaconsole_get_connection_by_id($source['id_server']);
if (metaconsole_connect($server) != NOERR) {
continue;
}
}
$id_agent = agents_get_module_id(
$source['id_agent_module']
);
if (!$id_agent) {
continue;
}
$modulepush = [
'server' => (isset($source['id_server']) === true) ? $source['id_server'] : 0,
'module' => $source['id_agent_module'],
];
array_push($modules, $modulepush);
array_push($weights, $source['weight']);
if (empty($source['label']) === false || $params_combined['labels']) {
$agent_description = agents_get_description($id_agent);
$agent_group = agents_get_agent_group($id_agent);
$agent_address = agents_get_address($id_agent);
$agent_alias = agents_get_alias($id_agent);
$module_name = modules_get_agentmodule_name(
$source['id_agent_module']
);
$module_description = modules_get_agentmodule_descripcion(
$source['id_agent_module']
);
$items_label = [
'type' => 'custom_graph',
'id_agent' => $id_agent,
'id_agent_module' => $source['id_agent_module'],
'agent_description' => $agent_description,
'agent_group' => $agent_group,
'agent_address' => $agent_address,
'agent_alias' => $agent_alias,
'module_name' => $module_name,
'module_description' => $module_description,
];
if (is_array($source['label']) === true) {
$lab = '';
foreach ($source['label'] as $label) {
$lab .= reporting_label_macro(
$items_label,
($label ?? '')
);
}
} else if ($source['label'] != '') {
$lab = reporting_label_macro(
$items_label,
($source['label'] ?? '')
);
} else {
$lab = reporting_label_macro(
$items_label,
($params_combined['labels'] ?? '')
);
}
$labels[$source['id_agent_module']] = $lab;
}
if (is_metaconsole() === true) {
metaconsole_restore_db();
}
}
}
if ((bool) $params_combined['from_interface'] === true) {
$labels = [];
}
if ($module_list) {
$params_combined['modules_id'] = $module_list;
} else {
$params_combined['modules_id'] = $modules;
}
if (isset($summatory) === true) {
$params_combined['summatory'] = $summatory;
}
if (isset($average) === true) {
$params_combined['average'] = $average;
}
if (isset($modules_series) === true) {
$params_combined['modules_series'] = $modules_series;
}
if (isset($labels) === true) {
$params_combined['labels'] = $labels;
}
if (isset($weights) === true) {
$params_combined['weight_list'] = $weights;
}
if (!$module_list) {
$module_list = $modules;
}
if ($sources === false) {
if ($params_combined['return']) {
return false;
} else {
ui_print_info_message(
[
'no_close' => true,
'message' => __('No items.'),
]
);
return;
}
}
$width = $params['width'];
$height = $params['height'];
$homeurl = $params['homeurl'];
$ttl = $params['ttl'];
$date_array = [];
$date_array['period'] = $params['period'];
$date_array['final_date'] = $params['date'];
$date_array['start_date'] = ($params['date'] - $params['period']);
$background_color = $params['backgroundColor'];
$datelimit = $date_array['start_date'];
$fixed_font_size = $config['font_size'];
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
),
];
}
$long_index = '';
if (($config['style'] === 'pandora_black' && !is_metaconsole()) && ($params['pdf'] === false || $params['pdf'] === null )
) {
$background_color = '#222';
$params['legend_color'] = '#fff';
} else if ($params['pdf']) {
$params['legend_color'] = '#000';
}
switch ($params_combined['stacked']) {
default:
case CUSTOM_GRAPH_STACKED_LINE:
case CUSTOM_GRAPH_STACKED_AREA:
case CUSTOM_GRAPH_AREA:
case CUSTOM_GRAPH_LINE:
$date_array = [];
$date_array['period'] = $params['period'];
$date_array['final_date'] = $params['date'];
$date_array['start_date'] = ($params['date'] - $params['period']);
if (is_metaconsole()) {
$server_name = metaconsole_get_server_by_id($modules[0]['server']);
}
if (isset($params_combined['custom_period']) !== false && $params_combined['custom_period'] !== false) {
$period = $params_combined['custom_period'];
} else {
$period = $params['period'];
}
if ($params_combined['projection']) {
$output_projection = forecast_projection_graph(
$module_list[0],
$period,
$params_combined['projection'],
false,
false,
false,
$server_name
);
}
$i = 0;
$array_data = [];
foreach ($module_list as $key => $agent_module_id) {
if ((bool) $agent_module_id === false) {
continue;
}
// Only 10 item for chart.
if ($i >= $config['items_combined_charts']) {
break;
}
if (is_metaconsole()) {
metaconsole_restore_db();
if (isset($agent_module_id['server'])) {
$id_server = $agent_module_id['server'];
} else if (isset($agent_module_id['id_server'])) {
$id_server = $agent_module_id['id_server'];
} else {
$id_server = $source['id_server'];
}
$server = metaconsole_get_connection_by_id($id_server);
if (metaconsole_connect($server) != NOERR) {
continue;
}
}
if (is_array($agent_module_id)) {
$agent_module_id = $agent_module_id['module'];
}
$module_data = db_get_row_sql(
'SELECT * FROM tagente_modulo
WHERE id_agente_modulo = '.$agent_module_id
);
$data_module_graph = [];
$data_module_graph['history_db'] = db_search_in_history_db(
$date_array['start_date']
);
$data_module_graph['agent_name'] = modules_get_agentmodule_agent_name(
$agent_module_id
);
if (is_metaconsole()) {
$data_module_graph['agent_alias'] = db_get_value(
'alias',
'tagente',
'id_agente',
(int) $module_data['id_agente']
);
} else {
$data_module_graph['agent_alias'] = modules_get_agentmodule_agent_alias(
$agent_module_id
);
}
$data_module_graph['agent_id'] = $module_data['id_agente'];
$data_module_graph['module_name'] = $module_data['nombre'];
$data_module_graph['id_module_type'] = $module_data['id_tipo_modulo'];
$data_module_graph['module_type'] = modules_get_moduletype_name(
$data_module_graph['id_module_type']
);
$data_module_graph['uncompressed'] = is_module_uncompressed(
$data_module_graph['module_type']
);
$data_module_graph['w_min'] = $module_data['min_warning'];
$data_module_graph['w_max'] = $module_data['max_warning'];
$data_module_graph['w_inv'] = $module_data['warning_inverse'];
$data_module_graph['c_min'] = $module_data['min_critical'];
$data_module_graph['c_max'] = $module_data['max_critical'];
$data_module_graph['c_inv'] = $module_data['critical_inverse'];
$data_module_graph['module_id'] = $agent_module_id;
$data_module_graph['unit'] = $module_data['unit'];
$params['unit'] = $module_data['unit'];
$params['divisor'] = get_data_multiplier($params['unit']);
// Stract data.
$array_data_module = grafico_modulo_sparse_data(
$agent_module_id,
$date_array,
$data_module_graph,
$params,
$i
);
$series_suffix = $i;
// Convert to array graph and weight.
foreach ($array_data_module as $key => $value) {
$array_data[$key] = $value;
if ($params_combined['weight_list'][$i] != 1) {
foreach ($value['data'] as $k => $v) {
if ($v[1] != false) {
$array_data[$key]['data'][$k][1] = ($v[1] * $params_combined['weight_list'][$i]);
$array_data[$key]['slice_data'][$v[0]]['avg'] *= $params_combined['weight_list'][$i];
$array_data[$key]['slice_data'][$v[0]]['min'] *= $params_combined['weight_list'][$i];
$array_data[$key]['slice_data'][$v[0]]['max'] *= $params_combined['weight_list'][$i];
}
}
$array_data[$key]['max'] *= $params_combined['weight_list'][$i];
$array_data[$key]['min'] *= $params_combined['weight_list'][$i];
$array_data[$key]['avg'] *= $params_combined['weight_list'][$i];
$array_data[$key]['weight'] = $params_combined['weight_list'][$i];
}
}
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
),
];
}
// Work around for fixed the agents name with huge size chars.
$fixed_font_size = $config['font_size'];
$i++;
if (is_metaconsole()) {
metaconsole_restore_db();
}
}
if (empty($array_data) === true) {
if ($params_combined['return']) {
return graph_nodata_image($params);
}
echo graph_nodata_image($params);
return false;
}
if ($params_combined['projection']) {
// If projection doesn't have data then don't draw graph.
if ($output_projection != null) {
$date_array_projection = max($output_projection);
$date_array['final_date'] = ($date_array_projection[0] / 1000);
$array_data['projection']['data'] = $output_projection;
}
}
// Summatory and average series.
if ($params_combined['stacked'] == CUSTOM_GRAPH_AREA
|| $params_combined['stacked'] == CUSTOM_GRAPH_LINE
) {
if ($params_combined['summatory']
|| $params_combined['average']
) {
$array_data = combined_graph_summatory_average(
$array_data,
$params_combined['average'],
$params_combined['summatory'],
$params_combined['modules_series'],
$date_array
);
}
}
$series_type_array = series_type_graph_array(
$array_data,
$params_combined
);
$series_type = $series_type_array['series_type'];
$legend = $series_type_array['legend'];
$color = $series_type_array['color'];
$threshold_data = [];
if ($params_combined['from_interface']) {
$yellow_threshold = 0;
$red_threshold = 0;
$yellow_up = 0;
$red_up = 0;
$yellow_inverse = 0;
$red_inverse = 0;
$compare_warning = false;
$compare_critical = false;
$do_it_warning_min = true;
$do_it_critical_min = true;
$do_it_warning_max = true;
$do_it_critical_max = true;
$do_it_warning_inverse = true;
$do_it_critical_inverse = true;
foreach ($module_list as $index => $id_module) {
// Get module warning_min and critical_min.
$warning_min = db_get_value(
'min_warning',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
$critical_min = db_get_value(
'min_critical',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
if ($index == 0) {
$compare_warning = $warning_min;
} else {
if ($compare_warning != $warning_min) {
$do_it_warning_min = false;
}
}
if ($index == 0) {
$compare_critical = $critical_min;
} else {
if ($compare_critical != $critical_min) {
$do_it_critical_min = false;
}
}
}
if ($do_it_warning_min || $do_it_critical_min) {
foreach ($module_list as $index => $id_module) {
$warning_max = db_get_value(
'max_warning',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
$critical_max = db_get_value(
'max_critical',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
if ($index == 0) {
$yellow_up = $warning_max;
} else {
if ($yellow_up != $warning_max) {
$do_it_warning_max = false;
}
}
if ($index == 0) {
$red_up = $critical_max;
} else {
if ($red_up != $critical_max) {
$do_it_critical_max = false;
}
}
}
}
if ($do_it_warning_min || $do_it_critical_min) {
foreach ($module_list as $index => $id_module) {
$warning_inverse = db_get_value(
'warning_inverse',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
$critical_inverse = db_get_value(
'critical_inverse',
'tagente_modulo',
'id_agente_modulo',
$id_module
);
if ($index == 0) {
$yellow_inverse = $warning_inverse;
} else {
if ($yellow_inverse != $warning_inverse) {
$do_it_warning_inverse = false;
}
}
if ($index == 0) {
$red_inverse = $critical_inverse;
} else {
if ($red_inverse != $critical_inverse) {
$do_it_critical_inverse = false;
}
}
}
}
if ($do_it_warning_min
&& $do_it_warning_max
&& $do_it_warning_inverse
) {
$yellow_threshold = $compare_warning;
$threshold_data['yellow_threshold'] = $compare_warning;
$threshold_data['yellow_up'] = $yellow_up;
$threshold_data['yellow_inverse'] = (bool) $yellow_inverse;
}
if ($do_it_critical_min
&& $do_it_critical_max
&& $do_it_critical_inverse
) {
$red_threshold = $compare_critical;
$threshold_data['red_threshold'] = $compare_critical;
$threshold_data['red_up'] = $red_up;
$threshold_data['red_inverse'] = (bool) $red_inverse;
}
$params['threshold_data'] = $threshold_data;
}
if ($params['vconsole'] === true) {
$water_mark = false;
}
$output = area_graph(
$agent_module_id,
$array_data,
$legend,
$series_type,
$color,
$date_array,
$data_module_graph,
$params,
$water_mark,
$array_events_alerts
);
break;
case CUSTOM_GRAPH_BULLET_CHART_THRESHOLD:
case CUSTOM_GRAPH_BULLET_CHART:
$number_elements = count($module_list);
if ($params_combined['stacked'] == CUSTOM_GRAPH_BULLET_CHART_THRESHOLD) {
$acumulador = 0;
foreach ($module_list as $module_item) {
$module = $module_item;
$query_last_value = sprintf(
'
SELECT datos
FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp < %d
ORDER BY utimestamp DESC',
$module,
$params['date']
);
$temp_data = db_get_value_sql($query_last_value);
if ($acumulador < $temp_data) {
$acumulador = $temp_data;
}
}
}
foreach ($module_list as $module_item) {
if (is_metaconsole() === true) {
// Automatic custom graph from the report
// template in metaconsole.
$server = metaconsole_get_connection_by_id(
$module_item['server']
);
metaconsole_connect($server);
}
$module = $module_item['module'];
$search_in_history_db = db_search_in_history_db($datelimit);
$temp[$module] = io_safe_output(
modules_get_agentmodule($module)
);
$query_last_value = sprintf(
'
SELECT datos
FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp < %d
ORDER BY utimestamp DESC',
$module,
$params['date']
);
$temp_data = db_get_value_sql($query_last_value);
if ($temp_data) {
if (is_numeric($temp_data)) {
$value = $temp_data;
} else {
$value = count($value);
}
} else {
$value = false;
}
if (!empty($params_combined['labels'])
&& isset($params_combined['labels'][$module])
) {
$label = io_safe_output($params_combined['labels'][$module]);
} else {
$alias = db_get_value(
'alias',
'tagente',
'id_agente',
$temp[$module]['id_agente']
);
$label = $alias.': '.$temp[$module]['nombre'];
}
$temp[$module]['label'] = $label;
$temp[$module]['value'] = $value;
$temp_max = reporting_get_agentmodule_data_max(
$module,
$params['period'],
$params['date']
);
if ($temp_max < 0) {
$temp_max = 0;
}
if (isset($acumulador)) {
$temp[$module]['max'] = $acumulador;
} else {
$temp[$module]['max'] = ($temp_max === false) ? 0 : $temp_max;
}
$temp_min = reporting_get_agentmodule_data_min(
$module,
$params['period'],
$params['date']
);
if ($temp_min < 0) {
$temp_min = 0;
}
$temp[$module]['min'] = ($temp_min === false) ? 0 : $temp_min;
if (is_metaconsole() === true) {
metaconsole_restore_db();
}
}
$graph_values = $temp;
if (!$params['vconsole']) {
$width = 1024;
$height = 50;
} else {
$height = ($height / $number_elements);
$water_mark = false;
}
$color = color_graph_array();
$output = stacked_bullet_chart(
$graph_values,
$width,
$height,
$color,
[],
$long_index,
ui_get_full_url(
'images/image_problem_area_small.png',
false,
false,
false
),
'',
'',
$water_mark,
$config['fontpath'],
($config['font_size'] + 1),
'',
$ttl,
$homeurl,
$background_color
);
break;
case CUSTOM_GRAPH_GAUGE:
$i = 0;
$number_elements = count($module_list);
foreach ($module_list as $module_item) {
if (is_metaconsole() === true) {
$server = metaconsole_get_connection_by_id(
$module_item['server']
);
metaconsole_connect($server);
}
$module = $module_item['module'];
$temp[$module] = modules_get_agentmodule($module);
$query_last_value = sprintf(
'
SELECT datos
FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp < %d
ORDER BY utimestamp DESC',
$module,
$params['date']
);
$temp_data = db_get_value_sql($query_last_value);
if ($temp_data) {
if (is_numeric($temp_data)) {
$value = $temp_data;
} else {
$value = count($value);
}
} else {
$value = false;
}
$temp[$module]['label'] = ($params_combined['labels'][$module] != '') ? $params_combined['labels'][$module] : $temp[$module]['nombre'];
$temp[$module]['value'] = $value;
$temp[$module]['label'] = ui_print_truncate_text(
$temp[$module]['label'],
'module_small',
false,
true,
false,
'..'
);
if ($temp[$module]['unit'] == '%') {
$temp[$module]['min'] = 0;
$temp[$module]['max'] = 100;
} else {
$min = $temp[$module]['min'];
if ($temp[$module]['max'] == 0) {
$max = reporting_get_agentmodule_data_max(
$module,
$params['period'],
$params['date']
);
} else {
$max = $temp[$module]['max'];
}
$temp[$module]['min'] = ($min == 0 ) ? 0 : $min;
$temp[$module]['max'] = ($max == 0 ) ? 100 : $max;
}
$temp[$module]['gauge'] = uniqid('gauge_');
if (is_metaconsole() === true) {
metaconsole_restore_db();
}
$i++;
}
$graph_values = $temp;
$color = color_graph_array();
if ($params['vconsole'] === false) {
$new_width = 200;
$new_height = 200;
} else {
$ratio = ((200 * ( $height / (200 * $number_elements) )) / (200 * ( $width / (200 * $number_elements))));
$new_width = ( 200 * ( $width / (200 * $number_elements) ) );
$new_height = ( 200 * ( $height / (200 * $number_elements) / $ratio ) );
if ($height > $width) {
$new_height = (200 * ($height / (200 * $number_elements)));
$new_width = (200 * ($width / (200 * $number_elements)) / $ratio);
}
}
if (isset($params['pdf']) === true && $params['pdf'] === true) {
$transitionDuration = 0;
} else {
$transitionDuration = 500;
}
$output = stacked_gauge(
$graph_values,
$new_width,
$new_height,
$color,
$module_name_list,
ui_get_full_url(
'images/image_problem_area_small.png',
false,
false,
false
),
$config['fontpath'],
$fixed_font_size,
'',
$homeurl,
$transitionDuration
);
break;
case CUSTOM_GRAPH_HBARS:
case CUSTOM_GRAPH_VBARS:
$label = '';
$i = 0;
foreach ($module_list as $module_item) {
if ($i >= $config['items_combined_charts']) {
break;
}
if (is_metaconsole() === true) {
$server = metaconsole_get_connection_by_id(
$module_item['server']
);
metaconsole_connect($server);
}
$module = $module_item['module'];
$module_data = modules_get_agentmodule($module);
$query_last_value = sprintf(
'SELECT datos
FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp < %d
ORDER BY utimestamp DESC',
$module,
$params['date']
);
$temp_data = db_get_value_sql($query_last_value);
if (empty($params_combined['labels']) === false
&& isset($params_combined['labels'][$module]) === true
) {
$label = $params_combined['labels'][$module];
} else {
$alias = db_get_value(
'alias',
'tagente',
'id_agente',
$module_data['id_agente']
);
$label = $alias.' - '.$module_data['nombre'];
}
$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();
}
$i++;
}
$color = color_graph_array();
if ($params['vconsole'] === true) {
$water_mark = '';
}
$options = [
'height' => $height,
'waterMark' => $water_mark,
'ttl' => $ttl,
'pdf' => $params['pdf'],
'legend' => ['display' => false],
'scales' => [
'x' => [
'bounds' => 'data',
'grid' => ['display' => false],
],
'y' => [
'grid' => ['display' => false],
],
],
'labels' => $graph_labels,
];
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
$options['axis'] = 'y';
}
if ((bool) $params['pdf'] === true) {
$options['dataLabel'] = ['display' => 'auto'];
if ($params_combined['stacked'] == CUSTOM_GRAPH_HBARS) {
$options['layout'] = [
'padding' => ['right' => 35],
];
} else {
$options['layout'] = [
'padding' => ['top' => 35],
];
}
}
$output = '