diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 2bcdbf7af4..5b7262be83 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -647,7 +647,12 @@ if ($get_agent_alerts_datatable === true) { $order = get_datatable_order(true); $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']; $tag_filter = $filter_alert['tag_filter']; $action_filter = $filter_alert['action']; @@ -676,7 +681,7 @@ if ($get_agent_alerts_datatable === true) { $selectLastFiredDown = false; switch ($sortField) { - case 'module': + case 'agent_module_name': switch ($sort) { case 'asc': $selectModuleasc = $selected; @@ -696,7 +701,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'template': + case 'template_name': switch ($sort) { case 'asc': $selectTemplateasc = $selected; @@ -736,7 +741,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'agent': + case 'agent_name': switch ($sort) { case 'asc': $selectLastFiredasc = $selected; @@ -857,7 +862,7 @@ if ($get_agent_alerts_datatable === true) { if (is_metaconsole() === true) { include_once $config['homedir'].'/enterprise/meta/include/functions_alerts_meta.php'; 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); } else { @@ -865,7 +870,7 @@ if ($get_agent_alerts_datatable === true) { 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); } @@ -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 = []; if ($alerts['alerts_simple']) { foreach ($alerts['alerts_simple'] as $alert) { $data[] = ui_format_alert_row($alert, true, $url, 'font-size: 7pt;'); } + $data = array_reduce( $data, function ($carry, $row) { @@ -902,11 +955,11 @@ if ($get_agent_alerts_datatable === true) { $tmp->policy = $row[0]; $tmp->standby = $row[1]; $tmp->force = $row[2]; - $tmp->agent = $row[3]; - $tmp->module = $row[4]; - $tmp->template = $row[5]; + $tmp->agent_name = $row[3]; + $tmp->agent_module_name = $row[4]; + $tmp->template_name = $row[5]; $tmp->action = $row[6]; - $tmp->lastFired = $row[7]; + $tmp->last_fired = $row[7]; $tmp->status = $row[8]; $tmp->validate = $row[9]; @@ -916,6 +969,7 @@ if ($get_agent_alerts_datatable === true) { ); } + // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 9db7f80fb7..cac764dfb3 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -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']); if (metaconsole_connect($server) == NOERR) { diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 65f8537b17..fc8446ca08 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -294,7 +294,7 @@ if ($free_search != '') { $columns = array_merge( $columns, - ['agent'] + ['agent_name'] ); } @@ -309,10 +309,10 @@ if ($free_search != '') { $columns = array_merge( $columns, - ['module'], - ['template'], + ['agent_module_name'], + ['template_name'], ['action'], - ['lastFired'], + ['last_fired'], ['status'] ); @@ -359,7 +359,7 @@ if ($free_search != '') { ], 'drawCallback' => 'alerts_table_controls()', 'order' => [ - 'field' => 'module', + 'field' => 'agent_module_name', 'direction' => 'asc', ], 'zeroRecords' => __('No alerts found'), @@ -400,7 +400,7 @@ if ($free_search != '') { ], 'drawCallback' => 'alerts_table_controls()', 'order' => [ - 'field' => 'module', + 'field' => 'agent_module_name', 'direction' => 'asc', ], 'zeroRecords' => __('No alerts found'),