event validation/in process

This commit is contained in:
fbsanchez 2019-06-13 12:30:09 +02:00
parent f3a0f37a1c
commit ecc2fef8f6
5 changed files with 184 additions and 24 deletions

View File

@ -79,6 +79,39 @@ $save_filter = get_parameter('save_filter', 0);
$get_filter_values = get_parameter('get_filter_values', 0);
$update_event_filter = get_parameter('update_event_filter', 0);
$save_event_filter = get_parameter('save_event_filter', 0);
$in_process_event = get_parameter('in_process_event', 0);
$validate_event = get_parameter('validate_event', 0);
$delete_event = get_parameter('delete_event', 0);
// Delete event (filtered or not).
if ($delete_event) {
$filter = get_parameter('filter', []);
$id_evento = get_parameter('id_evento', 0);
// Check acl.
echo events_delete($id_evento, $filter);
return;
}
// Validates an event (filtered or not).
if ($validate_event) {
$filter = get_parameter('filter', []);
$id_evento = get_parameter('id_evento', 0);
// Check acl.
echo events_update_status($id_evento, EVENT_VALIDATE, $filter);
return;
}
// Sets status to in progress.
if ($in_process_event) {
$filter = get_parameter('filter', []);
$id_evento = get_parameter('id_evento', 0);
// Check acl.
echo events_update_status($id_evento, EVENT_PROCESS, $filter);
return;
}
// Saves an event filter.
if ($save_event_filter) {

View File

@ -32,6 +32,7 @@ require_once $config['homedir'].'/include/functions_db.php';
require_once $config['homedir'].'/include/functions_io.php';
require_once $config['homedir'].'/include/functions_notifications.php';
require_once $config['homedir'].'/include/functions_servers.php';
require_once $config['homedir'].'/include/functions_update_manager.php';
// Enterprise includes.
enterprise_include_once('include/functions_metaconsole.php');
@ -1940,6 +1941,7 @@ class ConsoleSupervisor
public function checkUpdateManagerRegistration()
{
global $config;
include_once $config['homedir'].'/include/functions_update_manager.php';
$login = get_parameter('login', false);
if (update_manager_verify_registration() === false) {
@ -2244,6 +2246,7 @@ class ConsoleSupervisor
public function getUMMessages()
{
global $config;
include_once $config['homedir'].'/include/functions_update_manager.php';
if (update_manager_verify_registration() === false) {
// Console not subscribed.
@ -2261,8 +2264,6 @@ class ConsoleSupervisor
$future = (time() + 2 * SECONDS_1HOUR);
config_update_value('last_um_check', $future);
include_once $config['homedir'].'/include/functions_update_manager.php';
$params = [
'pandora_uid' => $config['pandora_uid'],
'timezone' => $config['timezone'],

View File

@ -184,6 +184,90 @@ function events_get_column_names($fields)
}
/**
* Validates all events matching target filter.
*
* @param integer $id_evento Master event.
* @param integer $status Target status.
* @param array $filter Optional. Filter options.
* @param boolean $history Apply on historical table.
*
* @return integer Events validated or false if error.
*/
function events_update_status($id_evento, $status, $filter=null, $history=false)
{
error_log($id_evento);
error_log($status);
if (!$status) {
return false;
}
if (!isset($id_evento) || $id_evento <= 0) {
return false;
}
if (!isset($filter) || !is_array($filter)) {
$filter = ['group_rep' => 0];
}
$table = events_get_events_table(is_metaconsole(), $history);
switch ($filter['group_rep']) {
case '0':
case '2':
default:
// No groups option direct update.
$update_sql = sprintf(
'UPDATE %s
SET estado = %d
WHERE id_evento = %d',
$table,
$status,
$id_evento
);
break;
case '1':
// Group by events.
$sql = events_get_all(
['te.*'],
$filter,
// Offset.
null,
// Limit.
null,
// Order.
null,
// Sort_field.
null,
// Historical table.
$history,
// Return_sql.
true
);
$update_sql = sprintf(
'UPDATE %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado
AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d
SET tu.estado = %d',
$table,
$sql,
$id_evento,
$status
);
break;
}
error_log($update_sql);
return db_process_sql($update_sql);
}
/**
* Retrieve all events filtered.
*
@ -193,6 +277,8 @@ function events_get_column_names($fields)
* @param integer $limit Limit (pagination).
* @param string $order Sort order.
* @param string $sort_field Sort field.
* @param boolean $history Apply on historical table.
* @param boolean $return_sql Return SQL (true) or execute it (false).
*
* @return array Events.
* @throws Exception On error.
@ -204,6 +290,7 @@ function events_get_all(
$limit=null,
$order=null,
$sort_field=null,
$history=false,
$return_sql=false
) {
global $config;
@ -326,7 +413,7 @@ function events_get_all(
}
}
$table = events_get_events_table($meta, $history);
$table = events_get_events_table(is_metaconsole(), $history);
$tevento = sprintf(
'(SELECT *
FROM %s
@ -385,7 +472,7 @@ function events_get_all(
case '1':
// Group by events.
$group_by .= 'estado, evento, id_agente, id_agentmodule';
$group_by .= 'te.estado, te.evento, te.id_agente, te.id_agentmodule';
$group_by .= $extra;
break;
@ -429,7 +516,10 @@ function events_get_all(
MAX(id_evento) as max_id_evento';
if ($count === false) {
unset($fields[array_search('te.user_comment', $fields)]);
$idx = array_search('te.user_comment', $fields);
if ($idx !== false) {
unset($fields[$idx]);
}
}
}

View File

@ -1,4 +1,4 @@
/*global jQuery,$,forced_title_callback,Base64,*/
/*global jQuery,$,forced_title_callback,Base64*/
// Show the modal window of an event
function show_event_dialog(event_id, group_rep, dialog_page, result) {
@ -669,11 +669,39 @@ function show_event_response_command_dialog(id, response, total_checked) {
});
}
function validate_event(e, row) {
console.log(row);
function update_event(table, id_evento, type) {
var inputs = $("#events_form :input");
var values = {};
inputs.each(function() {
values[this.name] = $(this).val();
});
// Update events matching current filters and id_evento selected.
$.ajax({
type: "POST",
url: $("#hidden-ajax_file").val(),
data: {
page: "include/ajax/events",
validate_event: type.validate_event,
in_process_event: type.in_process_event,
id_evento: id_evento,
filter: values
},
success: function() {
table.draw().page(0);
}
});
}
function delete_event(e, row) {
function validate_event(table, id_evento) {
return update_event(table, id_evento, { validate_event: 1 });
}
function in_process_event(table, id_evento) {
return update_event(table, id_evento, { in_process_event: 1 });
}
function delete_event(table, id_evento, row) {
$(row)
.closest("tr")
.remove();

View File

@ -53,6 +53,10 @@ if (! check_acl($config['id_user'], 0, 'ER')
'ACL Violation',
'Trying to access event viewer'
);
if (is_ajax()) {
return ['error' => 'noaccess'];
}
include 'general/noaccess.php';
return;
}
@ -94,10 +98,6 @@ $user_comment = get_parameter('filter[user_comment]');
// Ajax responses.
if (is_ajax()) {
$get_filter_values = get_parameter('get_filter_values', 0);
$save_event_filter = get_parameter('save_event_filter', 0);
$update_event_filter = get_parameter('update_event_filter', 0);
$get_event_filters = get_parameter('get_event_filters', 0);
$get_events = get_parameter('get_events', 0);
$filter = get_parameter('filter', []);
// Datatables offset, limit.
@ -1083,16 +1083,18 @@ try {
// Close.
$active_filters_div .= '</div>';
$table_id = 'events';
// Print datatable.
ui_print_datatable(
[
'id' => 'events',
'id' => $table_id,
'class' => 'info_table events',
'style' => 'width: 100%;',
'ajax_url' => 'operation/events/events',
'ajax_data' => ['get_events' => 1],
'form' => [
'id' => 'events_form',
'class' => 'flex-row',
'html' => $filter,
'inputs' => [],
@ -1215,12 +1217,12 @@ function process_datatables_callback(table, settings) {
$(rows).eq( i ).before(
'<tr class="group"><td colspan="100%">'
+'<?php echo __('Agent').' '; ?>'
+group+' <?php echo __('has').' '; ?>'
+group+' <?php echo __('has at least').' '; ?>'
+'<span style="cursor: pointer" id="s'+j+'">'+'</span>'
+'<?php echo ' '.__('events'); ?>'
+'</td></tr>'
);
events_per_group.push(i);
events_per_group.push(i - last_count);
last_count = i;
last = group;
j += 1;
@ -1426,25 +1428,31 @@ function process_datatables_item(item) {
item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>';
// Validate.
item.options += '<a href="javascript:" onclick="validate_event(';
item.options += item.id_evento+', this)" >';
item.options += '<a href="javascript:" onclick="validate_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+')" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate events')]); ?></a>';
} else {
item.options += item.id_evento+')" >';
item.options += '<?php echo html_print_image('images/tick.png', true, ['title' => __('Validate event')]); ?></a>';
}
// In progress.
item.options += '<a href="javascript:" onclick="inprogress_event(';
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Chnge to in progress status')]); ?></a>';
// In process.
item.options += '<a href="javascript:" onclick="in_process_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+')" >';
} else {
item.options += item.id_evento+')" >';
}
item.options += '<?php echo html_print_image('images/hourglass.png', true, ['title' => __('Change to in progress status')]); ?></a>';
// Delete.
item.options += '<a href="javascript:" onclick="delete_event(';
item.options += item.id_evento+', this)" >';
item.options += '<a href="javascript:" onclick="delete_event(dt_<?php echo $table_id; ?>,';
if (item.max_id_evento) {
item.options += item.max_id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete events')]); ?></a>';
} else {
item.options += item.id_evento+', this)" >';
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete event')]); ?></a>';
}