Feature to update action assignate a alert and module. Internal Ticket: #3994

This commit is contained in:
m-lopez-f 2016-09-01 09:09:03 +02:00
parent 82fab282dc
commit e914b3c87c
4 changed files with 188 additions and 13 deletions

View File

@ -332,11 +332,11 @@ if ($id_agente) {
else {
ui_pagination ($total, 'index.php?sec='.$sec.'&sec2=godmode/alerts/alert_list' . $form_params . $sort_params);
}
$simple_alerts = agents_get_alerts_simple ($id_agents, false,
array ('offset' => (int) get_parameter ('offset'),
'limit' => $config['block_size'], 'order' => $order), $where, false);
$offset = get_parameter('offset');
$offset = (int) get_parameter('offset');
$simple_alerts = agents_get_alerts_simple ($id_agents, false,
array ('offset' => $offset,
'limit' => $config['block_size'], 'order' => $order), $where, false);
if (!$id_agente) {
$url = 'index.php?sec='.$sec.'&sec2=godmode/alerts/alert_list&tab=list&pure='.$pure.'&offset=' . $offset . $form_params;
@ -347,7 +347,7 @@ else {
$table = new stdClass();
if ( defined("METACONSOLE") )
if ( is_metaconsole() )
$table->class = 'alert_list databox';
else
$table->class = 'databox data';
@ -497,6 +497,7 @@ foreach ($simple_alerts as $alert) {
$data[2] .= "<td></td>";
$data[2] .= "</tr>";
}
foreach ($actions as $action_id => $action) {
$data[2] .= "<tr>";
$data[2] .= "<td>";
@ -534,19 +535,27 @@ foreach ($simple_alerts as $alert) {
// Is possible manage actions if have LW permissions in the agent group of the alert module
if (check_acl ($config['id_user'], $agent_group, "LW")) {
$data[2] .= '<form method="post" action="' . $url . '" class="delete_link" style="display: inline; vertical-align: -50%;">';
$data[2] .= html_print_input_image ('delete',
'images/cross.png', 1, 'padding:0px;', true,
array('title' => __('Delete action')));
$data[2] .= html_print_input_hidden ('delete_action', 1, true);
$data[2] .= html_print_input_hidden ('id_alert', $alert['id'], true);
$data[2] .= html_print_input_hidden ('id_action', $action_id, true);
$data[2] .= '</form>';
//~ $data[2] .= '<form method="post" action="' . $url . '" class="delete_link" style="display: inline; vertical-align: -50%;">';
$data[2] .= '<form method="post" action="' . $url . '" class="delete_link" style="display: inline;">';
$data[2] .= html_print_input_image ('delete',
'images/cross.png', 1, 'padding:0px;', true,
array('title' => __('Delete action')));
$data[2] .= html_print_input_hidden ('delete_action', 1, true);
$data[2] .= html_print_input_hidden ('id_alert', $alert['id'], true);
$data[2] .= html_print_input_hidden ('id_action', $action_id, true);
$data[2] .= '</form>';
$data[2] .= html_print_input_image ('update_action',
'images/config.png', 1, 'padding:0px;', true,
array('title' => __('Update action'),
'onclick' => 'show_display_update_action(\''.$action['id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action_id.'\',\''.$alert['id_agent_module'].'\')'));
$data[2] .= html_print_input_hidden ('id_agent_module', $alert['id_agent_module'], true);
}
$data[2] .= "</td>";
$data[2] .= "</tr>";
}
$data[2] .= '<div id="update_action-div" style="display:none;text-align:left">';
$data[2] .= '</div>';
$data[2] .= '</table>';
// Is possible manage actions if have LW permissions in the agent group of the alert module
if (check_acl ($config['id_user'], $agent_group, "LW")) {
@ -828,5 +837,38 @@ function show_add_action(id_alert) {
.show ();
}
function show_display_update_action(id_module_action, alert_id, alert_id_agent_module, action_id) {
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("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").html (data);
$("#update_action-div").hide ()
.dialog ({
resizable: true,
draggable: true,
title: '<?php echo __('Update action'); ?>',
modal: true,
overlay: {
opacity: 0.5,
background: "black"
},
width: 500,
height: 300
})
.show ();
}
});
}
/* ]]> */
</script>

View File

@ -42,6 +42,7 @@ else {
$create_alert = (bool) get_parameter ('create_alert');
$add_action = (bool) get_parameter ('add_action');
$update_action = (bool) get_parameter ('update_action');
$delete_action = (bool) get_parameter ('delete_action');
$delete_alert = (bool) get_parameter ('delete_alert');
$disable_alert = (bool) get_parameter ('disable_alert');
@ -167,6 +168,33 @@ if ($add_action) {
__('Successfully added'), __('Could not be added'), '', true);
}
if ($update_action) {
$id_action = (int) get_parameter ('action_select_ajax');
$id_module_action = (int) get_parameter ('id_module_action_ajax');
$fires_min = (int) get_parameter ('fires_min_ajax');
$fires_max = (int) get_parameter ('fires_max_ajax');
$values = array ();
if ($fires_min != -1)
$values['fires_min'] = $fires_min;
if ($fires_max != -1)
$values['fires_max'] = $fires_max;
$values['module_action_threshold'] = (int) get_parameter ('module_action_threshold_ajax');
$values['id_alert_action'] = $id_action;
$result = alerts_update_alert_agent_module_action ($id_module_action, $values);
if ($result) {
db_pandora_audit("Alert management", 'Update action ' . $id_action . ' in alert ' . $id_alert_module);
}
else {
db_pandora_audit("Alert management", 'Fail to updated action ' . $id_action . ' in alert ' . $id_alert_module);
}
$messageAction = ui_print_result_message ($result,
__('Successfully updated'), __('Could not be updated'), '', true);
}
if ($delete_action) {
$id_action = (int) get_parameter ('id_action');
$id_alert = (int) get_parameter ('id_alert');

View File

@ -32,6 +32,7 @@ $get_agent_alerts_simple = (bool) get_parameter ('get_agent_alerts_simple');
$disable_alert = (bool) get_parameter ('disable_alert');
$enable_alert = (bool) get_parameter ('enable_alert');
$get_actions_module = (bool) get_parameter ('get_actions_module');
$show_update_action_menu = (bool) get_parameter ('show_update_action_menu');
if ($get_agent_alerts_simple) {
$id_agent = (int) get_parameter ('id_agent');
@ -104,5 +105,76 @@ if ($get_actions_module) {
echo json_encode ($alerts_modules);
return;
}
if ($show_update_action_menu) {
$id_agent_module = (int) get_parameter ('id_agent_module');
$id_module_action = (int) get_parameter ('id_module_action');
$id_agent = (int) get_parameter ('id_agent');
$id_alert = (int) get_parameter ('id_alert');
$module_name = modules_get_agentmodule_name ($id_agent_module);
$id_agent = modules_get_agentmodule_agent ($id_agent_module);
$agent_name = agents_get_name ($id_agent);
$id_action = (int) get_parameter ('id_action');
$actions = alerts_get_alert_agent_module_actions ($id_alert);
$action_opction = db_get_row ('talert_template_module_actions', 'id', $id_module_action);
$data .= '<form id="update_action-'.$alert['id'] . '" method="post">';
$data .= '<table class="databox_color" style="width:100%">';
$data .= html_print_input_hidden ('update_action', 1, true);
$data .= html_print_input_hidden ('id_module_action_ajax', $id_module_action, true);
if (! $id_agente) {
$data .= '<tr class="datos2">';
$data .= '<td class="datos2" style="font-weight:bold;padding:6px;">';
$data .= __('Agent');
$data .= '</td>';
$data .= '<td class="datos">';
$data .= ui_print_truncate_text($agent_name, 'agent_small', false, true, true, '[&hellip;]');
$data .= '</td>';
$data .= '</tr>';
}
$data .= '<tr class="datos">';
$data .= '<td class="datos" style="font-weight:bold;padding:6px;">';
$data .= __('Module');
$data .= '</td>';
$data .= '<td class="datos">';
$data .= ui_print_truncate_text($module_name, 'module_small', false, true, true, '[&hellip;]');
$data .= '</td>';
$data .= '</tr>';
$data .= '<tr class="datos2">';
$data .= '<td class="datos2" style="font-weight:bold;padding:6px;">';
$data .= __('Action');
$data .= '</td>';
$data .= '<td class="datos2">';
$data .= html_print_select ($actions, 'action_select_ajax', $id_action, '', __('None'), 0, true, false, true, '', false, 'width:150px');
$data .= '</td>';
$data .= '</tr>';
$data .= '<tr class="datos">';
$data .= '<td class="datos" style="font-weight:bold;padding:6px;">';
$data .= __('Number of alerts match from') . '&nbsp;' . ui_print_help_icon ("alert-matches", true, ui_get_full_url(false, false, false, false));
$data .= '</td>';
$data .= '<td class="datos">';
$data .= html_print_input_text ('fires_min_ajax', $action_opction['fires_min'], '', 4, 10, true);
$data .= ' '.__('to').' ';
$data .= html_print_input_text ('fires_max_ajax', $action_opction['fires_max'], '', 4, 10, true);
$data .= '</td>';
$data .= '</tr>';
$data .= '<tr class="datos2">';
$data .= '<td class="datos2" style="font-weight:bold;padding:6px;">';
$data .= __('Threshold') . "&nbsp;" . ui_print_help_icon ('action_threshold', true, ui_get_full_url(false, false, false, false));
$data .= '</td>';
$data .= '<td class="datos2">';
$data .= html_print_input_text ('module_action_threshold_ajax', $action_opction['module_action_threshold'], '', 4, 10, true);
$data .= '</td>';
$data .= '</tr>';
$data .= '</table>';
$data .= html_print_submit_button (__('Update'), 'updbutton', false, array('class' => "sub next", 'style' => "float:right"), true);
$data .= '</form>';
echo $data;
return;
}
return;
?>

View File

@ -1223,6 +1223,39 @@ function alerts_add_alert_agent_module_action ($id_alert_template_module, $id_al
}
}
/**
* Update an action to an alert associated to a module.
*
* @param int Id of register.
* @param mixed Options of the action.
*
* @return mixed Affected rows or false if something goes wrong.
*/
function alerts_update_alert_agent_module_action ($id_module_action, $options = false) {
global $config;
$values = array ();
$values['fires_max'] = 0;
$values['fires_min'] = 0;
$values['module_action_threshold'] = 0;
if ($options) {
$max = 0;
$min = 0;
if (isset ($options['fires_max']))
$values['fires_max'] = $options['fires_max'];
if (isset ($options['fires_min']))
$values['fires_min'] = $options['fires_min'];
if (isset ($options['module_action_threshold']))
$values['module_action_threshold'] = (int) $options['module_action_threshold'];
if (isset ($options['id_alert_action']))
$values['id_alert_action'] = (int) $options['id_alert_action'];
}
return (@db_process_sql_update ('talert_template_module_actions',
$values,
array ('id' => $id_module_action))) !== false;
}
/**
* Delete an action to an alert associated to a module.
*