#10347 added list agents in tactical view groups

This commit is contained in:
Daniel Cebrian 2023-03-02 13:48:14 +01:00
parent a4a5650a01
commit dc6256058f
4 changed files with 202 additions and 10 deletions

View File

@ -26,9 +26,6 @@
* ============================================================================
*/
// Test id group.
$id_group = 9;
global $config;
check_login();
@ -42,6 +39,11 @@ if (! check_acl($config['id_user'], 0, 'PM')) {
return;
}
$id_group = get_parameter('id', '');
if (empty($id_group) === true) {
return;
}
if (is_metaconsole() === false) {
// Header.
ui_print_standard_header(
@ -132,7 +134,7 @@ $events_by_agents_group .= '</td></tr></table>';
$table_col2->data[2][0] = $events_by_agents_group;
ui_toggle(
html_print_table($table_col2, true),
__('Alerts'),
__('Alerts and events'),
'',
'',
false,
@ -146,8 +148,46 @@ $table_col3->data = [];
$table_col3->rowclass[] = '';
$table_col3->headstyle[0] = 'text-align:center;';
$table_col3->width = '100%';
$table_col3->data[0][0] = 'En desarrollo';
try {
$columns = [
'alias',
'status',
'alerts',
'ultimo_contacto_remoto',
];
$columnNames = [
__('Alias'),
__('Status'),
__('Alerts'),
__('Ultimo contacto remoto'),
];
// Load datatables user interface.
$table_col3->data[3][0] = ui_print_datatable(
[
'id' => 'list_agents_tactical',
'class' => 'info_table',
'style' => 'width: 100%',
'columns' => $columns,
'column_names' => $columnNames,
'return' => true,
'ajax_url' => 'include/ajax/group',
'ajax_data' => [
'method' => 'getAgentsByGroup',
'id_group' => $id_group,
],
'no_sortable_columns' => [-1],
'order' => [
'field' => 'alias',
'direction' => 'asc',
],
]
);
} catch (Exception $e) {
echo $e->getMessage();
}
ui_toggle(
html_print_table($table_col3, true),

View File

@ -5341,7 +5341,7 @@ function get_baseline_data(
}
function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true)
function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true, $noWaterMark=true)
{
global $config;
@ -5379,10 +5379,12 @@ function graph_so_by_group($id_group, $width=300, $height=200, $recursive=true)
$data[] = $row['count'];
}
$water_mark = [
'file' => $config['homedir'].'/images/logo_vertical_water.png',
'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false),
];
if ($noWaterMark === false) {
$water_mark = [
'file' => $config['homedir'].'/images/logo_vertical_water.png',
'url' => ui_get_full_url('images/logo_vertical_water.png', false, false, false),
];
}
$options = [
'width' => $width,

View File

@ -48,6 +48,7 @@ class Group extends Entity
'distributionBySoGraph',
'groupEventsByAgent',
'loadInfoAgent',
'getAgentsByGroup',
];
@ -576,4 +577,150 @@ class Group extends Entity
}
public static function getAgentsByGroup()
{
global $config;
$data = [];
$id_group = get_parameter('id_group', '');
$id_groups = [$id_group];
$groups = groups_get_children($id_group);
if (count($groups) > 0) {
$id_groups = [];
foreach ($groups as $key => $value) {
$id_groups[] = $value['id_grupo'];
}
}
$start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']);
$orderDatatable = get_datatable_order(true);
$pagination = '';
$order = '';
try {
ob_start();
if (isset($orderDatatable)) {
switch ($orderDatatable['field']) {
case 'alerts':
$orderDatatable['field'] = 'fired_count';
break;
case 'status':
$orderDatatable['field'] = 'total_count';
default:
$orderDatatable['field'] = $orderDatatable['field'];
break;
}
$order = sprintf(
' ORDER BY %s %s',
$orderDatatable['field'],
$orderDatatable['direction']
);
}
if (isset($length) && $length > 0
&& isset($start) && $start >= 0
) {
$pagination = sprintf(
' LIMIT %d OFFSET %d ',
$length,
$start
);
}
$sql = sprintf(
'SELECT alias,
critical_count,
warning_count,
unknown_count,
total_count,
notinit_count,
ultimo_contacto_remoto,
fired_count
FROM tagente t
WHERE disabled = 0 AND
total_count <> notinit_count AND
id_grupo IN (%s)
%s %s',
implode(',', $id_groups),
$order,
$pagination
);
$data = db_get_all_rows_sql($sql);
$sql = sprintf(
'SELECT alias,
critical_count,
warning_count,
unknown_count,
total_count,
notinit_count,
ultimo_contacto_remoto,
fired_count
FROM tagente t
WHERE disabled = 0 AND
total_count <> notinit_count AND
id_grupo IN (%s)
%s',
implode(',', $id_groups),
$order,
);
$count_agents = db_get_num_rows($sql);
foreach ($data as $key => $agent) {
$status_img = agents_tree_view_status_img(
$agent['critical_count'],
$agent['warning_count'],
$agent['unknown_count'],
$agent['total_count'],
$agent['notinit_count']
);
$data[$key]['alias'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=main&id_agente='.$agent['id_agente'].'"><b>'.$agent['alias'].'</b></a>';
$data[$key]['status'] = $status_img;
$data[$key]['alerts'] = agents_tree_view_alert_img($agent['fired_count']);
}
if (empty($data) === true) {
$total = 0;
$data = [];
} else {
$total = $count_agents;
}
echo json_encode(
[
'data' => $data,
'recordsTotal' => $total,
'recordsFiltered' => $total,
]
);
// Capture output.
$response = ob_get_clean();
} catch (\Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
exit;
}
json_decode($response);
if (json_last_error() === JSON_ERROR_NONE) {
echo $response;
} else {
echo json_encode(
[
'success' => false,
'error' => $response,
]
);
}
exit;
}
}

View File

@ -23,3 +23,6 @@ rect {
#modal-info-agent {
display: none;
}
#list_agents_tactical_wrapper {
max-height: 600px;
}