From 544497d2ba21137f2d5580f85816eecfa9b1eb58 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 9 Sep 2022 13:07:36 +0200 Subject: [PATCH 1/6] Fix alerts list pagination on meta --- .../include/ajax/alert_list.ajax.php | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 2bcdbf7af4..bf2bf6bacc 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -857,7 +857,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 +865,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); } @@ -916,6 +916,39 @@ if ($get_agent_alerts_datatable === true) { ); } + 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 strnatcmp($a->$sortField, $b->$sortField); + } else { + return ($a->$sortField - $b->$sortField); + } + } else { + if (is_string($a->$sortField) === true) { + return strnatcmp($b->$sortField, $a->$sortField); + } else { + return ($a->$sortField + $b->$sortField); + } + } + }; + } + + + usort($data, arrayOutputSorting($sort, $sortField)); + $data = array_slice($data, $start, $length); + } + // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ From 56c5f324b07f254b3d39ff038ffe94bb7d7ba0ca Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 15 Sep 2022 18:01:16 +0200 Subject: [PATCH 2/6] Fix alerts metaconsole datatable order --- .../include/ajax/alert_list.ajax.php | 73 ++++++++++--------- .../operation/agentes/alerts_status.php | 8 +- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index bf2bf6bacc..b4c9fc571f 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -885,12 +885,47 @@ 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 strnatcmp($a[$sortField], $b[$sortField]); + } else { + return ($a[$sortField] - $b[$sortField]); + } + } else { + if (is_string($a[$sortField]) === true) { + return strnatcmp($b[$sortField], $a[$sortField]); + } else { + return ($a[$sortField] + $b[$sortField]); + } + } + }; + } + + + usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField)); + $data = 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,9 +937,9 @@ 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->status = $row[8]; @@ -916,38 +951,6 @@ if ($get_agent_alerts_datatable === true) { ); } - 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 strnatcmp($a->$sortField, $b->$sortField); - } else { - return ($a->$sortField - $b->$sortField); - } - } else { - if (is_string($a->$sortField) === true) { - return strnatcmp($b->$sortField, $a->$sortField); - } else { - return ($a->$sortField + $b->$sortField); - } - } - }; - } - - - usort($data, arrayOutputSorting($sort, $sortField)); - $data = array_slice($data, $start, $length); - } // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 65f8537b17..9dcc079baf 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,8 +309,8 @@ if ($free_search != '') { $columns = array_merge( $columns, - ['module'], - ['template'], + ['agent_module_name'], + ['template_name'], ['action'], ['lastFired'], ['status'] @@ -359,7 +359,7 @@ if ($free_search != '') { ], 'drawCallback' => 'alerts_table_controls()', 'order' => [ - 'field' => 'module', + 'field' => 'module_name', 'direction' => 'asc', ], 'zeroRecords' => __('No alerts found'), From c177ee2e2e4877e2d5eaf070edd261e5caa0190c Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 16 Sep 2022 15:01:52 +0200 Subject: [PATCH 3/6] Fix meta alert datatable order --- pandora_console/include/ajax/alert_list.ajax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index b4c9fc571f..6c16e9595d 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -900,13 +900,13 @@ if ($get_agent_alerts_datatable === true) { return function ($a, $b) use ($sort, $sortField) { if ($sort === 'asc') { if (is_string($a[$sortField]) === true) { - return strnatcmp($a[$sortField], $b[$sortField]); + return strcmp($a[$sortField], $b[$sortField]); } else { return ($a[$sortField] - $b[$sortField]); } } else { if (is_string($a[$sortField]) === true) { - return strnatcmp($b[$sortField], $a[$sortField]); + return strcmp($b[$sortField], $a[$sortField]); } else { return ($a[$sortField] + $b[$sortField]); } From bc5f1d0dce7d6bf001d35a51add3c1b7c530ad5b Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 19 Sep 2022 14:02:50 +0200 Subject: [PATCH 4/6] Fix meta alert datatable order --- pandora_console/include/ajax/alert_list.ajax.php | 6 +++--- pandora_console/include/functions_ui.php | 2 +- pandora_console/operation/agentes/alerts_status.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 6c16e9595d..227435858f 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -900,13 +900,13 @@ if ($get_agent_alerts_datatable === true) { return function ($a, $b) use ($sort, $sortField) { if ($sort === 'asc') { if (is_string($a[$sortField]) === true) { - return strcmp($a[$sortField], $b[$sortField]); + return strnatcasecmp($a[$sortField], $b[$sortField]); } else { return ($a[$sortField] - $b[$sortField]); } } else { if (is_string($a[$sortField]) === true) { - return strcmp($b[$sortField], $a[$sortField]); + return strnatcasecmp($b[$sortField], $a[$sortField]); } else { return ($a[$sortField] + $b[$sortField]); } @@ -916,7 +916,7 @@ if ($get_agent_alerts_datatable === true) { usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField)); - $data = array_slice($alerts['alerts_simple'], $start, $length); + $alerts['alerts_simple'] = array_slice($alerts['alerts_simple'], $start, $length); } $data = []; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d30171eba3..c368782489 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 9dcc079baf..4c2fa2bc73 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -359,7 +359,7 @@ if ($free_search != '') { ], 'drawCallback' => 'alerts_table_controls()', 'order' => [ - 'field' => 'module_name', + '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'), From 522607ec40eda77115e41e42c84dc8b47cf99861 Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 19 Sep 2022 14:14:33 +0200 Subject: [PATCH 5/6] Fix meta alert datatable order --- pandora_console/include/ajax/alert_list.ajax.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 227435858f..3b33031f0d 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -676,7 +676,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 +696,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'template': + case 'template_name': switch ($sort) { case 'asc': $selectTemplateasc = $selected; @@ -736,7 +736,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'agent': + case 'agent_name': switch ($sort) { case 'asc': $selectLastFiredasc = $selected; From 2a4176085fc1f33749b6535598e6d2f871070cf5 Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 26 Sep 2022 09:22:19 +0200 Subject: [PATCH 6/6] Fix alerts meta datatables --- .../include/ajax/alert_list.ajax.php | 22 +++++++++++++++++-- .../operation/agentes/alerts_status.php | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 3b33031f0d..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']; @@ -915,6 +920,19 @@ if ($get_agent_alerts_datatable === true) { } + // 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); } @@ -941,7 +959,7 @@ if ($get_agent_alerts_datatable === true) { $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]; diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 4c2fa2bc73..fc8446ca08 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -312,7 +312,7 @@ if ($free_search != '') { ['agent_module_name'], ['template_name'], ['action'], - ['lastFired'], + ['last_fired'], ['status'] );