add new functionality in event response
Former-commit-id: 2cf28b95c068c40e79b8f05b212aad0f720de79b
This commit is contained in:
parent
75b889ff4a
commit
8780571a74
|
@ -54,6 +54,7 @@ $table_events = get_parameter('table_events', 0);
|
|||
$total_events = (bool) get_parameter('total_events');
|
||||
$total_event_graph = (bool) get_parameter('total_event_graph');
|
||||
$graphic_event_group = (bool) get_parameter('graphic_event_group');
|
||||
$get_table_response_command = (bool) get_parameter('get_table_response_command');
|
||||
|
||||
if ($get_event_name) {
|
||||
$event_id = get_parameter('event_id');
|
||||
|
@ -116,6 +117,7 @@ if ($get_response_target) {
|
|||
}
|
||||
|
||||
echo events_get_response_target($event_id, $response_id, $server_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -129,6 +131,7 @@ if ($get_response) {
|
|||
}
|
||||
|
||||
echo json_encode($event_response);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,6 +139,7 @@ if ($perform_event_response) {
|
|||
global $config;
|
||||
|
||||
$command = get_parameter('target', '');
|
||||
|
||||
$response_id = get_parameter('response_id');
|
||||
|
||||
$event_response = db_get_row('tevent_response', 'id', $response_id);
|
||||
|
@ -148,7 +152,11 @@ if ($perform_event_response) {
|
|||
'nano',
|
||||
];
|
||||
|
||||
$server_data = db_get_row('tserver', 'id_server', $event_response['server_to_exec']);
|
||||
$server_data = db_get_row(
|
||||
'tserver',
|
||||
'id_server',
|
||||
$event_response['server_to_exec']
|
||||
);
|
||||
|
||||
if (in_array(strtolower($command), $commandExclusions)) {
|
||||
echo 'Only stdin/stdout commands are supported';
|
||||
|
@ -234,13 +242,29 @@ if ($dialogue_event_response) {
|
|||
);
|
||||
echo '</div><br>';
|
||||
|
||||
echo "<div id='response_loading_command_".$out_iterator."' style='display:none'>".html_print_image('images/spinner.gif', true).'</div>';
|
||||
echo "<div id='response_loading_command_".$out_iterator."' style='display:none'>";
|
||||
echo html_print_image(
|
||||
'images/spinner.gif',
|
||||
true
|
||||
);
|
||||
echo '</div>';
|
||||
echo "<br><div id='response_out_".$out_iterator."' style='text-align:left'></div>";
|
||||
|
||||
if ($end) {
|
||||
echo "<br><div id='re_exec_command_".$out_iterator."' style='display:none;'>";
|
||||
html_print_button(__('Execute again'), 'btn_str', false, 'execute_event_response(false);', "class='sub next'");
|
||||
echo "<span id='execute_again_loading' style='display:none'>".html_print_image('images/spinner.gif', true).'</span>';
|
||||
html_print_button(
|
||||
__('Execute again'),
|
||||
'btn_str',
|
||||
false,
|
||||
'execute_event_response(false);',
|
||||
"class='sub next'"
|
||||
);
|
||||
echo "<span id='execute_again_loading' style='display:none'>";
|
||||
echo html_print_image(
|
||||
'images/spinner.gif',
|
||||
true
|
||||
);
|
||||
echo '</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
} else {
|
||||
|
@ -796,3 +820,67 @@ if ($graphic_event_group) {
|
|||
echo $prueba;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_table_response_command) {
|
||||
global $config;
|
||||
|
||||
$response_id = get_parameter('event_response_id');
|
||||
$params_string = db_get_value(
|
||||
'params',
|
||||
'tevent_response',
|
||||
'id',
|
||||
$response_id
|
||||
);
|
||||
|
||||
$params = explode(',', $params_string);
|
||||
|
||||
$table = new stdClass;
|
||||
$table->id = 'events_responses_table_command';
|
||||
$table->width = '90%';
|
||||
$table->styleTable = 'text-align:center; margin: 0 auto;';
|
||||
|
||||
$table->style = [];
|
||||
$table->style[0] = 'text-align:center;';
|
||||
$table->style[1] = 'text-align:center;';
|
||||
|
||||
$table->head = [];
|
||||
$table->head[0] = __('Commands');
|
||||
$table->head[0] .= ui_print_help_tip(
|
||||
__('These commands will apply to all selected events'),
|
||||
true
|
||||
);
|
||||
$table->head[1] = __('Value');
|
||||
|
||||
if (isset($params) === true
|
||||
&& is_array($params) === true
|
||||
) {
|
||||
foreach ($params as $key => $value) {
|
||||
$table->data[$key][0] = $value;
|
||||
$table->data[$key][1] = html_print_input_text(
|
||||
$value.'-'.$key,
|
||||
'',
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
'',
|
||||
'response_command_input'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo '<form id="form_response_command">';
|
||||
echo html_print_table($table, true);
|
||||
echo '</form>';
|
||||
echo html_print_submit_button(
|
||||
__('Execute'),
|
||||
'enter_command',
|
||||
false,
|
||||
'class="sub next" style="float:right; margin-top:15px; margin-right:25px;"',
|
||||
true
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -241,6 +241,7 @@ function show_massive_response_dialog(
|
|||
},
|
||||
close: function(event, ui) {
|
||||
$(".chk_val").prop("checked", false);
|
||||
$("#event_response_command_window").dialog("close");
|
||||
},
|
||||
width: response["modal_width"],
|
||||
height: response["modal_height"]
|
||||
|
@ -375,7 +376,12 @@ function add_row_param(id_table, param) {
|
|||
}
|
||||
|
||||
// Get an event response from db
|
||||
function get_response_target(event_id, response_id, server_id) {
|
||||
function get_response_target(
|
||||
event_id,
|
||||
response_id,
|
||||
server_id,
|
||||
response_command
|
||||
) {
|
||||
var ajax_file = $("#hidden-ajax_file").val();
|
||||
|
||||
var target = "";
|
||||
|
@ -400,15 +406,21 @@ function get_response_target(event_id, response_id, server_id) {
|
|||
}
|
||||
});
|
||||
|
||||
// Replace the custom params macros
|
||||
// Replace the custom params macros.
|
||||
var response_params = get_response_params(response_id);
|
||||
|
||||
if (response_params.length > 1 || response_params[0] != "") {
|
||||
for (i = 0; i < response_params.length; i++) {
|
||||
target = target.replace(
|
||||
"_" + response_params[i] + "_",
|
||||
$("#" + response_params[i]).val()
|
||||
);
|
||||
if (!response_command) {
|
||||
target = target.replace(
|
||||
"_" + response_params[i] + "_",
|
||||
$("#" + response_params[i]).val()
|
||||
);
|
||||
} else {
|
||||
target = target.replace(
|
||||
"_" + response_params[i] + "_",
|
||||
response_command[response_params[i] + "-" + i]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,10 +471,6 @@ function perform_response_massive(target, response_id, out_iterator) {
|
|||
$("#response_loading_command_" + out_iterator).show();
|
||||
$("#response_out_" + out_iterator).html("");
|
||||
|
||||
var finished = 0;
|
||||
var time = Math.round(+new Date() / 1000);
|
||||
var timeout = time + 10;
|
||||
|
||||
var params = [];
|
||||
params.push("page=include/ajax/events");
|
||||
params.push("perform_event_response=1");
|
||||
|
@ -487,7 +495,7 @@ function perform_response_massive(target, response_id, out_iterator) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Change the status of an event to new, in process or validated
|
||||
// Change the status of an event to new, in process or validated.
|
||||
function event_change_status(event_ids) {
|
||||
var ajax_file = $("#hidden-ajax_file").val();
|
||||
|
||||
|
@ -681,3 +689,53 @@ function show_events_group_agent(id_insert, id_agent, server_id) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function show_event_response_command_dialog(id, response, total_checked) {
|
||||
var ajax_file = $("#hidden-ajax_file").val();
|
||||
|
||||
var params = [];
|
||||
params.push("page=include/ajax/events");
|
||||
params.push("get_table_response_command=1");
|
||||
params.push("event_response_id=" + id);
|
||||
|
||||
jQuery.ajax({
|
||||
data: params.join("&"),
|
||||
type: "POST",
|
||||
url: (action = ajax_file),
|
||||
dataType: "html",
|
||||
success: function(data) {
|
||||
$("#event_response_command_window")
|
||||
.hide()
|
||||
.empty()
|
||||
.append(data)
|
||||
.dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: false,
|
||||
open: function() {
|
||||
$("#response_loading_dialog").hide();
|
||||
$("#button-submit_event_response").show();
|
||||
},
|
||||
width: 600,
|
||||
height: 300
|
||||
})
|
||||
.show();
|
||||
|
||||
$("#submit-enter_command").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var response_command = [];
|
||||
|
||||
$(".response_command_input").each(function() {
|
||||
response_command[$(this).attr("name")] = $(this).val();
|
||||
});
|
||||
|
||||
check_massive_response_event(
|
||||
id,
|
||||
response,
|
||||
total_checked,
|
||||
response_command
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -988,6 +988,10 @@ if ($group_rep == 2) {
|
|||
'A maximum of %s event custom responses can be selected',
|
||||
$config['max_execution_event_response']
|
||||
).'</span>';
|
||||
echo '<span id="max_custom_selected" style="display:none; color:#FC4444; line-height: 200%;">';
|
||||
echo __(
|
||||
'Please, select an event'
|
||||
).'</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
@ -995,12 +999,14 @@ if ($group_rep == 2) {
|
|||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
function execute_event_response(event_list_btn) {
|
||||
function execute_event_response(event_list_btn) {
|
||||
|
||||
$('#max_custom_event_resp_msg').hide();
|
||||
$('#max_custom_selected').hide();
|
||||
|
||||
var response_id = $('select[name=response_id]').val();
|
||||
|
||||
|
||||
if (!isNaN(response_id)) { // It is a custom response
|
||||
|
||||
var response = get_response(response_id);
|
||||
|
@ -1015,59 +1021,58 @@ if ($group_rep == 2) {
|
|||
|
||||
var total_checked = $(".chk_val:checked").length;
|
||||
|
||||
// Limit number of events to apply custom responses to for performance reasons
|
||||
// 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.
|
||||
if (total_checked > <?php echo $config['max_execution_event_response']; ?> ) {
|
||||
$('#max_custom_event_resp_msg').show();
|
||||
return;
|
||||
}
|
||||
|
||||
var response_command = [];
|
||||
$(".response_command_input").each(function() {
|
||||
response_command[$(this).attr("name")] = $(this).val();
|
||||
});
|
||||
|
||||
if (event_list_btn) {
|
||||
$('#button-submit_event_response').hide(function() {
|
||||
$('#response_loading_dialog').show(function() {
|
||||
var check_params = get_response_params(
|
||||
response_id
|
||||
);
|
||||
|
||||
$(".chk_val").each(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
event_id = $(this).val();
|
||||
server_id = $('#hidden-server_id_'+event_id).val();
|
||||
response['target'] = get_response_target(
|
||||
event_id,
|
||||
response_id,
|
||||
server_id
|
||||
);
|
||||
if (total_checked-1 === counter) end=1;
|
||||
show_massive_response_dialog(
|
||||
event_id,
|
||||
response_id,
|
||||
response,
|
||||
counter,
|
||||
end
|
||||
);
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
if(check_params[0] !== ''){
|
||||
show_event_response_command_dialog(
|
||||
response_id,
|
||||
response,
|
||||
total_checked
|
||||
);
|
||||
}
|
||||
else{
|
||||
check_massive_response_event(
|
||||
response_id,
|
||||
response,
|
||||
total_checked,
|
||||
response_command
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#button-btn_str').hide(function() {
|
||||
$('#execute_again_loading').show(function() {
|
||||
|
||||
$(".chk_val").each(function() {
|
||||
|
||||
if ($(this).is(":checked")) {
|
||||
//var server_id = $('#hidden-server_id_'+).
|
||||
event_id = $(this).val();
|
||||
server_id = $('#hidden-server_id_'+event_id).val();
|
||||
|
||||
response['target'] = get_response_target(event_id, response_id, server_id);
|
||||
|
||||
if (total_checked-1 === counter) end=1;
|
||||
|
||||
show_massive_response_dialog(event_id, response_id, response, counter, end);
|
||||
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
check_massive_response_event(
|
||||
response_id,
|
||||
response,
|
||||
total_checked,
|
||||
response_command
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1087,6 +1092,42 @@ if ($group_rep == 2) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function check_massive_response_event(
|
||||
response_id,
|
||||
response,
|
||||
total_checked,
|
||||
response_command
|
||||
){
|
||||
var counter=0;
|
||||
var end=0;
|
||||
|
||||
$(".chk_val").each(function() {
|
||||
if ($(this).is(":checked")) {
|
||||
event_id = $(this).val();
|
||||
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;
|
||||
|
||||
show_massive_response_dialog(
|
||||
event_id,
|
||||
response_id,
|
||||
response,
|
||||
counter,
|
||||
end
|
||||
);
|
||||
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
} else {
|
||||
|
|
|
@ -611,6 +611,7 @@ if ($delete) {
|
|||
|
||||
echo "<div id='event_details_window'></div>";
|
||||
echo "<div id='event_response_window'></div>";
|
||||
echo "<div id='event_response_command_window' title='".__('Command')."'></div>";
|
||||
|
||||
ui_require_jquery_file('bgiframe');
|
||||
ui_require_javascript_file('pandora_events');
|
||||
|
|
Loading…
Reference in New Issue