Merge branch 'ent-9456-giss-errores-en-la-paginacion-vista-alertas-metaconsola' into 'develop'

Fix alerts list pagination on meta

Ref: pandora_enterprise#9456

See merge request artica/pandorafms!5095
This commit is contained in:
Jimmy Olano 2022-09-27 14:10:47 +00:00
commit 09e934395f
3 changed files with 71 additions and 17 deletions

View File

@ -647,7 +647,12 @@ if ($get_agent_alerts_datatable === true) {
$order = get_datatable_order(true); $order = get_datatable_order(true);
$url = get_parameter('url', '#'); $url = get_parameter('url', '#');
$free_search_alert = $filter_alert['free_search_alert']; if (empty($filter_alert['free_search']) === false) {
$free_search_alert = $filter_alert['free_search'];
} else {
$free_search_alert = $filter_alert['free_search_alert'];
}
$idGroup = $filter_alert['ag_group']; $idGroup = $filter_alert['ag_group'];
$tag_filter = $filter_alert['tag_filter']; $tag_filter = $filter_alert['tag_filter'];
$action_filter = $filter_alert['action']; $action_filter = $filter_alert['action'];
@ -676,7 +681,7 @@ if ($get_agent_alerts_datatable === true) {
$selectLastFiredDown = false; $selectLastFiredDown = false;
switch ($sortField) { switch ($sortField) {
case 'module': case 'agent_module_name':
switch ($sort) { switch ($sort) {
case 'asc': case 'asc':
$selectModuleasc = $selected; $selectModuleasc = $selected;
@ -696,7 +701,7 @@ if ($get_agent_alerts_datatable === true) {
} }
break; break;
case 'template': case 'template_name':
switch ($sort) { switch ($sort) {
case 'asc': case 'asc':
$selectTemplateasc = $selected; $selectTemplateasc = $selected;
@ -736,7 +741,7 @@ if ($get_agent_alerts_datatable === true) {
} }
break; break;
case 'agent': case 'agent_name':
switch ($sort) { switch ($sort) {
case 'asc': case 'asc':
$selectLastFiredasc = $selected; $selectLastFiredasc = $selected;
@ -857,7 +862,7 @@ if ($get_agent_alerts_datatable === true) {
if (is_metaconsole() === true) { if (is_metaconsole() === true) {
include_once $config['homedir'].'/enterprise/meta/include/functions_alerts_meta.php'; include_once $config['homedir'].'/enterprise/meta/include/functions_alerts_meta.php';
if ($idAgent != 0) { if ($idAgent != 0) {
$alerts['alerts_simple'] = alerts_meta_get_alerts($agents, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); $alerts['alerts_simple'] = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter);
$countAlertsSimple = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); $countAlertsSimple = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter);
} else { } else {
@ -865,7 +870,7 @@ if ($get_agent_alerts_datatable === true) {
users_get_groups($config['id_user'], 'AR', false) users_get_groups($config['id_user'], 'AR', false)
); );
$alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); $alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter);
$countAlertsSimple = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); $countAlertsSimple = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter);
} }
@ -885,12 +890,60 @@ if ($get_agent_alerts_datatable === true) {
} }
} }
// Order and pagination metacosole.
if (is_metaconsole() === true) {
/**
* Auxiliar Ordenation function
*
* @param string $sort Direction of sort.
* @param string $sortField Field for perform the sorting.
*/
function arrayOutputSorting($sort, $sortField)
{
return function ($a, $b) use ($sort, $sortField) {
if ($sort === 'asc') {
if (is_string($a[$sortField]) === true) {
return strnatcasecmp($a[$sortField], $b[$sortField]);
} else {
return ($a[$sortField] - $b[$sortField]);
}
} else {
if (is_string($a[$sortField]) === true) {
return strnatcasecmp($b[$sortField], $a[$sortField]);
} else {
return ($a[$sortField] + $b[$sortField]);
}
}
};
}
// Status order.
if ($sortField === 'status') {
foreach ($alerts['alerts_simple'] as $i => $alert) {
if ($alert['times_fired'] > 0) {
$alerts['alerts_simple'][$i]['status'] = '3';
} else if ($alert['disabled'] > 0) {
$alerts['alerts_simple'][$i]['status'] = '1';
} else {
$alerts['alerts_simple'][$i]['status'] = '2';
}
}
}
usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField));
$alerts['alerts_simple'] = array_slice($alerts['alerts_simple'], $start, $length);
}
$data = []; $data = [];
if ($alerts['alerts_simple']) { if ($alerts['alerts_simple']) {
foreach ($alerts['alerts_simple'] as $alert) { foreach ($alerts['alerts_simple'] as $alert) {
$data[] = ui_format_alert_row($alert, true, $url, 'font-size: 7pt;'); $data[] = ui_format_alert_row($alert, true, $url, 'font-size: 7pt;');
} }
$data = array_reduce( $data = array_reduce(
$data, $data,
function ($carry, $row) { function ($carry, $row) {
@ -902,11 +955,11 @@ if ($get_agent_alerts_datatable === true) {
$tmp->policy = $row[0]; $tmp->policy = $row[0];
$tmp->standby = $row[1]; $tmp->standby = $row[1];
$tmp->force = $row[2]; $tmp->force = $row[2];
$tmp->agent = $row[3]; $tmp->agent_name = $row[3];
$tmp->module = $row[4]; $tmp->agent_module_name = $row[4];
$tmp->template = $row[5]; $tmp->template_name = $row[5];
$tmp->action = $row[6]; $tmp->action = $row[6];
$tmp->lastFired = $row[7]; $tmp->last_fired = $row[7];
$tmp->status = $row[8]; $tmp->status = $row[8];
$tmp->validate = $row[9]; $tmp->validate = $row[9];
@ -916,6 +969,7 @@ if ($get_agent_alerts_datatable === true) {
); );
} }
// Datatables format: RecordsTotal && recordsfiltered. // Datatables format: RecordsTotal && recordsfiltered.
echo json_encode( echo json_encode(
[ [

View File

@ -1075,7 +1075,7 @@ function ui_format_alert_row(
} }
} }
if (is_metaconsole() === true) { if (is_metaconsole() === true && (int) $server_id !== 0) {
$server = db_get_row('tmetaconsole_setup', 'id', $alert['server_data']['id']); $server = db_get_row('tmetaconsole_setup', 'id', $alert['server_data']['id']);
if (metaconsole_connect($server) == NOERR) { if (metaconsole_connect($server) == NOERR) {

View File

@ -294,7 +294,7 @@ if ($free_search != '') {
$columns = array_merge( $columns = array_merge(
$columns, $columns,
['agent'] ['agent_name']
); );
} }
@ -309,10 +309,10 @@ if ($free_search != '') {
$columns = array_merge( $columns = array_merge(
$columns, $columns,
['module'], ['agent_module_name'],
['template'], ['template_name'],
['action'], ['action'],
['lastFired'], ['last_fired'],
['status'] ['status']
); );
@ -359,7 +359,7 @@ if ($free_search != '') {
], ],
'drawCallback' => 'alerts_table_controls()', 'drawCallback' => 'alerts_table_controls()',
'order' => [ 'order' => [
'field' => 'module', 'field' => 'agent_module_name',
'direction' => 'asc', 'direction' => 'asc',
], ],
'zeroRecords' => __('No alerts found'), 'zeroRecords' => __('No alerts found'),
@ -400,7 +400,7 @@ if ($free_search != '') {
], ],
'drawCallback' => 'alerts_table_controls()', 'drawCallback' => 'alerts_table_controls()',
'order' => [ 'order' => [
'field' => 'module', 'field' => 'agent_module_name',
'direction' => 'asc', 'direction' => 'asc',
], ],
'zeroRecords' => __('No alerts found'), 'zeroRecords' => __('No alerts found'),