diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php
index 46071914fc..18f8c12528 100644
--- a/pandora_console/include/ajax/events.php
+++ b/pandora_console/include/ajax/events.php
@@ -94,6 +94,7 @@ if ($get_comments === true) {
$eventsGrouped = [];
// Consider if the event is grouped.
+ $whereGrouped = '1=1';
if (isset($event['event_rep']) === true && $event['event_rep'] > 0) {
// Default grouped message filtering (evento and estado).
$whereGrouped = sprintf(
@@ -117,39 +118,39 @@ if ($get_comments === true) {
(int) $event['id_agentmodule']
);
}
+ }
- try {
- if (is_metaconsole() === true
- && $event['server_id'] > 0
- ) {
- $node = new Node($event['server_id']);
- $node->connect();
- }
+ try {
+ if (is_metaconsole() === true
+ && $event['server_id'] > 0
+ ) {
+ $node = new Node($event['server_id']);
+ $node->connect();
+ }
- $sql = sprintf(
- 'SELECT `user_comment`
- FROM tevento
- WHERE %s',
- $whereGrouped
- );
+ $sql = sprintf(
+ 'SELECT `user_comment`
+ FROM tevento
+ WHERE %s',
+ $whereGrouped
+ );
- // Get grouped comments.
- $eventsGrouped = db_get_all_rows_sql($sql);
- } catch (\Exception $e) {
- // Unexistent agent.
- if (is_metaconsole() === true
- && $event['server_id'] > 0
- ) {
- $node->disconnect();
- }
+ // Get grouped comments.
+ $eventsGrouped = db_get_all_rows_sql($sql);
+ } catch (\Exception $e) {
+ // Unexistent agent.
+ if (is_metaconsole() === true
+ && $event['server_id'] > 0
+ ) {
+ $node->disconnect();
+ }
- $eventsGrouped = [];
- } finally {
- if (is_metaconsole() === true
- && $event['server_id'] > 0
- ) {
- $node->disconnect();
- }
+ $eventsGrouped = [];
+ } finally {
+ if (is_metaconsole() === true
+ && $event['server_id'] > 0
+ ) {
+ $node->disconnect();
}
}
diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php
index 4979ddfdd2..42c6a965cd 100644
--- a/pandora_console/include/functions_api.php
+++ b/pandora_console/include/functions_api.php
@@ -17395,7 +17395,7 @@ function util_api_check_agent_and_print_error($id_agent, $returnType, $access='A
* Function for get event id and node id, then we get in return the Metaconsole event ID.
*
* @param [string] $server_id id server (Node)
- * @param [string] $console_event_id console Id node event in tmetaconsole_event
+ * @param [string] $console_event_id console Id node event in tevent
* @param [string] $trash2 don't use
* @param [string] $returnType
*
@@ -17406,19 +17406,54 @@ function util_api_check_agent_and_print_error($id_agent, $returnType, $access='A
*/
function api_get_event_mcid($server_id, $console_event_id, $trash2, $returnType)
{
- global $config;
+ try {
+ if (is_metaconsole() === true
+ && $server_id > 0
+ ) {
+ $node = new Node($server_id);
+ $node->connect();
+ }
+
+ // Get grouped comments.
+ $mc_event_id = db_get_all_rows_sql(
+ sprintf(
+ 'SELECT id_evento
+ FROM tevento
+ WHERE id_evento = %d
+ ',
+ $console_event_id
+ )
+ );
- if (is_metaconsole()) {
- $mc_event_id = db_get_all_rows_sql("SELECT id_evento FROM tmetaconsole_event WHERE id_source_event = $console_event_id AND server_id = $server_id ");
if ($mc_event_id !== false) {
- returnData($returnType, ['type' => 'string', 'data' => $mc_event_id]);
+ returnData(
+ $returnType,
+ [
+ 'type' => 'string',
+ 'data' => $mc_event_id,
+ ]
+ );
} else {
returnError('id_not_found', 'string');
}
- } else {
+ } catch (\Exception $e) {
+ // Unexistent agent.
+ if (is_metaconsole() === true
+ && $server_id > 0
+ ) {
+ $node->disconnect();
+ }
+
returnError('forbidden', 'string');
- return;
+ } finally {
+ if (is_metaconsole() === true
+ && $server_id > 0
+ ) {
+ $node->disconnect();
+ }
}
+
+ return;
}
diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php
index 464d62b02b..749839d513 100644
--- a/pandora_console/include/functions_events.php
+++ b/pandora_console/include/functions_events.php
@@ -1336,7 +1336,6 @@ function events_get_all(
if (is_metaconsole() === true
&& empty($id_server) === true
&& isset($filter['csv_all']) === false
- && $filter['csv_all'] !== 1
) {
// TODO: XXX TIP. captura el error.
$pagination = sprintf(
@@ -1350,6 +1349,10 @@ function events_get_all(
// Group by.
$group_by = 'GROUP BY ';
$tagente_join = 'LEFT';
+ if (isset($filter['group_rep']) === false) {
+ $filter['group_rep'] = 0;
+ }
+
switch ($filter['group_rep']) {
case '0':
default:
@@ -1639,7 +1642,6 @@ function events_get_all(
if (isset($limit, $offset) === true
&& $limit !== 0
&& isset($filter['csv_all']) === false
- && $filter['csv_all'] !== 1
) {
$count = count($data);
$end = ((int) $offset !== 0) ? ($offset + $limit) : $limit;
diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php
index 7e8d8c1509..49cfaf0f3f 100755
--- a/pandora_console/include/functions_ui.php
+++ b/pandora_console/include/functions_ui.php
@@ -3254,7 +3254,7 @@ function ui_print_datatable(array $parameters)
$parameters['paging'] = true;
}
- $no_sortable_columns = [];
+ $no_sortable_columns = json_encode([]);
if (isset($parameters['no_sortable_columns'])) {
$no_sortable_columns = json_encode($parameters['no_sortable_columns']);
}
@@ -3326,6 +3326,11 @@ function ui_print_datatable(array $parameters)
$parameters['datacolumns'] = $parameters['columns'];
}
+ if (isset($parameters['csv']) === false) {
+ $parameters['csv'] = 1;
+ }
+
+ $filter = '';
// Datatable filter.
if (isset($parameters['form']) && is_array($parameters['form'])) {
if (isset($parameters['form']['id'])) {
@@ -3496,7 +3501,7 @@ function ui_print_datatable(array $parameters)
language: {
processing:"'.$processing.'"
},
- buttons: [
+ buttons: '.$parameters['csv'].'== 1 ? [
{
extend: "csv",
text : "'.__('Export current page to CSV').'",
@@ -3512,7 +3517,7 @@ function ui_print_datatable(array $parameters)
}'.$export_columns.'
}
}
- ],
+ ] : [],
lengthMenu: '.json_encode($pagination_options).',
ajax: {
url: "'.ui_get_full_url('ajax.php', false, false, false).'",
diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js
index a4a8889361..5b325762ce 100644
--- a/pandora_console/include/javascript/pandora_dashboards.js
+++ b/pandora_console/include/javascript/pandora_dashboards.js
@@ -1387,131 +1387,6 @@ function dashboardLoadVC(settings) {
});
}
-// eslint-disable-next-line no-unused-vars
-function dashboardShowEventDialog(settings) {
- settings = JSON.parse(atob(settings));
- var dialog_exist = $("div[aria-describedby='event_details_window']");
- if (dialog_exist.length == 1) {
- $("div[aria-describedby='event_details_window']").remove();
- }
- $.ajax({
- method: "post",
- url: settings.ajaxUrl,
- data: {
- page: settings.page,
- get_extended_event: 1,
- event: settings.event,
- dialog_page: "",
- meta: 0,
- history: 0,
- filter: [],
- node_id: settings.node_id
- },
- dataType: "html",
- success: function(data) {
- $("#event_details_window")
- .hide()
- .empty()
- .append(data)
- .dialog({
- title: settings.event.evento,
- resizable: true,
- draggable: true,
- modal: true,
- create: function() {
- $("#button-delete_button").removeAttr("onclick");
- $("#button-delete_button").click(function() {
- var confirm_message = $("#hidden-delete_confirm_message").val();
- if (confirm(confirm_message) == false) {
- return false;
- }
- $.ajax({
- method: "post",
- url: settings.ajaxUrl,
- data: {
- page: "include/ajax/events",
- delete_event: 1,
- node_id: settings.node_id,
- id_evento: settings.event.id_evento,
- filter: []
- },
- success: function() {
- $("#notification_delete_error").show();
- $("#event_details_window").dialog("close");
- },
- error: function(error) {
- console.error(error);
- }
- });
- });
- },
- close: function() {
- //$("#refrcounter").countdown("resume");
- //$("div.vc-countdown").countdown("resume");
- $.ajax({
- method: "post",
- url: settings.ajaxUrl,
- data: {
- page: "operation/dashboard/dashboard",
- method: "drawWidget",
- dashboardId: settings.dashboardId,
- cellId: settings.cellId,
- widgetId: settings.widgetId,
- redraw: 1
- },
- success: function(dataWidget) {
- // Widget empty and reload.
- $("#widget-" + settings.cellId + " .content-widget").empty();
- $("#widget-" + settings.cellId + " .content-widget").append(
- dataWidget
- );
- },
- error: function(error) {
- console.error(error);
- }
- });
- },
- overlay: {
- opacity: 0.5,
- background: "black"
- },
- width: 710,
- height: 600
- })
- .show();
-
- //$("#refrcounter").countdown("pause");
- //$("div.vc-countdown").countdown("pause");
-
- switch (settings.result) {
- case "comment_ok":
- $("#notification_comment_success").show();
- break;
- case "comment_error":
- $("#notification_comment_error").show();
- break;
- case "status_ok":
- $("#notification_status_success").show();
- break;
- case "status_error":
- $("#notification_status_error").show();
- break;
- case "owner_ok":
- $("#notification_owner_success").show();
- break;
- case "owner_error":
- $("#notification_owner_error").show();
- break;
- }
-
- forced_title_callback();
- },
- error: function(error) {
- console.error(error);
- }
- });
-}
-
// eslint-disable-next-line no-unused-vars
function dashboardInitTinyMce(url) {
// Initialice.
diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js
index 1ffab23603..4aefad62c2 100644
--- a/pandora_console/include/javascript/pandora_events.js
+++ b/pandora_console/include/javascript/pandora_events.js
@@ -1,7 +1,7 @@
-/*global jQuery, $, forced_title_callback, dt_events, confirmDialog*/
+/*global jQuery, $, forced_title_callback, confirmDialog*/
// Show the modal window of an event
-function show_event_dialog(event, dialog_page, result) {
+function show_event_dialog(event, dialog_page) {
var ajax_file = $("#hidden-ajax_file").val();
if (dialog_page == undefined) {
@@ -85,6 +85,7 @@ function show_event_dialog(event, dialog_page, result) {
$("#refrcounter").countdown("pause");
$("div.vc-countdown").countdown("pause");
+ /*
switch (result) {
case "comment_ok":
$("#notification_comment_success").show();
@@ -105,6 +106,7 @@ function show_event_dialog(event, dialog_page, result) {
$("#notification_owner_error").show();
break;
}
+ */
forced_title_callback();
},
@@ -675,7 +677,9 @@ function update_event(table, id_evento, type, event_rep, row, server_id) {
redraw = true;
}
if (redraw) {
- table.draw(false);
+ $("#" + table)
+ .DataTable()
+ .draw(false);
} else {
$(row)
.closest("tr")
@@ -692,6 +696,11 @@ function update_event(table, id_evento, type, event_rep, row, server_id) {
function validate_event(table, id_evento, event_rep, row, server_id) {
var button = document.getElementById("val-" + id_evento);
+ var meta = $("#hidden-meta").val();
+ if (meta) {
+ button = document.getElementById("val-" + id_evento + "-" + server_id);
+ }
+
if (!button) {
// Button does not exist. Ignore.
processed += 1;
@@ -712,6 +721,11 @@ function validate_event(table, id_evento, event_rep, row, server_id) {
function in_process_event(table, id_evento, event_rep, row, server_id) {
var button = document.getElementById("proc-" + id_evento);
+ var meta = $("#hidden-meta").val();
+ if (meta) {
+ button = document.getElementById("proc-" + id_evento + "-" + server_id);
+ }
+
if (!button) {
// Button does not exist. Ignore.
processed += 1;
@@ -732,6 +746,11 @@ function in_process_event(table, id_evento, event_rep, row, server_id) {
function delete_event(table, id_evento, event_rep, row, server_id) {
var button = document.getElementById("del-" + id_evento);
+ var meta = $("#hidden-meta").val();
+ if (meta) {
+ button = document.getElementById("del-" + id_evento + "-" + server_id);
+ }
+
if (!button) {
// Button does not exist. Ignore.
processed += 1;
@@ -771,6 +790,11 @@ function execute_delete_event_reponse(
server_id
) {
var button = document.getElementById("del-" + id_evento);
+ var meta = $("#hidden-meta").val();
+ if (meta) {
+ button = document.getElementById("del-" + id_evento + "-" + server_id);
+ }
+
if (!button) {
// Button does not exist. Ignore.
processed += 1;
@@ -868,17 +892,22 @@ function execute_event_response(event_list_btn) {
});
}
} else {
- var event_id = $(this).val();
- var server_id = $("#hidden-server_id_" + event_id).val();
-
// It is not a custom response
switch (response_id) {
case "in_progress_selected":
$(".chk_val:checked").each(function() {
- // Parent: TD. GrandParent: TR.
+ var event_id = $(this).val();
+ var meta = $("#hidden-meta").val();
+ var server_id = 0;
+ if (meta) {
+ var split_id = event_id.split("|");
+ event_id = split_id[0];
+ server_id = split_id[1];
+ }
+
in_process_event(
- dt_events,
- $(this).val(),
+ "events",
+ event_id,
$(this).attr("event_rep"),
this.parentElement.parentElement,
server_id
@@ -887,8 +916,17 @@ function execute_event_response(event_list_btn) {
break;
case "validate_selected":
$(".chk_val:checked").each(function() {
+ var event_id = $(this).val();
+ var meta = $("#hidden-meta").val();
+ var server_id = 0;
+ if (meta) {
+ var split_id = event_id.split("|");
+ event_id = split_id[0];
+ server_id = split_id[1];
+ }
+
validate_event(
- dt_events,
+ "events",
event_id,
$(this).attr("event_rep"),
this.parentElement.parentElement,
@@ -898,8 +936,17 @@ function execute_event_response(event_list_btn) {
break;
case "delete_selected":
$(".chk_val:checked").each(function() {
+ var event_id = $(this).val();
+ var meta = $("#hidden-meta").val();
+ var server_id = 0;
+ if (meta) {
+ var split_id = event_id.split("|");
+ event_id = split_id[0];
+ server_id = split_id[1];
+ }
+
execute_delete_event_reponse(
- dt_events,
+ "events",
event_id,
$(this).attr("event_rep"),
this.parentElement.parentElement,
@@ -931,7 +978,9 @@ function check_massive_response_event(
var meta = $("#hidden-meta").val();
var server_id = 0;
if (meta) {
- server_id = $("#hidden-server_id_" + event_id).val();
+ var split_id = event_id.split("|");
+ event_id = split_id[0];
+ server_id = split_id[1];
}
response["target"] = get_response_target(
@@ -958,3 +1007,41 @@ function event_widget_options() {
$(".event-widget-input").enable();
}
}
+
+function process_buffers(buffers) {
+ $("#events_buffers_display").empty();
+ if (buffers != null && buffers.settings != undefined && buffers.data) {
+ var html = "
" + buffers.settings.translate.nev;
+ html += ": (" + buffers.settings.total + ") ";
+ html += "";
+ Object.entries(buffers.data).forEach(function(element) {
+ html += "";
+ html += "";
+ html += buffers.settings.translate.ev + " ";
+ html += element[0];
+ html += ": ";
+ html += " ";
+
+ var class_total = "info";
+ var str_total = "";
+ if (buffers.settings.total == element[1]) {
+ class_total += " danger";
+ str_total = buffers.settings.translate.tevn;
+ }
+ html += '';
+ html += element[1];
+ if (str_total != "") {
+ html += '';
+ html += " " + str_total;
+ html += " ";
+ }
+
+ html += " ";
+
+ html += " ";
+ });
+ html += " ";
+
+ $("#events_buffers_display").html(html);
+ }
+}
diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php
index 8242b1d227..acdf98ccb8 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php
@@ -501,8 +501,6 @@ class EventsListWidget extends Widget
$output = '';
\ui_require_css_file('events', 'include/styles/', true);
- \ui_require_css_file('tables', 'include/styles/', true);
- \ui_require_javascript_file('pandora_events');
\ui_require_javascript_file('pandora_events', 'include/javascript/', true);
$this->values['groupId'] = explode(',', $this->values['groupId'][0]);
@@ -536,7 +534,7 @@ class EventsListWidget extends Widget
io_safe_output($filter['tag_without'])
);
- if (!empty($filter['id_agent_module'])) {
+ if (empty($filter['id_agent_module']) === false) {
$name = \modules_get_modules_name(
' FROM tagente_modulo',
' WHERE id_agente_modulo = '.$filter['id_agent_module'],
@@ -581,221 +579,100 @@ class EventsListWidget extends Widget
}
}
- // Order.
- $order['field'] = 'timestamp';
- $order['direction'] = 'DESC';
-
- $fields = [
- 'te.id_evento',
- 'te.id_agente',
- 'te.id_usuario',
- 'te.id_grupo',
- 'te.estado',
- 'te.timestamp',
- 'te.evento',
- 'te.utimestamp',
- 'te.event_type',
- 'te.id_alert_am',
- 'te.criticity',
- 'te.user_comment',
- 'te.tags',
- 'te.source',
- 'te.id_extra',
- 'te.critical_instructions',
- 'te.warning_instructions',
- 'te.unknown_instructions',
- 'te.owner_user',
- 'if(te.ack_utimestamp > 0, from_unixtime(te.ack_utimestamp),"") as ack_utimestamp',
- 'te.custom_data',
- 'te.data',
- 'te.module_status',
- 'ta.alias as agent_name',
- 'tg.nombre as group_name',
+ $default_fields = [
+ [
+ 'text' => 'evento',
+ 'class' => 'mw120px',
+ ],
+ [
+ 'text' => 'mini_severity',
+ 'class' => 'no-padding',
+ ],
+ 'id_evento',
+ 'agent_name',
+ 'timestamp',
+ 'event_type',
+ [
+ 'text' => 'options',
+ 'class' => 'action_buttons w120px',
+ ],
];
+ $fields = explode(',', $config['event_fields']);
- $home_url = $config['homeurl'];
+ // Always check something is shown.
+ if (empty($fields) === true) {
+ $fields = $default_fields;
+ }
- $fields[] = 'am.nombre as module_name';
- $fields[] = 'am.id_agente_modulo as id_agentmodule';
- $fields[] = 'am.custom_id as module_custom_id';
- $fields[] = 'ta.server_name as server_name';
+ // Get column names.
+ $column_names = events_get_column_names($fields, true);
- $events = \events_get_all(
- // Fields.
- $fields,
- // Filter.
- $filter,
- // Offset.
- 0,
- // Limit.
- $this->values['limit'],
- // Order.
- $order['direction'],
- // Sort field.
- $order['field'],
- // History.
- false,
- // SQL.
- false,
- // Having.
- '',
- // ValidatedEvents.
- false,
- // Recursive Groups.
- (bool) $this->values['groupRecursion'],
- // Already connected.
- // ($this->nodeId > 0)
+ // AJAX call options responses.
+ $output .= '
';
+ $output .= '
';
+ $output .= '
';
+ $output .= \html_print_input_hidden(
+ 'ajax_file',
+ \ui_get_full_url('ajax.php', false, false, false),
+ true
);
- if (is_metaconsole() === true
- && empty($filter['server_id']) !== false
- ) {
- $events = $events['data'];
- }
+ $output .= \html_print_input_hidden(
+ 'meta',
+ is_metaconsole(),
+ true
+ );
- if ($events === false) {
- $events = [];
- }
+ $output .= \html_print_input_hidden(
+ 'delete_confirm_message',
+ __('Are you sure?'),
+ true
+ );
- $i = 0;
- if (isset($events) === true
- && is_array($events) === true
- && empty($events) === false
- ) {
- $output .= \html_print_input_hidden(
- 'ajax_file',
- \ui_get_full_url('ajax.php', false, false, false),
- true
- );
+ $table_id = 'dashboard_list_events_'.$this->cellId;
- $output .= \html_print_input_hidden(
- 'meta',
- is_metaconsole(),
- true
- );
-
- $output .= \html_print_input_hidden(
- 'delete_confirm_message',
- __('Are you sure?'),
- true
- );
-
- $table = new \StdClass;
- $table->class = 'widget_groups_status databox';
- $table->cellspacing = '1';
- $table->width = '100%';
- $table->data = [];
- $table->size = [];
- $table->rowclass = [];
-
- // If its node, get direccion value and construct rute.
- if ($this->nodeId !== null && $this->nodeId > 0) {
- metaconsole_restore_db();
- $result = db_get_all_rows_sql('SELECT server_url FROM tmetaconsole_setup WHERE id = '.$this->nodeId.'');
- $home_url = $result[0]['server_url'];
- metaconsole_connect(null, $this->nodeId);
- }
-
- hd($events, true);
-
- foreach ($events as $event) {
- $data = [];
- $event['evento'] = \io_safe_output($event['evento']);
-
- $data[0] = \events_print_type_img($event['event_type'], true);
- $agent_alias = \agents_get_alias($event['id_agente']);
-
- if ($agent_alias !== '') {
- $data[1] = '';
- $data[1] .= $agent_alias;
- $data[1] .= ' ';
- } else {
- $data[1] = ' ';
- }
-
- if (isset($event['event_rep']) === true
- && $event['event_rep'] > 1
- ) {
- $data[1] .= ' ('.$event['event_rep'].')';
- }
-
- // Group.
- $data[2] = $event['group_name'];
-
- // Tags.
- $data[3] = $event['tags'];
-
- $settings = json_encode(
+ // Print datatable.
+ $output .= ui_print_datatable(
+ [
+ 'id' => $table_id,
+ 'class' => 'info_table events',
+ 'style' => 'width: 100%;',
+ 'ajax_url' => 'operation/events/events',
+ 'ajax_data' => [
+ 'get_events' => 1,
+ 'table_id' => $table_id,
+ 'filter' => $filter,
+ 'length' => $this->values['limit'],
+ 'groupRecursion' => (bool) $this->values['groupRecursion'],
+ ],
+ 'default_pagination' => $this->values['limit'],
+ 'pagination_options' => [
[
- 'event' => $event,
- 'page' => 'include/ajax/events',
- 'cellId' => $this->cellId,
- 'ajaxUrl' => \ui_get_full_url(
- 'ajax.php',
- false,
- false,
- false
- ),
- 'result' => false,
- 'dashboardId' => $this->dashboardId,
- 'widgetId' => $this->widgetId,
- 'cellId' => $this->cellId,
- 'node_id' => $this->nodeId,
- ]
- );
-
- if ($this->publicLink === false) {
- $data[4] = '';
- }
-
- $data[4] .= substr(\io_safe_output($event['evento']), 0, 150);
- if (strlen($event['evento']) > 150) {
- $data[4] .= '...';
- }
-
- if ($this->publicLink === false) {
- $data[4] .= ' ';
- }
-
- $data[5] = \ui_print_timestamp($event['timestamp'], true);
-
- $table->data[$i] = $data;
-
- $bg_color = 'background: #E8E8E8;';
- if ($config['style'] === 'pandora_black' && !is_metaconsole()) {
- $bg_color = 'background: #222;';
- }
-
- $table->cellstyle[$i][0] = $bg_color;
- $rowclass = \events_get_criticity_class($event['criticity']);
- $table->cellclass[$i][1] = $rowclass;
- $table->cellclass[$i][2] = $rowclass;
- $table->cellclass[$i][3] = $rowclass;
- $table->cellclass[$i][4] = $rowclass;
- $table->cellclass[$i][5] = $rowclass;
- $i++;
- }
-
- $output .= \html_print_table($table, true);
- $output .= "
";
- $output .= "
";
- $output .= "
";
- } else {
- $output .= '';
- $output .= \ui_print_info_message(
- \__('There are no events matching selected search filters'),
- '',
- true
- );
- $output .= '
';
- }
+ $this->values['limit'],
+ 10,
+ 25,
+ 100,
+ ],
+ [
+ $this->values['limit'],
+ 10,
+ 25,
+ 100,
+ ],
+ ],
+ 'order' => [
+ 'field' => 'timestamp',
+ 'direction' => 'desc',
+ ],
+ 'column_names' => $column_names,
+ 'columns' => $fields,
+ 'ajax_return_operation' => 'buffers',
+ 'ajax_return_operation_function' => 'process_buffers',
+ // 'drawCallback' => 'process_datatables_callback(this, settings)',
+ 'return' => true,
+ 'csv' => 0,
+ ]
+ );
return $output;
}
diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css
index b6b774c208..f6a280dd50 100644
--- a/pandora_console/include/styles/dashboards.css
+++ b/pandora_console/include/styles/dashboards.css
@@ -572,3 +572,8 @@ div#main_pure {
#main_page > .ui-content div.label > p {
margin: 0;
}
+
+.content-widget .dataTables_wrapper {
+ width: 98%;
+ margin-top: 5px;
+}
diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php
index d980258c26..4e99379071 100644
--- a/pandora_console/operation/events/events.php
+++ b/pandora_console/operation/events/events.php
@@ -267,6 +267,9 @@ if (is_metaconsole() === true) {
// Ajax responses.
if (is_ajax() === true) {
$get_events = (int) get_parameter('get_events', 0);
+ $table_id = get_parameter('table_id', '');
+ $groupRecursion = (bool) get_parameter('groupRecursion', false);
+
// Datatables offset, limit.
$start = get_parameter('start', 0);
$length = get_parameter(
@@ -349,7 +352,11 @@ if (is_ajax() === true) {
// Sort field.
$order['field'],
// History.
- $history
+ $history,
+ false,
+ '',
+ false,
+ $groupRecursion
);
$buffers = [];
@@ -364,7 +371,11 @@ if (is_ajax() === true) {
null,
null,
null,
- $history
+ $history,
+ false,
+ '',
+ false,
+ $groupRecursion
);
if ($count !== false) {
@@ -379,12 +390,13 @@ if (is_ajax() === true) {
if (empty($events) === false) {
$data = array_reduce(
$events,
- function ($carry, $item) {
+ function ($carry, $item) use ($table_id) {
global $config;
$tmp = (object) $item;
$tmp->meta = is_metaconsole();
- //// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
+
+ // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
if ($tmp->meta === true) {
if ($tmp->server_name !== null) {
$tmp->data_server = metaconsole_get_servers(
@@ -463,6 +475,479 @@ if (is_ajax() === true) {
$tmp->b64 = base64_encode(json_encode($tmp));
+ // Show comments events.
+ $tmp->user_comment = $tmp->comments;
+ if ($tmp->comments !== 'undefined' && strlen($tmp->comments) > 80) {
+ $tmp->user_comment .= ' ';
+ $tmp->user_comment .= ' ';
+
+ // Grouped events.
+ if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
+ $evn .= '('.$tmp->event_rep.') ';
+ }
+
+ $evn .= $tmp->evento.' ';
+
+ // Add event severity format to itself.
+ $tmp->evento = $evn;
+
+ // Grouped events.
+ if (isset($item->max_timestamp) === true
+ && ($item->max_timestamp) === false
+ ) {
+ $item->timestamp = $item->max_timestamp;
+ }
+
+ // Event type prepared.
+ switch ($tmp->event_type) {
+ case EVENTS_ALERT_FIRED;
+ case EVENTS_ALERT_RECOVERED;
+ case EVENTS_ALERT_CEASED;
+ case EVENTS_ALERT_MANUAL_VALIDATION;
+ $text = __('ALERT');
+ $color = COL_ALERTFIRED;
+ break;
+
+ case EVENTS_RECON_HOST_DETECTED;
+ case EVENTS_SYSTEM;
+ case EVENTS_ERROR;
+ case EVENTS_NEW_AGENT;
+ case EVENTS_CONFIGURATION_CHANGE;
+ $text = __('SYSTEM');
+ $color = COL_MAINTENANCE;
+ break;
+
+ case EVENTS_GOING_UP_WARNING;
+ case EVENTS_GOING_DOWN_WARNING;
+ $text = __('WARNING');
+ $color = COL_WARNING;
+ break;
+
+ case EVENTS_GOING_DOWN_NORMAL;
+ case EVENTS_GOING_UP_NORMAL;
+ $text = __('NORMAL');
+ $color = COL_NORMAL;
+ break;
+
+ case EVENTS_GOING_DOWN_CRITICAL;
+ case EVENTS_GOING_UP_CRITICAL;
+ $text = __('CRITICAL');
+ $color = COL_CRITICAL;
+ break;
+
+ case EVENTS_UNKNOWN;
+ case EVENTS_GOING_UNKNOWN;
+ default:
+ $text = __('UNKNOWN');
+ $color = COL_UNKNOWN;
+ break;
+ }
+
+ $event_type = ''.$text.'
';
+ $tmp->event_type = $event_type;
+
+ // Module status.
+ // Event severity prepared.
+ switch ($tmp->module_status) {
+ case AGENT_MODULE_STATUS_NORMAL;
+ $text = __('NORMAL');
+ $color = COL_NORMAL;
+ break;
+
+ case AGENT_MODULE_STATUS_CRITICAL_BAD;
+ $text = __('CRITICAL');
+ $color = COL_CRITICAL;
+ break;
+
+ case AGENT_MODULE_STATUS_NO_DATA;
+ $text = __('NOT INIT');
+ $color = COL_NOTINIT;
+ break;
+
+ case AGENT_MODULE_STATUS_CRITICAL_ALERT;
+ case AGENT_MODULE_STATUS_NORMAL_ALERT;
+ case AGENT_MODULE_STATUS_WARNING_ALERT;
+ $text = __('ALERT');
+ $color = COL_ALERTFIRED;
+ break;
+
+ case AGENT_MODULE_STATUS_WARNING;
+ $text = __('WARNING');
+ $color = COL_WARNING;
+ break;
+
+ default:
+ $text = __('UNKNOWN');
+ $color = COL_UNKNOWN;
+ break;
+ }
+
+ $module_status = ''.$text.'
';
+ $tmp->module_status = $module_status;
+
+ // Status.
+ switch ($tmp->estado) {
+ case EVENT_STATUS_NEW:
+ $img = html_print_image(
+ 'images/star.png',
+ true,
+ [
+ 'title' => __('New event'),
+ 'class' => 'forced-title',
+ ]
+ );
+ $state = 0;
+ break;
+
+ case EVENT_STATUS_VALIDATED:
+ $state = 1;
+ $img = html_print_image(
+ 'images/tick.png',
+ true,
+ [
+ 'title' => __('Event validated'),
+ 'class' => 'forced-title invert_filter',
+ ]
+ );
+ break;
+
+ case EVENT_STATUS_INPROCESS:
+ $state = 2;
+ $img = html_print_image(
+ 'images/hourglass.png',
+ true,
+ [
+ 'title' => __('Event in process'),
+ 'class' => 'forced-title invert_filter',
+ ]
+ );
+ break;
+
+ default:
+ $img = html_print_image(
+ 'images/star.png',
+ true,
+ [
+ 'title' => __('Unknown'),
+ 'class' => 'forced-title',
+ ]
+ );
+ $state = 0;
+ break;
+ }
+
+ $draw_state = '';
+ $draw_state .= '';
+ $draw_state .= $state;
+ $draw_state .= ' ';
+ $draw_state .= $img;
+ $draw_state .= '
';
+ $tmp->estado = $draw_state;
+
+ // Owner.
+ if (empty($tmp->owner_user) === true) {
+ $tmp->owner_user = __('System');
+ }
+
+ // Group name.
+ if (empty($tmp->id_grupo) === true) {
+ $tmp->id_grupo = __('All');
+ } else {
+ $tmp->id_grupo = $tmp->group_name;
+ }
+
+ // Module name.
+ $tmp->id_agentmodule = $tmp->module_name;
+
+ // Options.
+ // Show more.
+ $tmp->options = '';
+ $tmp->options .= html_print_image(
+ 'images/operation.png',
+ true,
+ [
+ 'title' => __('Show more'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= ' ';
+
+ if ((int) $tmp->user_can_write === 1) {
+ if ((int) $tmp->estado !== 1) {
+ // Validate.
+ $tmp->options .= 'options .= ' id="val-'.$id_val.'">';
+ $tmp->options .= html_print_image(
+ 'images/tick.png',
+ true,
+ [
+ 'title' => __('Validate events'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= ' ';
+ } else {
+ $id_val = $tmp->id_evento;
+ if (is_metaconsole() === true) {
+ $id_val .= '-'.$tmp->server_id;
+ }
+
+ $tmp->options .= $tmp->id_evento.', 0, this, ';
+ $tmp->options .= $tmp->server_id.')" id="val-'.$id_val.'">';
+ $tmp->options .= html_print_image(
+ 'images/tick.png',
+ true,
+ [
+ 'title' => __('Validate event'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= '';
+ }
+ }
+
+ if ((int) $tmp->estado !== 2) {
+ // In process.
+ $tmp->options .= '';
+ } else {
+ $id_proc = $tmp->id_evento;
+ if (is_metaconsole() === true) {
+ $id_proc .= '-'.$tmp->server_id;
+ }
+
+ $tmp->options .= $tmp->id_evento.', 0, this, ';
+ $tmp->options .= $tmp->server_id.')" id="proc-'.$id_proc.'">';
+ }
+
+ $tmp->options .= html_print_image(
+ 'images/hourglass.png',
+ true,
+ [
+ 'title' => __('Change to in progress status'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= ' ';
+ }
+ }
+
+ if ((int) $tmp->user_can_manage === 1) {
+ // Delete.
+ $tmp->options .= '';
+ $tmp->options .= html_print_image(
+ 'images/cross.png',
+ true,
+ [
+ 'title' => __('Delete events'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= ' ';
+ } else {
+ $id_del = $tmp->id_evento;
+ if (is_metaconsole() === true) {
+ $id_del .= '-'.$tmp->server_id;
+ }
+
+ $tmp->options .= $tmp->id_evento.', 0, this, ';
+ $tmp->options .= $tmp->server_id.')" id="del-'.$id_del.'">';
+ $tmp->options .= html_print_image(
+ 'images/cross.png',
+ true,
+ [
+ 'title' => __('Delete event'),
+ 'class' => 'invert_filter',
+ ]
+ );
+ $tmp->options .= '';
+ }
+ }
+
+ // Multi select.
+ $value_checkbox = $tmp->id_evento;
+ if (is_metaconsole() === true) {
+ $value_checkbox .= '|'.$tmp->server_id;
+ }
+
+ $tmp->m = ' max_id_evento) === true
+ && empty($tmp->max_id_evento) === false
+ ) {
+ $tmp->m .= ' event_rep="'.$tmp->event_rep.'" ';
+ } else {
+ $tmp->m .= ' event_rep="0" ';
+ }
+
+ $tmp->m .= 'class="candeleted chk_val">';
+
+ // Url to go to node from meta.
+ $server_url = '';
+ $hashdata = '';
+ if ($tmp->meta === true) {
+ if (isset($tmp->data_server) === true
+ && isset($tmp->server_url_hash) === true
+ ) {
+ $server_url = $tmp->data_server['server_url'];
+ $hashdata = $tmp->server_url_hash;
+ }
+ }
+
+ // Url to agent view.
+ $url_link = ui_get_full_url(
+ 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='
+ );
+ $url_link_hash = '';
+ if ($tmp->meta === true) {
+ $url_link = $server_url;
+ $url_link .= '/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=';
+ $url_link_hash = $hashdata;
+ }
+
+ // Agent name link.
+ if ($tmp->id_agente > 0) {
+ $draw_agent_name = '';
+ $draw_agent_name .= $tmp->agent_name;
+ $draw_agent_name .= ' ';
+ $tmp->agent_name = $draw_agent_name;
+ } else {
+ $tmp->agent_name = '';
+ }
+
+ // Agent ID link.
+ if ($tmp->id_agente > 0) {
+ $draw_agent_id = '';
+ $draw_agent_id .= $tmp->id_agente;
+ $draw_agent_id .= ' ';
+ $tmp->id_agente = $draw_agent_id;
+ } else {
+ $tmp->id_agente = '';
+ }
+
+ if (empty($tmp->custom_data) === false) {
+ $custom_data = json_decode(io_safe_output($tmp->custom_data), true);
+ $custom_data_str = '';
+ if (isset($custom_data) === true && empty($custom_data) === false) {
+ foreach ($custom_data as $key => $value) {
+ $custom_data_str .= $value['attr_name'].' = '.$value['val'].' ';
+ }
+ }
+
+ $tmp->custom_data = $custom_data_str;
+ }
+
$carry[] = $tmp;
return $carry;
}
@@ -1748,6 +2233,8 @@ try {
$table_id = 'events';
$form_id = 'events_form';
+
+
// Print datatable.
ui_print_datatable(
[
@@ -1758,6 +2245,7 @@ try {
'ajax_data' => [
'get_events' => 1,
'history' => (int) $history,
+ 'table_id' => $table_id,
],
'form' => [
'id' => $form_id,
@@ -1800,7 +2288,6 @@ try {
-2,
'column-instructions',
],
- 'ajax_postprocess' => 'process_datatables_item(item)',
'ajax_return_operation' => 'buffers',
'ajax_return_operation_function' => 'process_buffers',
'drawCallback' => 'process_datatables_callback(this, settings)',
@@ -2018,386 +2505,6 @@ function process_datatables_callback(table, settings) {
$('#checkbox-all_validate_box').uncheck();
}
}
-
-function process_buffers(buffers) {
- $('#events_buffers_display').empty();
- if(buffers != null && buffers.settings != undefined && buffers.data) {
- var html = ''+buffers.settings.translate.nev;
- html += ': ('+buffers.settings.total+') ';
- html += '';
- Object.entries(buffers.data).forEach(function (element) {
- html += '';
- html += '';
- html += buffers.settings.translate.ev+' ';
- html += element[0];
- html += ': ';
- html += ' ';
-
- var class_total = 'info';
- var str_total = '';
- if(buffers.settings.total == element[1]) {
- class_total += ' danger';
- str_total = buffers.settings.translate.tevn;
- }
- html += '';
- html += element[1];
- if(str_total != '') {
- html += '';
- html += ' '+str_total;
- html += ' ';
- }
-
- html += ' ';
-
- html += ' ';
- });
- html += ' ';
-
- $('#events_buffers_display').html(html);
- }
-}
-
-function process_datatables_item(item) {
- // Url to go to node from meta.
- var server_url = '';
- var hashdata = '';
- if(item.meta === true){
- if(typeof item.data_server !== 'undefined' && typeof item.server_url_hash !== 'undefined'){
- server_url = item.data_server.server_url;
- hashdata = item.server_url_hash;
- }
- }
-
-
- // Show comments events.
- item.user_comment = item.comments
-
- if(typeof item.comments !== 'undefined' && item.comments.length > 80) {
- item.user_comment += ' ';
- }
-
- // Grouped events.
- if(item.max_id_evento) {
- item.id_evento = item.max_id_evento
- }
-
- /* Event severity prepared */
- var color = "";
- var text = "";
- switch (item.criticity) {
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
- }
- output = '';
- output += '
';
-
- // Add event severity to end of text.
- evn = '';
- // Grouped events.
- if(item.event_rep && item.event_rep > 1) {
- evn += '('+item.event_rep+') ';
- }
- evn += item.evento+' ';
- if(item.meta === true) {
- evn += ' ';
- }
-
- item.mini_severity = '';
- item.mini_severity += output;
- item.mini_severity += '
';
-
- criticity = '' + text + "
";
-
- // Grouped events.
- if(item.max_timestamp) {
- item.timestamp = item.max_timestamp;
- }
-
- /* Event type prepared. */
- switch (item.event_type) {
- case "":
- case "":
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- case "":
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- default:
- text = "";
- color = "";
- break;
- }
-
- event_type = '' + text + "
";
-
- /* Module status */
- /* Event severity prepared */
- var color = "";
- var text = "";
- switch (item.module_status) {
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- case "":
- case "":
- text = "";
- color = "";
- break;
-
- case "":
- text = "";
- color = "";
- break;
- }
-
- module_status = '' + text + "
";
-
- /* Options */
- // Show more.
- item.options = ' __('Show more'), 'class' => 'invert_filter']); ?> ';
-
-
-
- if (item.user_can_write == '1') {
- if (item.estado != '1') {
- // Validate.
- item.options += '';
- item.options += ' __('Validate events'), 'class' => 'invert_filter']); ?> ';
- } else {
- item.options += item.id_evento+', 0, this, '+item.server_id+')" id="val-'+item.id_evento+'">';
- item.options += ' __('Validate event'), 'class' => 'invert_filter']); ?>';
- }
- }
-
- if (item.estado != '2') {
- // In process.
- item.options += '';
- } else {
- item.options += item.id_evento+', 0, this, '+item.server_id+')" id="proc-'+item.id_evento+'">';
- }
- item.options += ' __('Change to in progress status'), 'class' => 'invert_filter']); ?> ';
- }
- }
-
- if (item.user_can_manage == '1') {
- // Delete.
- item.options += '';
- item.options += ' __('Delete events'), 'class' => 'invert_filter']); ?> ';
- } else {
- item.options += item.id_evento+', 0, this, '+item.server_id+')" id="del-'+item.id_evento+'">';
- item.options += ' __('Delete event'), 'class' => 'invert_filter']); ?>';
- }
- }
-
-
- // Multi select.
- item.m = ' ';
-
- /* Status */
- img = ' __('Unknown'), 'class' => 'forced-title']); ?>';
- state = '0';
- switch (item.estado) {
- case "":
- img = ' __('New event'), 'class' => 'forced-title']); ?>';
- break;
-
- case "":
-
- state = '1';
- img = ' __('Event validated'), 'class' => 'forced-title invert_filter']); ?>';
- break;
-
- case "":
- state = '2';
-
- img = ' __('Event in process'), 'class' => 'forced-title invert_filter']); ?>';
- break;
- }
-
- /* Update column content now to avoid json poisoning. */
-
-
- // Url to agent view.
- var url_link = '';
- var url_link_hash = '';
- if(item.meta === true){
- url_link = server_url+'/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=';
- url_link_hash = hashdata;
- }
-
-
- /* Agent name link */
- if (item.id_agente > 0) {
- item.agent_name = '' + item.agent_name + ' ';
- } else {
- item.agent_name = '';
- }
-
- /* Agent ID link */
- if (item.id_agente > 0) {
- item.id_agente = '' + item.id_agente + ' ';
- } else {
- item.id_agente = '';
- }
-
- item.estado = '';
- item.estado += '';
- item.estado += state;
- item.estado += ' ';
- item.estado += img;
- item.estado += '
';
-
- item.criticity = criticity;
- item.event_type = event_type;
- item.module_status = module_status;
-
- /* Event ID dash */
- item.id_evento = "#"+item.id_evento;
-
- /* Owner */
- if (item.owner_user == "0") {
- item.owner_user = '';
- }
-
- // Add event severity format to itself.
- item.evento = evn;
-
- /* Group name */
- if (item.id_grupo == "0") {
- item.id_grupo = "";
- } else {
- item.id_grupo = item.group_name;
- }
-
- /* Module name */
- item.id_agentmodule = item.module_name;
-
- if (item.custom_data !== '') {
- var custom_data_str = '';
-
- var item_custom_data_obj = (function(json_str) {
- try {
- return JSON.parse(json_str);
- } catch (err) {
- return false;
- }
- })(item.custom_data);
-
- if (item_custom_data_obj !== false) {
- for (const [attr_name, val] of Object.entries(item_custom_data_obj)) {
- custom_data_str += attr_name + ' = ' + val + ' ';
- }
- item.custom_data = custom_data_str;
- } else {
- item.custom_data = '';
- }
- }
-}
-
/* Datatables auxiliary functions ends */
/* Tag management starts */