ajaxMethods = ['getStatusHeatMap'];
ui_require_css_file('heatmap');
$this->title = __('Groups');
$this->total = $this->calculateTotalGroups();
}
/**
* Return the total groups.
*
* @return integer
*/
public function calculateTotalGroups():int
{
$total = db_get_value_sql('SELECT count(*) FROM tgrupo');
return $total;
}
/**
* Return the status groups in heat map.
*
* @return string
*/
public function getStatusHeatMap():string
{
global $config;
if (isset($config['id_group']) === false) {
$config['id_group'] = false;
}
$groups = users_get_groups($config['id_group'], 'AR', false);
if (is_array($groups) === true && count($groups) >= 10) {
return $this->getStatusHeatMapGroup();
}
$agents = agents_get_agents();
if (is_array($agents) === true && count($agents) >= 10) {
$this->title = __('My monitored agents');
return $this->getStatusHeatMapAgents().''.$this->title.'';
}
$this->title = __('My monitored modules');
return $this->getStatusHeatMapModules().''.$this->title.'';
}
/**
* Return the status modules in heatmap.
*
* @return string
*/
public function getStatusHeatMapModules():string
{
global $config;
$width = (int) get_parameter('width', 350);
$height = (int) get_parameter('height', 275);
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
$modules = modules_get_modules_in_group($id_groups);
$heatmap = '';
if (is_array($modules) === true) {
$total_groups = count($modules);
if ($total_groups === 0) {
return graph_nodata_image(['width' => '400']);
}
// Best square.
$high = (float) max($width, $height);
$low = 0.0;
while (abs($high - $low) > 0.000001) {
$mid = (($high + $low) / 2.0);
$midval = (floor($width / $mid) * floor($height / $mid));
if ($midval >= $total_groups) {
$low = $mid;
} else {
$high = $mid;
}
}
$square_length = min(($width / floor($width / $low)), ($height / floor($height / $low)));
// Print starmap.
$heatmap .= sprintf(
'';
return html_print_div(
[
'content' => $heatmap,
'style' => 'margin: 0 auto; width: fit-content; min-height: 285px;',
],
true
);
}
/**
* Return the status agents in heat map.
*
* @return string
*/
public function getStatusHeatMapAgents():string
{
global $config;
$width = get_parameter('width', 350);
$height = get_parameter('height', 275);
$id_groups = array_keys(users_get_groups($config['id_user'], 'AR', false));
if (in_array(0, $id_groups) === false) {
foreach ($id_groups as $key => $id_group) {
if ((bool) check_acl_restricted_all($config['id_user'], $id_group, 'AR') === false) {
unset($id_groups[$key]);
}
}
}
$id_groups = implode(',', $id_groups);
$sql = 'SELECT * FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
WHERE (g.id_group IN ('.$id_groups.') OR a.id_grupo IN ('.$id_groups.'))
AND a.disabled = 0';
$all_agents = db_get_all_rows_sql($sql);
if (empty($all_agents)) {
return null;
}
$total_agents = count($all_agents);
// Best square.
$high = (float) max($width, $height);
$low = 0.0;
while (abs($high - $low) > 0.000001) {
$mid = (($high + $low) / 2.0);
$midval = (floor($width / $mid) * floor($height / $mid));
if ($midval >= $total_agents) {
$low = $mid;
} else {
$high = $mid;
}
}
$square_length = min(($width / floor($width / $low)), ($height / floor($height / $low)));
// Print starmap.
$heatmap = sprintf(
'';
return html_print_div(
[
'content' => $heatmap,
'style' => 'margin: 0 auto; width: fit-content; min-height: 285px;',
],
true
);
}
/**
* Return the status groups in heat map.
*
* @return string
*/
public function getStatusHeatMapGroup():string
{
global $config;
$width = get_parameter('width', 350);
$height = get_parameter('height', 275);
// ACL Check.
$agent_a = check_acl($config['id_user'], 0, 'AR');
$agent_w = check_acl($config['id_user'], 0, 'AW');
$groups_list = groupview_get_groups_list(
$config['id_user'],
($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'),
true
);
$total_groups = $groups_list['counter'];
$groups = $groups_list['groups'];
// Best square.
$high = (float) max($width, $height);
$low = 0.0;
while (abs($high - $low) > 0.000001) {
$mid = (($high + $low) / 2.0);
$midval = (floor($width / $mid) * floor($height / $mid));
if ($midval >= $total_groups) {
$low = $mid;
} else {
$high = $mid;
}
}
$square_length = min(($width / floor($width / $low)), ($height / floor($height / $low)));
// Print starmap.
$heatmap = sprintf(
'';
return html_print_div(
[
'content' => $heatmap,
'style' => 'margin: 0 auto; width: fit-content; min-height: 285px;',
],
true
);
}
}