mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-09-26 03:19:05 +02:00
Merge branch 'ent-9641-mejorar-heatmaps' into 'develop'
Ent 9641 mejorar heatmaps See merge request artica/pandorafms!5196
This commit is contained in:
commit
423d4b8763
@ -78,6 +78,7 @@ if (is_ajax() === true) {
|
|||||||
0 => __('Group agents'),
|
0 => __('Group agents'),
|
||||||
1 => __('Group modules by tag'),
|
1 => __('Group modules by tag'),
|
||||||
2 => __('Group modules by module group'),
|
2 => __('Group modules by module group'),
|
||||||
|
3 => __('Group modules by agents'),
|
||||||
],
|
],
|
||||||
'type',
|
'type',
|
||||||
$type,
|
$type,
|
||||||
@ -203,6 +204,10 @@ if (is_ajax() === true) {
|
|||||||
'5'
|
'5'
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// Empty.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
@ -212,6 +217,7 @@ if (is_ajax() === true) {
|
|||||||
enterprise_include_once('include/functions_agents.php');
|
enterprise_include_once('include/functions_agents.php');
|
||||||
$id = get_parameter('id', 0);
|
$id = get_parameter('id', 0);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case 3:
|
||||||
case 2:
|
case 2:
|
||||||
$data = db_get_row('tagente_modulo', 'id_agente_modulo', $id);
|
$data = db_get_row('tagente_modulo', 'id_agente_modulo', $id);
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ class Heatmap
|
|||||||
ui_require_css_file('heatmap');
|
ui_require_css_file('heatmap');
|
||||||
|
|
||||||
$settings = [
|
$settings = [
|
||||||
'type' => 'POST',
|
'type' => 'GET',
|
||||||
'dataType' => 'html',
|
'dataType' => 'html',
|
||||||
'url' => ui_get_full_url(
|
'url' => ui_get_full_url(
|
||||||
'ajax.php',
|
'ajax.php',
|
||||||
@ -169,11 +169,41 @@ class Heatmap
|
|||||||
setting['data']['height'] = $(`#div_${randomId}`).height() + 10;
|
setting['data']['height'] = $(`#div_${randomId}`).height() + 10;
|
||||||
setting['data']['width'] = $(`#div_${randomId}`).width();
|
setting['data']['width'] = $(`#div_${randomId}`).width();
|
||||||
|
|
||||||
|
var totalModules = 0;
|
||||||
|
|
||||||
// Initial charge.
|
// Initial charge.
|
||||||
ajaxRequest(
|
$.ajax({
|
||||||
`div_${randomId}`,
|
type: setting.type,
|
||||||
setting
|
dataType: setting.dataType,
|
||||||
);
|
url: setting.url,
|
||||||
|
data: setting.data,
|
||||||
|
success: function(data) {
|
||||||
|
$(`#div_${randomId}`).append(data);
|
||||||
|
totalModules = $('rect').length;
|
||||||
|
let cont = 0;
|
||||||
|
while (cont < Math.ceil(totalModules / 10)) {
|
||||||
|
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
|
||||||
|
cont ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getRandomInteger(min, max) {
|
||||||
|
return Math.floor(Math.random() * max) + min;
|
||||||
|
}
|
||||||
|
|
||||||
|
function oneSquare(solid, time) {
|
||||||
|
var randomPoint = getRandomInteger(1, totalModules);
|
||||||
|
let target = $(`#${randomId}_${randomPoint}`);
|
||||||
|
setTimeout(function() {
|
||||||
|
let class_name = target.attr('class');
|
||||||
|
class_name = class_name.split(' ')[0];
|
||||||
|
const newClassName = class_name.split('_')[0];
|
||||||
|
target.removeClass(`${class_name} hover`);
|
||||||
|
target.addClass(`${newClassName}_${solid} hover`);
|
||||||
|
oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900));
|
||||||
|
}, time);
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh.
|
// Refresh.
|
||||||
setInterval(
|
setInterval(
|
||||||
@ -206,23 +236,29 @@ class Heatmap
|
|||||||
// randomly sort.
|
// randomly sort.
|
||||||
lista = lista.sort(function() {return Math.random() - 0.5});
|
lista = lista.sort(function() {return Math.random() - 0.5});
|
||||||
|
|
||||||
const countPerSecond = total / refresh;
|
let countPerSecond = total / refresh;
|
||||||
|
if (countPerSecond < 1) {
|
||||||
|
countPerSecond = 1;
|
||||||
|
}
|
||||||
|
|
||||||
let cont = 0;
|
let cont = 0;
|
||||||
let limit = countPerSecond - 1;
|
let limit = countPerSecond - 1;
|
||||||
|
|
||||||
const timer = setInterval(
|
const timer = setInterval(
|
||||||
function() {
|
function() {
|
||||||
while (cont <= limit) {
|
while (cont <= limit) {
|
||||||
$(`#${randomId}_${lista[cont]['id']}`).removeClass();
|
if (typeof lista[cont] !== 'undefined') {
|
||||||
$(`#${randomId}_${lista[cont]['id']}`).addClass(`${lista[cont]['status']} hover`);
|
const rect = document.getElementsByName(`${lista[cont]['id']}`);
|
||||||
|
$(`#${rect[0].id}`).removeClass();
|
||||||
cont++;
|
$(`#${rect[0].id}`).addClass(`${lista[cont]['status']} hover`);
|
||||||
}
|
}
|
||||||
limit = limit + countPerSecond;
|
|
||||||
},
|
cont++;
|
||||||
1000
|
}
|
||||||
);
|
limit = limit + countPerSecond;
|
||||||
|
},
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
function(){
|
function(){
|
||||||
@ -314,8 +350,10 @@ class Heatmap
|
|||||||
|
|
||||||
// All agents.
|
// All agents.
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'SELECT DISTINCT id_agente as id,alias,id_grupo,normal_count,warning_count,critical_count, unknown_count,notinit_count,total_count,fired_count,
|
'SELECT DISTINCT id_agente as id,alias,id_grupo,normal_count,warning_count,critical_count,
|
||||||
(SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente ORDER BY last_status_change DESC LIMIT 1) AS last_status_change
|
unknown_count,notinit_count,total_count,fired_count,
|
||||||
|
(SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente
|
||||||
|
ORDER BY last_status_change DESC LIMIT 1) AS last_status_change
|
||||||
FROM tagente WHERE `disabled` = 0 %s %s ORDER BY id_grupo,id_agente ASC',
|
FROM tagente WHERE `disabled` = 0 %s %s ORDER BY id_grupo,id_agente ASC',
|
||||||
$alias,
|
$alias,
|
||||||
$id_grupo
|
$id_grupo
|
||||||
@ -391,7 +429,8 @@ class Heatmap
|
|||||||
|
|
||||||
// All modules.
|
// All modules.
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'SELECT am.id_agente_modulo AS id, ae.known_status AS `status`, am.id_module_group AS id_grupo, ae.last_status_change FROM tagente_modulo am
|
'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_module_group AS id_grupo,
|
||||||
|
ae.last_status_change FROM tagente_modulo am
|
||||||
INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo
|
INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo
|
||||||
WHERE am.disabled = 0 %s %s GROUP BY am.id_module_group, am.id_agente_modulo',
|
WHERE am.disabled = 0 %s %s GROUP BY am.id_module_group, am.id_agente_modulo',
|
||||||
$filter_group,
|
$filter_group,
|
||||||
@ -489,7 +528,8 @@ class Heatmap
|
|||||||
|
|
||||||
// All modules.
|
// All modules.
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'SELECT ae.id_agente_modulo AS id, ae.known_status AS `status`, tm.id_tag AS id_grupo, ae.last_status_change FROM tagente_estado ae
|
'SELECT ae.id_agente_modulo AS id, ae.estado AS `status`, tm.id_tag AS id_grupo,
|
||||||
|
ae.last_status_change FROM tagente_estado ae
|
||||||
INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo
|
INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo
|
||||||
WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo',
|
WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo',
|
||||||
$filter_tag,
|
$filter_tag,
|
||||||
@ -567,6 +607,98 @@ class Heatmap
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all modules group by agents
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getAllModulesByAgents()
|
||||||
|
{
|
||||||
|
$filter_name = '';
|
||||||
|
if (empty($this->search) === false) {
|
||||||
|
$filter_name = 'AND nombre LIKE "%'.$this->search.'%"';
|
||||||
|
}
|
||||||
|
|
||||||
|
// All modules.
|
||||||
|
$sql = sprintf(
|
||||||
|
'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_agente AS id_grupo,
|
||||||
|
ae.last_status_change FROM tagente_modulo am
|
||||||
|
INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo
|
||||||
|
WHERE am.disabled = 0 %s GROUP BY ae.id_agente_modulo ORDER BY id_grupo',
|
||||||
|
$filter_name
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = db_get_all_rows_sql($sql);
|
||||||
|
|
||||||
|
// Module status.
|
||||||
|
foreach ($result as $key => $module) {
|
||||||
|
$status = '';
|
||||||
|
switch ($module['status']) {
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
||||||
|
case 1:
|
||||||
|
case 100:
|
||||||
|
$status = 'critical';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL:
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
||||||
|
case 0:
|
||||||
|
case 300:
|
||||||
|
$status = 'normal';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AGENT_MODULE_STATUS_WARNING:
|
||||||
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
||||||
|
case 2:
|
||||||
|
case 200:
|
||||||
|
$status = 'warning';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
||||||
|
case 3:
|
||||||
|
$status = 'unknown';
|
||||||
|
break;
|
||||||
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
||||||
|
case 5:
|
||||||
|
$status = 'notinit';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($module['last_status_change'] != 0) {
|
||||||
|
$seconds = (time() - $module['last_status_change']);
|
||||||
|
|
||||||
|
if ($seconds >= SECONDS_1DAY) {
|
||||||
|
$status .= '_10';
|
||||||
|
} else if ($seconds >= 77760) {
|
||||||
|
$status .= '_9';
|
||||||
|
} else if ($seconds >= 69120) {
|
||||||
|
$status .= '_8';
|
||||||
|
} else if ($seconds >= 60480) {
|
||||||
|
$status .= '_7';
|
||||||
|
} else if ($seconds >= 51840) {
|
||||||
|
$status .= '_6';
|
||||||
|
} else if ($seconds >= 43200) {
|
||||||
|
$status .= '_5';
|
||||||
|
} else if ($seconds >= 34560) {
|
||||||
|
$status .= '_4';
|
||||||
|
} else if ($seconds >= 25920) {
|
||||||
|
$status .= '_3';
|
||||||
|
} else if ($seconds >= 17280) {
|
||||||
|
$status .= '_2';
|
||||||
|
} else if ($seconds >= 8640) {
|
||||||
|
$status .= '_1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[$key]['status'] = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetData
|
* GetData
|
||||||
*
|
*
|
||||||
@ -575,6 +707,10 @@ class Heatmap
|
|||||||
public function getData()
|
public function getData()
|
||||||
{
|
{
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
|
case 3:
|
||||||
|
$data = $this->getAllModulesByAgents();
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$data = $this->getAllModulesByGroup();
|
$data = $this->getAllModulesByGroup();
|
||||||
break;
|
break;
|
||||||
@ -709,9 +845,10 @@ class Heatmap
|
|||||||
$groups = [];
|
$groups = [];
|
||||||
$contX = 0;
|
$contX = 0;
|
||||||
$contY = 0;
|
$contY = 0;
|
||||||
|
$cont = 1;
|
||||||
foreach ($result as $value) {
|
foreach ($result as $value) {
|
||||||
echo '<rect id="'.$this->randomId.'_'.$value['id'].'" class="'.$value['status'].' hover"
|
echo '<rect id="'.$this->randomId.'_'.$cont.'" class="'.$value['status'].' hover"
|
||||||
width="1" height="1" x ="'.$contX.' "y="'.$contY.'" />';
|
width="1" height="1" x ="'.$contX.' "y="'.$contY.'" name="'.$value['id'].'" />';
|
||||||
|
|
||||||
$contX++;
|
$contX++;
|
||||||
if ($contX >= $Xaxis) {
|
if ($contX >= $Xaxis) {
|
||||||
@ -724,14 +861,15 @@ class Heatmap
|
|||||||
} else {
|
} else {
|
||||||
$groups[$value['id_grupo']] += 1;
|
$groups[$value['id_grupo']] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cont++;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$('rect').click(function() {
|
$('rect').click(function() {
|
||||||
const type = <?php echo $this->type; ?>;
|
const type = <?php echo $this->type; ?>;
|
||||||
const hash = '<?php echo $this->randomId; ?>';
|
const id = $(`#${this.id}`).attr("name");
|
||||||
const id = this.id.replace(`${hash}_`, '');
|
|
||||||
|
|
||||||
$("#info_dialog").dialog({
|
$("#info_dialog").dialog({
|
||||||
resizable: true,
|
resizable: true,
|
||||||
@ -778,6 +916,10 @@ class Heatmap
|
|||||||
foreach ($groups as $key => $group) {
|
foreach ($groups as $key => $group) {
|
||||||
$name = '';
|
$name = '';
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
|
case 3:
|
||||||
|
$name = agents_get_alias($key);
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$name = modules_get_modulegroup_name($key);
|
$name = modules_get_modulegroup_name($key);
|
||||||
break;
|
break;
|
||||||
|
@ -91,6 +91,10 @@ if ($is_ajax === false && $pure === false) {
|
|||||||
|
|
||||||
$header_name = __('Heatmap view');
|
$header_name = __('Heatmap view');
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case 3:
|
||||||
|
$header_name .= ' - '.__('Agents');
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if (current($filter) == 0) {
|
if (current($filter) == 0) {
|
||||||
$header_name .= ' - '.__('Module group').': '.__('Not assigned');
|
$header_name .= ' - '.__('Module group').': '.__('Not assigned');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user