mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
new widget datamatrix pandora_enterprise#8619
This commit is contained in:
parent
ff8c0d999d
commit
f273813869
@ -1451,6 +1451,7 @@ if (check_login()) {
|
|||||||
|
|
||||||
// Datatables offset, limit.
|
// Datatables offset, limit.
|
||||||
$start = get_parameter('start', 0);
|
$start = get_parameter('start', 0);
|
||||||
|
$formatData = (bool) get_parameter('formatData', 0);
|
||||||
$length = get_parameter(
|
$length = get_parameter(
|
||||||
'length',
|
'length',
|
||||||
$config['block_size']
|
$config['block_size']
|
||||||
@ -1471,6 +1472,14 @@ if (check_login()) {
|
|||||||
$date = (get_system_time() - ($time_all_box * $start));
|
$date = (get_system_time() - ($time_all_box * $start));
|
||||||
$datelimit = ($date - $time_all_box);
|
$datelimit = ($date - $time_all_box);
|
||||||
foreach ($modules as $key => $value) {
|
foreach ($modules as $key => $value) {
|
||||||
|
// TODO: tresholds.
|
||||||
|
$value['thresholds'] = [
|
||||||
|
'min_critical' => (empty($value['c_min']) === true) ? null : $value['c_min'],
|
||||||
|
'max_critical' => (empty($value['c_max']) === true) ? null : $value['c_max'],
|
||||||
|
'min_warning' => (empty($value['w_min']) === true) ? null : $value['w_min'],
|
||||||
|
'max_warning' => (empty($value['w_max']) === true) ? null : $value['w_max'],
|
||||||
|
];
|
||||||
|
|
||||||
$module_data = db_uncompress_module_data(
|
$module_data = db_uncompress_module_data(
|
||||||
$value['id'],
|
$value['id'],
|
||||||
$datelimit,
|
$datelimit,
|
||||||
@ -1481,16 +1490,47 @@ if (check_login()) {
|
|||||||
|
|
||||||
$uncompressData[] = array_reduce(
|
$uncompressData[] = array_reduce(
|
||||||
$module_data,
|
$module_data,
|
||||||
function ($carry, $item) use ($value) {
|
function ($carry, $item) use ($value, $config, $formatData) {
|
||||||
|
// Last value.
|
||||||
|
$vdata = null;
|
||||||
if (is_array($item['data']) === true) {
|
if (is_array($item['data']) === true) {
|
||||||
foreach ($item['data'] as $i => $v) {
|
foreach ($item['data'] as $v) {
|
||||||
$carry[] = [
|
$vdata = $v['datos'];
|
||||||
'utimestamp' => $v['utimestamp'],
|
|
||||||
'Column-'.$value['id'] => $v['datos'],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$status = get_status_data_modules(
|
||||||
|
$value['id'],
|
||||||
|
$vdata,
|
||||||
|
$value['thresholds']
|
||||||
|
);
|
||||||
|
$resultData = '<span style="color:'.$status['color'].'">';
|
||||||
|
if ($vdata !== null && $vdata !== '') {
|
||||||
|
if (isset($formatData) === true
|
||||||
|
&& (bool) $formatData === true
|
||||||
|
) {
|
||||||
|
$resultData .= format_for_graph(
|
||||||
|
$vdata,
|
||||||
|
$config['graph_precision']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$resultData .= sla_truncate(
|
||||||
|
$vdata,
|
||||||
|
$config['graph_precision']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultData .= ' '.$value['unit'];
|
||||||
|
} else {
|
||||||
|
$resultData .= '--';
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultData .= '</span>';
|
||||||
|
$carry[] = [
|
||||||
|
'utimestamp' => $item['utimestamp'],
|
||||||
|
'Column-'.$value['id'] => $resultData,
|
||||||
|
];
|
||||||
|
|
||||||
return $carry;
|
return $carry;
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
@ -1511,20 +1551,6 @@ if (check_login()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: TO BE CONTINUED.
|
|
||||||
/*
|
|
||||||
if (is_numeric($tmp->data) === true) {
|
|
||||||
$tmp->data = format_numeric(
|
|
||||||
$tmp->data,
|
|
||||||
$config['graph_precision']
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$tmp->data = ui_print_truncate_text($tmp->data, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
$carry[] = $tmp;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $carry;
|
return $carry;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -4336,3 +4336,57 @@ function modules_get_regex(
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_status_data_modules($id_module, $data, $thresholds)
|
||||||
|
{
|
||||||
|
// Check not init.
|
||||||
|
if ($data === false) {
|
||||||
|
return ['color' => COL_NOTINIT];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check boolean.
|
||||||
|
$is_bolean = modules_is_boolean($id_module);
|
||||||
|
if ($is_bolean === true) {
|
||||||
|
if ($data > 0) {
|
||||||
|
return ['color' => COL_CRITICAL];
|
||||||
|
} else {
|
||||||
|
return ['color' => COL_NORMAL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (getStatuses() as $status) {
|
||||||
|
if ($thresholds[$status]['min'] === null
|
||||||
|
&& $thresholds[$status]['max'] === null
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($thresholds[$status]['min'] === null
|
||||||
|
&& $thresholds[$status]['max'] >= $data)
|
||||||
|
|| ($thresholds[$status]['max'] === null
|
||||||
|
&& $thresholds[$status]['min'] <= $data)
|
||||||
|
|| ($thresholds[$status]['min'] <= $data
|
||||||
|
&& $thresholds[$status]['max'] >= $data)
|
||||||
|
) {
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['color' => COL_NORMAL];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function getStatuses()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'CRITICAL',
|
||||||
|
'WARNING',
|
||||||
|
'NORMAL',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
@ -547,8 +547,10 @@ class DataMatrix extends Widget
|
|||||||
'length' => $this->values['limit'],
|
'length' => $this->values['limit'],
|
||||||
'period' => $this->values['period'],
|
'period' => $this->values['period'],
|
||||||
'slice' => $this->values['slice'],
|
'slice' => $this->values['slice'],
|
||||||
|
'formatData' => $this->values['formatData'],
|
||||||
'modules' => json_encode($modules),
|
'modules' => json_encode($modules),
|
||||||
],
|
],
|
||||||
|
'default_pagination' => $this->values['limit'],
|
||||||
'no_sortable_columns' => $columns_sort,
|
'no_sortable_columns' => $columns_sort,
|
||||||
'order' => [
|
'order' => [
|
||||||
'field' => 'date',
|
'field' => 'date',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user