wip events

This commit is contained in:
fbsanchez 2019-06-18 10:32:04 +02:00
parent a8a206fa10
commit f7cf6e1e8b
5 changed files with 117 additions and 84 deletions

View File

@ -1009,15 +1009,31 @@ function events_get_all(
if (!$user_is_admin) {
// XXX: Confirm there's no extra grants unhandled!.
$can_manage = '0 as user_can_manage';
if (!empty($EM_groups)) {
$can_manage = sprintf(
'(tbase.id_grupo IN (%s)) as user_can_manage',
join(', ', array_keys($EM_groups))
);
}
$can_write = '0 as user_can_write';
if (!empty($EW_groups)) {
$can_write = sprintf(
'(tbase.id_grupo IN (%s)) as user_can_write',
join(', ', array_keys($EW_groups))
);
}
$sql = sprintf(
'SELECT
tbase.*,
(tbase.id_grupo IN (%s)) as user_can_manage,
(tbase.id_grupo IN (%s)) as user_can_write
%s,
%s
FROM
(',
join(', ', array_keys($EM_groups)),
join(', ', array_keys($EW_groups))
$can_manage,
$can_write
).$sql.') tbase';
} else {
$sql = 'SELECT

View File

@ -3245,7 +3245,8 @@ function ui_print_datatable(array $parameters)
</script>';
// Order.
$output = $filter.$extra.$table.$js;
$err_msg = '<div id="error-'.$table_id.'"></div>';
$output = $err_msg.$filter.$extra.$table.$js;
ui_require_css_file('datatables.min', 'include/styles/js/');
ui_require_javascript_file('datatables.min');

View File

@ -668,7 +668,7 @@ function show_event_response_command_dialog(id, response, total_checked) {
});
}
var processing = 0;
var processed = 0;
function update_event(table, id_evento, type, row) {
var inputs = $("#events_form :input");
var values = {};
@ -678,7 +678,6 @@ function update_event(table, id_evento, type, row) {
});
var t1 = new Date();
processing += 1;
// Update events matching current filters and id_evento selected.
$.ajax({
type: "POST",
@ -691,24 +690,23 @@ function update_event(table, id_evento, type, row) {
id_evento: id_evento,
filter: values
},
success: function() {
success: function(d) {
processed += 1;
var t2 = new Date();
var diff_g = t2.getTime() - t1.getTime();
var diff_s = diff_g / 1000;
// If operation takes less than 2 seconds, redraw.
processing -= 1;
if (diff_s < 2) {
redraw = true;
}
if (redraw) {
if (processing == 0) {
table.draw(false);
if (processed >= $(".chk_val:checked").length) {
// If operation takes less than 2 seconds, redraw.
if (diff_s < 2) {
redraw = true;
}
if (redraw) {
table.draw(false);
} else {
$(row)
.closest("tr")
.remove();
}
} else {
$(row)
.closest("tr")
.remove();
}
}
});
@ -731,14 +729,22 @@ function delete_event(table, id_evento, row) {
// Imported from old files.
function execute_event_response(event_list_btn) {
processed = 0;
$("#max_custom_event_resp_msg").hide();
$("#max_custom_selected").hide();
var response_id = $("select[name=response_id]").val();
var total_checked = $(".chk_val:checked").length;
// Check select an event.
if (total_checked == 0) {
$("#max_custom_selected").show();
return;
}
if (!isNaN(response_id)) {
// It is a custom response
var response = get_response(response_id);
// If cannot get response abort it
@ -746,16 +752,8 @@ function execute_event_response(event_list_btn) {
return;
}
var total_checked = $(".chk_val:checked").length;
// Check select an event.
if (total_checked == 0) {
$("#max_custom_selected").show();
return;
}
// Limit number of events to apply custom responses
// to for performance reasons.
// due performance reasons.
if (total_checked > $("#max_execution_event_response").val()) {
$("#max_custom_event_resp_msg").show();
return;
@ -801,30 +799,32 @@ function execute_event_response(event_list_btn) {
}
} else {
// It is not a custom response
var delay = 5000;
var $i = 0;
switch (response_id) {
case "in_progress_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
in_process_event(dt_events, $(this).val(), this.parentElement);
}
$(".chk_val:checked").each(function() {
setTimeout(
in_process_event(dt_events, $(this).val(), this.parentElement),
total_checked * delay * $i++
);
});
dt_events.draw(false);
break;
case "validate_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
validate_event(dt_events, $(this).val(), this.parentElement);
}
$(".chk_val:checked").each(function() {
setTimeout(
validate_event(dt_events, $(this).val(), this.parentElement),
total_checked * delay * $i++
);
});
dt_events.draw(false);
break;
case "delete_selected":
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
delete_event(dt_events, $(this).val(), this.parentElement);
}
$(".chk_val:checked").each(function() {
setTimeout(
delete_event(dt_events, $(this).val(), this.parentElement),
total_checked * delay * $i++
);
});
dt_events.draw(false);
break;
}
}
@ -839,28 +839,20 @@ function check_massive_response_event(
var counter = 0;
var end = 0;
$(".chk_val").each(function() {
if ($(this).is(":checked")) {
var event_id = $(this).val();
var server_id = $("#hidden-server_id_" + event_id).val();
response["target"] = get_response_target(
event_id,
response_id,
server_id,
response_command
);
$(".chk_val:checked").each(function() {
var event_id = $(this).val();
var server_id = $("#hidden-server_id_" + event_id).val();
response["target"] = get_response_target(
event_id,
response_id,
server_id,
response_command
);
if (total_checked - 1 === counter) end = 1;
if (total_checked - 1 === counter) end = 1;
show_massive_response_dialog(
event_id,
response_id,
response,
counter,
end
);
show_massive_response_dialog(event_id, response_id, response, counter, end);
counter++;
}
counter++;
});
}

View File

@ -1,30 +1,48 @@
<?php
/**
* Event statistics.
*
* @category Statistics view.
* @package Pandora FMS
* @subpackage Events.
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
// Begin.
global $config;
require_once $config['homedir'].'/include/functions_graph.php';
check_login();
if (! check_acl($config['id_user'], 0, 'ER') && ! check_acl($config['id_user'], 0, 'EW') && ! check_acl($config['id_user'], 0, 'EM')) {
if (! check_acl($config['id_user'], 0, 'ER')
&& ! check_acl($config['id_user'], 0, 'EW')
&& ! check_acl($config['id_user'], 0, 'EM')
) {
db_pandora_audit('ACL Violation', 'Trying to access event viewer');
include 'general/noaccess.php';
return;
}
// header
// Header.
ui_print_page_header(__('Statistics'), 'images/op_events.png', false, false);
echo '<table width=95%>';

View File

@ -93,7 +93,7 @@ $text_agent = get_parameter('filter[text_agent]');
$id_agent = get_parameter('filter[id_agent]');
$id_agent_module = get_parameter('filter[id_agent_module]');
$pagination = get_parameter('filter[pagination]');
$event_view_hr = get_parameter('filter[event_view_hr]', 8);
$event_view_hr = get_parameter('filter[event_view_hr]', $config['event_view_hr']);
$id_user_ack = get_parameter('filter[id_user_ack]');
$group_rep = get_parameter('filter[group_rep]', 1);
$tag_with = get_parameter('filter[tag_with]', []);
@ -1034,6 +1034,13 @@ $filter .= ui_toggle(
);
try {
$checkbox_all = html_print_checkbox(
'all_validate_box',
1,
false,
true
);
$default_fields = [
'evento',
'id_evento',
@ -1070,7 +1077,7 @@ try {
'class' => 'action_buttons w120px',
],[
'text' => 'm',
'extra' => "<input name='all_validate_box' type='checkbox' value='1' id='checkbox-all_validate_box' />",
'extra' => $checkbox_all,
'class' => 'w20px',
],
];
@ -1090,7 +1097,7 @@ try {
'class' => 'action_buttons w120px',
],[
'text' => 'm',
'extra' => "<input name='all_validate_box' type='checkbox' value='1' id='checkbox-all_validate_box' />",
'extra' => $checkbox_all,
'class' => 'w20px no-text-imp',
],
]
@ -1298,7 +1305,6 @@ html_print_input_hidden(
echo "<div id='event_details_window'></div>";
echo "<div id='event_response_window'></div>";
echo "<div id='event_response_command_window' title='".__('Parameters')."'></div>";
echo "<div id='error-".$table_id."'></div>";
// Load filter div for dialog.
echo '<div id="load-modal-filter" style="display: none"></div>';