#9478 create edit delete alerts from meta

This commit is contained in:
Jonathan 2023-04-27 16:05:37 +02:00
parent 0b5672980d
commit fdc13256cd
7 changed files with 362 additions and 97 deletions

View File

@ -40,7 +40,24 @@ $table->size = [];
$table->style[0] = 'width: 50%';
$table->style[1] = 'width: 50%';
// Add an agent selector
if (is_metaconsole() === true) {
$params = [];
$params['return'] = true;
$params['show_helptip'] = true;
$params['input_name'] = 'id_agent';
$params['selectbox_id'] = 'id_agent_module';
$params['javascript_is_function_select'] = true;
$params['metaconsole_enabled'] = true;
$params['use_hidden_input_idagent'] = true;
$params['print_hidden_input_idagent'] = true;
$params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax';
$table->data[0][0] = html_print_label_input_block(
__('Agent'),
'<div class="w100p">'.ui_print_agent_autocomplete_input($params).'</div>'
);
} else {
// Add an agent selector.
if (! $id_agente) {
$params = [];
$params['return'] = true;
@ -57,11 +74,12 @@ if (! $id_agente) {
);
}
$modules = [];
if ($id_agente) {
$modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]);
}
}
$modules = [];
$table->data[0][1] = html_print_label_input_block(
__('Module'),
@ -319,7 +337,8 @@ $(document).ready (function () {
jQuery.post (<?php echo "'".ui_get_full_url(false, false, false, false)."'"; ?> + "ajax.php",
{"page" : "operation/agentes/estado_agente",
"get_agent_module_last_value" : 1,
"id_agent_module" : this.value
"id_agent_module" : this.value,
"server_name" : $('#text-id_agent').val(),
},
function (data, status) {
if (data === false) {
@ -338,5 +357,4 @@ $(document).ready (function () {
);
});
});
/* ]]> */
</script>

View File

@ -99,6 +99,19 @@ if ($update_alert) {
}
if ($create_alert) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
$id_alert_template = (int) get_parameter('template');
$id_agent_module = (int) get_parameter('id_agent_module');
@ -203,9 +216,28 @@ if ($create_alert) {
}
}
}
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
echo '<script>window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")</script>';
}
}
if ($delete_alert) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
$id_alert_agent_module = (int) get_parameter('id_alert');
$temp = db_get_row('talert_template_modules', 'id', $id_alert_agent_module);
@ -241,6 +273,11 @@ if ($delete_alert) {
'',
true
);
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
echo '<script>window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")</script>';
}
}
if ($add_action) {
@ -283,6 +320,19 @@ if ($add_action) {
}
if ($update_action) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
$alert_id = (int) get_parameter('alert_id');
$id_action = (int) get_parameter('action_select_ajax-'.$alert_id);
$id_module_action = (int) get_parameter('id_module_action_ajax');
@ -321,9 +371,28 @@ if ($update_action) {
'',
true
);
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
echo '<script>window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")</script>';
}
}
if ($delete_action) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
$id_action = (int) get_parameter('id_action');
$id_alert = (int) get_parameter('id_alert');
@ -348,6 +417,11 @@ if ($delete_action) {
'',
true
);
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
}
}
if ($enable_alert) {

View File

@ -406,6 +406,19 @@ if ($get_actions_module) {
}
if ($show_update_action_menu) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
if (! check_acl($config['id_user'], 0, 'LW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
@ -436,7 +449,12 @@ if ($show_update_action_menu) {
$id_action
);
if (is_metaconsole()) {
$data .= '<form id="update_action-'.$id_alert.'" method="post" action="index.php?sec=galertas&sec2=godmode/alerts/alert_list">';
} else {
$data .= '<form id="update_action-'.$id_alert.'" method="post" style="height:85%;">';
}
$data .= '<table class="w100p bg_color222" style="height:100%;">';
$data .= html_print_input_hidden(
'update_action',
@ -453,6 +471,11 @@ if ($show_update_action_menu) {
$id_action,
true
);
$data .= html_print_input_hidden(
'id_agent',
$server_name,
true
);
if (! $id_agente) {
$data .= '<tr class="datos2">';
$data .= '<td class="datos2 bolder pdd_6px font_10pt">';
@ -571,6 +594,11 @@ if ($show_update_action_menu) {
true
);
$data .= '</form>';
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
}
echo $data;
return;
}
@ -933,6 +961,7 @@ if ($get_agent_alerts_datatable === true) {
$tmp->last_fired = $row[7];
$tmp->status = $row[8];
$tmp->validate = $row[9];
$tmp->actions = $row[10];
} else {
// Open.
$tmp->standby = $row[0];

View File

@ -1139,6 +1139,7 @@ function ui_format_alert_row(
'last_fired' => 7,
'status' => 8,
'validate' => 9,
'actions' => 10,
];
} else {
$index = [
@ -1458,6 +1459,69 @@ function ui_format_alert_row(
}
$data[$index['status']] = ui_print_status_image($status, $title, true);
$data[$index['status']] .= '<div id="update_action-div-'.$alert['id'].'" class="invisible">';
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$connection = metaconsole_get_connection($agente['server_name']);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
$action = db_get_all_rows_filter(
'talert_template_module_actions',
['id_alert_template_module' => $alert['id']],
'id'
)[0];
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
}
// Edit.
$tableActionButtons[] = html_print_input_image(
'update_action',
'/images/edit.svg',
1,
'padding:0px;',
true,
[
'title' => __('Update action'),
'class' => 'main_menu_icon invert_filter',
'onclick' => 'show_display_update_action(\''.$action['id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['id'].'\',\''.$alert['agent_name'].'\')',
]
);
$tableActionButtons[] = html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true);
$tableActionButtons[] = '<form class="delete_alert_form display_in" action="index.php?sec=galertas&sec2=godmode/alerts/alert_list&tab=list" method="post" >';
$tableActionButtons[] = html_print_input_image(
'delete',
'images/delete.svg',
1,
'',
true,
[
'title' => __('Delete'),
'class' => 'invert_filter main_menu_icon',
]
);
$tableActionButtons[] = html_print_input_hidden('delete_alert', 1, true);
$tableActionButtons[] = html_print_input_hidden('id_alert', $alert['id'], true);
$tableActionButtons[] = html_print_input_hidden('id_agent', $alert['agent_name'], true);
$tableActionButtons[] = '</form>';
$data[$index['actions']] = html_print_div(
[
'style' => 'padding-top: 8px;',
'content' => implode('', $tableActionButtons),
],
true
);
}
return $data;
}
@ -3626,6 +3690,8 @@ function ui_print_datatable(array $parameters)
} else {
$pagination_options = [
[
// There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows.
// -1 Retun error or only 1 row.
$parameters['default_pagination'],
5,
10,
@ -3634,7 +3700,7 @@ function ui_print_datatable(array $parameters)
200,
500,
1000,
-1,
18446744073709551615,
],
[
$parameters['default_pagination'],

View File

@ -314,12 +314,18 @@ if (is_metaconsole() === false) {
}
}
if (is_metaconsole()) {
array_push($column_names, ['text' => 'actions']);
array_push($columns, 'actions');
}
if (is_metaconsole() === true) {
$no_sortable_columns = [
0,
1,
2,
5,
-1,
];
} else {
if (enterprise_installed() === true) {
@ -468,7 +474,17 @@ if (is_metaconsole() === false) {
}
}
} else {
html_print_action_buttons('');
echo "<form method='post' action='index.php?sec=galertas&sec2=godmode/alerts/alert_list&tab=builder&pure=0'>";
html_print_action_buttons(
html_print_submit_button(
__('Create alert'),
'submit',
false,
[ 'icon' => 'next'],
true
)
);
echo '</form>';
}
$html_content = ob_get_clean();
@ -565,7 +581,6 @@ function alerts_table_controls() {
}
}).change();
function validateAlerts() {
var alert_ids = [];
@ -601,6 +616,46 @@ function alerts_table_controls() {
},
});
}
function show_display_update_action(id_module_action, alert_id, alert_id_agent_module, action_id,id_agent='') {
$.each($('[id^="update_action-div"]'), function(){
$(this).html('');
});
var params = [];
params.push("show_update_action_menu=1");
params.push("id_agent_module=" + alert_id_agent_module);
params.push("id_module_action=" + id_module_action);
params.push("id_alert=" + alert_id);
params.push("id_action=" + action_id);
params.push("id_agent=" + id_agent);
params.push("page=include/ajax/alert_list.ajax");
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action="<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
success: function (data) {
$('#update_action-div-'+alert_id).html(data);
$('#update_action-div-'+alert_id).dialog ({
resizable: true,
draggable: true,
title: '<?php echo __('Update action'); ?>',
modal: true,
overlay: {
opacity: 0.5,
background: "black"
},
open: function() {
$('#action_select_ajax-'+alert_id).select2();
},
onclose: function() {
$('#update_action-div-'+alert_id).html("");
},
width: 600,
height: 350,
})
.show ();
}
});
}
</script>

View File

@ -94,6 +94,19 @@ if (is_ajax() === true) {
}
if ($get_agent_module_last_value === true) {
if (is_metaconsole()) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_name = explode(' ', io_safe_output(get_parameter('server_name')))[0];
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
echo json_encode(false);
// Restore db connection.
metaconsole_restore_db();
return;
}
}
}
$id_module = (int) get_parameter('id_agent_module');
$id_agent = (int) modules_get_agentmodule_agent((int) $id_module);
if (! check_acl_one_of_groups($config['id_user'], agents_get_all_groups_agent($id_agent), 'AR')) {
@ -132,6 +145,11 @@ if (is_ajax() === true) {
}
}
if (is_metaconsole()) {
// Restore db connection.
metaconsole_restore_db();
}
echo json_encode($value);
return;
}

View File

@ -929,7 +929,12 @@ if (is_ajax()) {
if (is_metaconsole() && !$force_local_modules) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
if (empty($server_name)) {
$server_name = explode(' ', io_safe_output($agentName))[0];
}
$connection = metaconsole_get_connection($server_name);
if ($server_id > 0) {
$connection = metaconsole_get_connection_by_id($server_id);
}