#12509 fixed status agents disabled

This commit is contained in:
Daniel Cebrian 2023-12-13 12:04:00 +01:00
parent 70d8b344b7
commit 6e246d5d29
4 changed files with 124 additions and 112 deletions

View File

@ -5115,7 +5115,8 @@ function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true,
FROM tagente a FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
LEFT JOIN tconfig_os os ON a.id_os = os.id_os LEFT JOIN tconfig_os os ON a.id_os = os.id_os
WHERE a.id_grupo IN (%s) OR g.id_group IN (%s) WHERE (a.id_grupo IN (%s) OR g.id_group IN (%s))
AND a.disabled = 0
GROUP BY os.id_os', GROUP BY os.id_os',
implode(',', $id_groups), implode(',', $id_groups),
implode(',', $id_groups) implode(',', $id_groups)
@ -5205,13 +5206,14 @@ function graph_events_agent_by_group($id_group, $width=300, $height=200, $noWate
// with it and then the number of times it occured. GROUP BY statement // with it and then the number of times it occured. GROUP BY statement
// is required if both DISTINCT() and COUNT() are in the statement. // is required if both DISTINCT() and COUNT() are in the statement.
$sql = sprintf( $sql = sprintf(
'SELECT DISTINCT(id_agente) AS id_agente, 'SELECT DISTINCT(te.id_agente) AS id_agente,
COUNT(id_agente) AS count COUNT(te.id_agente) AS count
FROM tevento te FROM tevento te
LEFT JOIN tagente a ON a.id_agente = te.id_agente
LEFT JOIN tagent_secondary_group g ON g.id_agent = te.id_agente LEFT JOIN tagent_secondary_group g ON g.id_agent = te.id_agente
WHERE 1=1 AND estado = 0 WHERE 1=1 AND estado = 0
%s %s %s %s AND a.disabled = 0
GROUP BY id_agente GROUP BY te.id_agente
ORDER BY count DESC LIMIT 8', ORDER BY count DESC LIMIT 8',
$tags_condition, $tags_condition,
$filter_groups $filter_groups

View File

@ -2503,7 +2503,8 @@ function groups_get_heat_map_agents(array $id_group, float $width=0, float $heig
$sql = 'SELECT * FROM tagente a $sql = 'SELECT * FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente
WHERE a.id_grupo IN ('.implode(',', $id_group).') OR g.id_group IN ('.implode(',', $id_group).')'; WHERE (a.id_grupo IN ('.implode(',', $id_group).') OR g.id_group IN ('.implode(',', $id_group).'))
AND a.disabled = 0';
$all_agents = db_get_all_rows_sql($sql); $all_agents = db_get_all_rows_sql($sql);
if (empty($all_agents)) { if (empty($all_agents)) {

View File

@ -352,6 +352,7 @@ class Agents extends Element
*/ */
public function getStatusGraph():string public function getStatusGraph():string
{ {
$data = [];
$agents = agents_get_agents( $agents = agents_get_agents(
false, false,
[ [
@ -435,13 +436,17 @@ class Agents extends Element
// To avoid that if a value is too small it is not seen. // To avoid that if a value is too small it is not seen.
$percentages = []; $percentages = [];
$total = array_sum($data); $total = array_sum($data);
foreach ($data as $key => $value) { if ($total > 0) {
$percentage = (($value / $total) * 100); foreach ($data as $key => $value) {
if ($percentage < 1 && $percentage > 0) { $percentage = (($value / $total) * 100);
$percentage = 1; if ($percentage < 1 && $percentage > 0) {
} $percentage = 1;
}
$percentages[$key] = format_numeric($percentage, 0); $percentages[$key] = format_numeric($percentage, 0);
}
} else {
$percentages = [];
} }
$data = $percentages; $data = $percentages;

View File

@ -113,116 +113,119 @@ class Groups extends Element
$id_groups = implode(',', $id_groups); $id_groups = implode(',', $id_groups);
$modules = modules_get_modules_in_group($id_groups); $modules = modules_get_modules_in_group($id_groups);
$total_groups = count($modules); $heatmap = '';
if ($total_groups === 0) { if (is_array($modules) === true) {
return graph_nodata_image(['width' => '400']); $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(
'<svg id="svg" style="width: %spx; height: %spx;">',
$width,
$height
);
$heatmap .= '<g>';
$row = 0;
$column = 0;
$x = 0;
$y = 0;
$cont = 1;
foreach ($modules as $key => $value) {
$module_id = $value['id_agente_modulo'];
$module_status = db_get_row(
'tagente_estado',
'id_agente_modulo',
$module_id,
);
$module_value = modules_get_last_value($module_id);
$status = '';
$title = '';
modules_get_status($module_id, $module_status['estado'], $module_value, $status, $title);
switch ($status) {
case STATUS_MODULE_NO_DATA:
// Not init status.
$status = 'notinit';
break;
case STATUS_MODULE_CRITICAL:
// Critical status.
$status = 'critical';
break;
case STATUS_MODULE_WARNING:
// Warning status.
$status = 'warning';
break;
case STATUS_MODULE_OK:
// Normal status.
$status = 'normal';
break;
case 3:
case -1:
default:
// Unknown status.
$status = 'unknown';
break;
} }
$redirect = ''; // Best square.
if (check_acl($config['id_user'], 0, 'AW')) { $high = (float) max($width, $height);
$redirect = 'onclick="redirectHeatmap(\'module\', '.$module_id.', '.$value['id_agente'].')"'; $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( $heatmap .= sprintf(
'<rect id="%s" x="%s" onmousemove="showLabel(this, event, \'%s\')" onmouseleave="hideLabel()" '.$redirect.' style="stroke-width:1;stroke:#ffffff" y="%s" row="%s" rx="3" ry="3" col="%s" width="%s" height="%s" class="scuare-status %s_%s"></rect>', '<svg id="svg" style="width: %spx; height: %spx;">',
'rect_'.$cont, $width,
$x, $height
$value['nombre'],
$y,
$row,
$column,
$square_length,
$square_length,
$status,
random_int(1, 10)
); );
$y += $square_length; $heatmap .= '<g>';
$row++; $row = 0;
if ((int) ($y + $square_length) > (int) $height) { $column = 0;
$y = 0; $x = 0;
$x += $square_length; $y = 0;
$row = 0; $cont = 1;
$column++; foreach ($modules as $key => $value) {
} $module_id = $value['id_agente_modulo'];
$module_status = db_get_row(
'tagente_estado',
'id_agente_modulo',
$module_id,
);
$module_value = modules_get_last_value($module_id);
$status = '';
$title = '';
modules_get_status($module_id, $module_status['estado'], $module_value, $status, $title);
switch ($status) {
case STATUS_MODULE_NO_DATA:
// Not init status.
$status = 'notinit';
break;
case STATUS_MODULE_CRITICAL:
// Critical status.
$status = 'critical';
break;
case STATUS_MODULE_WARNING:
// Warning status.
$status = 'warning';
break;
case STATUS_MODULE_OK:
// Normal status.
$status = 'normal';
break;
case 3:
case -1:
default:
// Unknown status.
$status = 'unknown';
break;
}
$redirect = '';
if (check_acl($config['id_user'], 0, 'AW')) {
$redirect = 'onclick="redirectHeatmap(\'module\', '.$module_id.', '.$value['id_agente'].')"';
}
$heatmap .= sprintf(
'<rect id="%s" x="%s" onmousemove="showLabel(this, event, \'%s\')" onmouseleave="hideLabel()" '.$redirect.' style="stroke-width:1;stroke:#ffffff" y="%s" row="%s" rx="3" ry="3" col="%s" width="%s" height="%s" class="scuare-status %s_%s"></rect>',
'rect_'.$cont,
$x,
$value['nombre'],
$y,
$row,
$column,
$square_length,
$square_length,
$status,
random_int(1, 10)
);
if ((int) ($x + $square_length) > (int) $width) {
$x = 0;
$y += $square_length; $y += $square_length;
$column = 0;
$row++; $row++;
} if ((int) ($y + $square_length) > (int) $height) {
$y = 0;
$x += $square_length;
$row = 0;
$column++;
}
$cont++; if ((int) ($x + $square_length) > (int) $width) {
$x = 0;
$y += $square_length;
$column = 0;
$row++;
}
$cont++;
}
} }
$heatmap .= '<script type="text/javascript"> $heatmap .= '<script type="text/javascript">
@ -289,7 +292,8 @@ class Groups extends Element
$sql = 'SELECT * FROM tagente a $sql = 'SELECT * FROM tagente a
LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente 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.')'; 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); $all_agents = db_get_all_rows_sql($sql);
if (empty($all_agents)) { if (empty($all_agents)) {
return null; return null;