Merge branch '1-acciones-masivas' into 'develop'
Add selection modules in "Bulk operations: Add action alerts and delete action alerts". #1 See merge request !15
This commit is contained in:
commit
2868ee3f2b
|
@ -52,7 +52,6 @@ $id_group = (int) get_parameter ('id_group');
|
|||
$id_agents = get_parameter ('id_agents');
|
||||
$id_alert_templates = (array) get_parameter ('id_alert_templates');
|
||||
$recursion = get_parameter ('recursion');
|
||||
|
||||
$add = (bool) get_parameter_post ('add');
|
||||
|
||||
if ($add) {
|
||||
|
@ -64,45 +63,61 @@ if ($add) {
|
|||
$fires_max = (int) get_parameter ('fires_max');
|
||||
|
||||
if (!empty($actions)) {
|
||||
$agent_alerts = agents_get_alerts($id_agents);
|
||||
$cont = 0;
|
||||
$agent_alerts_id = array();
|
||||
foreach ($agent_alerts['simple'] as $agent_alert) {
|
||||
if (in_array($agent_alert['id_alert_template'], $id_alert_templates)) {
|
||||
$agent_alerts_id[$cont] = $agent_alert['id'];
|
||||
$cont = $cont + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if ($fires_min > 0)
|
||||
$options['fires_min'] = $fires_min;
|
||||
if ($fires_max > 0)
|
||||
$options['fires_max'] = $fires_max;
|
||||
|
||||
if (empty($agent_alerts_id)) {
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No alerts selected'));
|
||||
}
|
||||
else {
|
||||
$results = true;
|
||||
foreach ($agent_alerts_id as $agent_alert_id) {
|
||||
foreach ($actions as $action) {
|
||||
$result = alerts_add_alert_agent_module_action($agent_alert_id, $action, $options);
|
||||
if ($result === false)
|
||||
$results = false;
|
||||
$modules = get_parameter ('module');
|
||||
$modules_id = array();
|
||||
if (!empty($modules)) {
|
||||
foreach ($modules as $module) {
|
||||
foreach ($id_agents as $id_agent) {
|
||||
$module_id = modules_get_agentmodule_id($module, $id_agent);
|
||||
$modules_id[] = $module_id['id_agente_modulo'];
|
||||
}
|
||||
}
|
||||
|
||||
db_pandora_audit("Massive management", "Add alert action " . json_encode($id_agents), false, false, 'Agents: ' .
|
||||
json_encode($id_agents) . ' Alerts : ' . json_encode($agent_alerts) .
|
||||
' Fires Min: ' . $fires_min . ' Fires Max: ' . $fires_max . ' Actions: ' . implode(',',$actions));
|
||||
$agent_alerts = agents_get_alerts($id_agents);
|
||||
$cont = 0;
|
||||
$agent_alerts_id = array();
|
||||
|
||||
ui_print_result_message ($results, __('Successfully added'), __('Could not be added'));
|
||||
foreach ($agent_alerts['simple'] as $agent_alert) {
|
||||
|
||||
if ((in_array($agent_alert['id_alert_template'], $id_alert_templates)) && (in_array($agent_alert['id_agent_module'], $modules_id))) {
|
||||
$agent_alerts_id[$cont] = $agent_alert['id'];
|
||||
$cont += 1;
|
||||
}
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if ($fires_min > 0)
|
||||
$options['fires_min'] = $fires_min;
|
||||
if ($fires_max > 0)
|
||||
$options['fires_max'] = $fires_max;
|
||||
|
||||
if (empty($agent_alerts_id)) {
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No alerts selected'));
|
||||
}
|
||||
else {
|
||||
$results = true;
|
||||
foreach ($agent_alerts_id as $agent_alert_id) {
|
||||
foreach ($actions as $action) {
|
||||
$result = alerts_add_alert_agent_module_action($agent_alert_id, $action, $options);
|
||||
if ($result === false)
|
||||
$results = false;
|
||||
}
|
||||
}
|
||||
|
||||
db_pandora_audit("Massive management", "Add alert action " . json_encode($id_agents), false, false, 'Agents: ' .
|
||||
json_encode($id_agents) . ' Alerts : ' . json_encode($agent_alerts) .
|
||||
' Fires Min: ' . $fires_min . ' Fires Max: ' . $fires_max . ' Actions: ' . implode(',',$actions));
|
||||
|
||||
ui_print_result_message ($results, __('Successfully added'), __('Could not be added'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No modules selected'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No action selected'));
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No actions selected'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,6 +165,15 @@ $table->data[2][0] .= '<span id="template_loading" class="invisible">';
|
|||
$table->data[2][0] .= html_print_image('images/spinner.png', true);
|
||||
$table->data[2][0] .= '</span>';
|
||||
$table->data[2][1] = html_print_select (array(), 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0);
|
||||
$table->data[2][2] = __('When select agents');
|
||||
$table->data[2][2] .= '<br>';
|
||||
$table->data[2][2] .= html_print_select (
|
||||
array('common' => __('Show common modules'),
|
||||
'all' => __('Show all modules'),'unknown' => __('Show unknown and not init modules')),
|
||||
'modules_selection_mode',
|
||||
'common', false, '', '', true);
|
||||
$table->data[2][3] = html_print_select (array(), 'module[]',
|
||||
$modules_select, false, '', '', true, true, false);
|
||||
|
||||
$actions = alerts_get_alert_actions ();
|
||||
$table->data[3][0] = __('Action');
|
||||
|
@ -233,6 +257,12 @@ $(document).ready (function () {
|
|||
update_alerts();
|
||||
});
|
||||
|
||||
$("#id_alert_templates").change(alert_templates_changed_by_multiple_agents_with_alerts);
|
||||
|
||||
$("#modules_selection_mode").click(function () {
|
||||
$("#id_alert_templates").trigger("change");
|
||||
});
|
||||
|
||||
function update_alerts() {
|
||||
var idAgents = Array();
|
||||
jQuery.each ($("#id_agents option:selected"), function (i, val) {
|
||||
|
|
|
@ -58,52 +58,65 @@ if ($delete) {
|
|||
$actions = get_parameter ('action');
|
||||
|
||||
if (!empty($actions)) {
|
||||
$agent_alerts = agents_get_alerts($id_agents);
|
||||
|
||||
$alerts_agent_modules = array();
|
||||
foreach ($agent_alerts['simple'] as $agent_alert) {
|
||||
if (in_array($agent_alert['id_alert_template'], $id_alert_templates)) {
|
||||
$alerts_agent_modules = array_merge($alerts_agent_modules, alerts_get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id'));
|
||||
$modules = (array) get_parameter ('module');
|
||||
$modules_id = array();
|
||||
if (!empty($modules)) {
|
||||
foreach ($modules as $module) {
|
||||
foreach ($id_agents as $id_agent) {
|
||||
$module_id = modules_get_agentmodule_id($module, $id_agent);
|
||||
$modules_id[] = $module_id['id_agente_modulo'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($alerts_agent_modules)) {
|
||||
ui_print_result_message (false, '',
|
||||
__('Could not be deleted. No alerts selected'));
|
||||
}
|
||||
else {
|
||||
$results = true;
|
||||
$agent_module_actions = array();
|
||||
|
||||
foreach ($alerts_agent_modules as $alert_agent_module) {
|
||||
$agent_module_actions = alerts_get_alert_agent_module_actions ($alert_agent_module['id'], array('id','id_alert_action'));
|
||||
|
||||
foreach ($agent_module_actions as $agent_module_action) {
|
||||
foreach ($actions as $action) {
|
||||
if ($agent_module_action['id_alert_action'] == $action) {
|
||||
$result = alerts_delete_alert_agent_module_action ($agent_module_action['id']);
|
||||
|
||||
if ($result === false)
|
||||
$results = false;
|
||||
}
|
||||
}
|
||||
|
||||
$agent_alerts = agents_get_alerts($id_agents);
|
||||
$alerts_agent_modules = array();
|
||||
foreach ($agent_alerts['simple'] as $agent_alert) {
|
||||
if ((in_array($agent_alert['id_alert_template'], $id_alert_templates)) && (in_array($agent_alert['id_agent_module'], $modules_id))) {
|
||||
$alerts_agent_modules = array_merge($alerts_agent_modules, alerts_get_alerts_agent_module ($agent_alert['id_agent_module'], true, false, 'id'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($results) {
|
||||
db_pandora_audit("Massive management", "Delete alert action", false, false,
|
||||
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
|
||||
' Actions: ' . implode(',',$actions));
|
||||
if (empty($alerts_agent_modules)) {
|
||||
ui_print_result_message (false, '',
|
||||
__('Could not be deleted. No alerts selected'));
|
||||
}
|
||||
else {
|
||||
db_pandora_audit("Massive management", "Fail try to delete alert action", false, false,
|
||||
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
|
||||
' Actions: ' . implode(',',$actions));
|
||||
$results = true;
|
||||
$agent_module_actions = array();
|
||||
|
||||
foreach ($alerts_agent_modules as $alert_agent_module) {
|
||||
$agent_module_actions = alerts_get_alert_agent_module_actions ($alert_agent_module['id'], array('id','id_alert_action'));
|
||||
|
||||
foreach ($agent_module_actions as $agent_module_action) {
|
||||
foreach ($actions as $action) {
|
||||
if ($agent_module_action['id_alert_action'] == $action) {
|
||||
$result = alerts_delete_alert_agent_module_action ($agent_module_action['id']);
|
||||
|
||||
if ($result === false)
|
||||
$results = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($results) {
|
||||
db_pandora_audit("Massive management", "Delete alert action", false, false,
|
||||
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
|
||||
' Actions: ' . implode(',',$actions));
|
||||
}
|
||||
else {
|
||||
db_pandora_audit("Massive management", "Fail try to delete alert action", false, false,
|
||||
'Agent: ' . json_encode($id_agents) . ' Alert templates: ' . json_encode($id_alert_templates) .
|
||||
' Actions: ' . implode(',',$actions));
|
||||
}
|
||||
|
||||
ui_print_result_message ($results,
|
||||
__('Successfully deleted'),
|
||||
__('Could not be deleted'));
|
||||
}
|
||||
|
||||
ui_print_result_message ($results,
|
||||
__('Successfully deleted'),
|
||||
__('Could not be deleted'));
|
||||
}
|
||||
else {
|
||||
ui_print_result_message (false, '', __('Could not be added').". ".__('No modules selected'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -143,9 +156,6 @@ $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion,
|
|||
true, false);
|
||||
|
||||
$table->data[1][0] = __('Agents with templates');
|
||||
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
|
||||
$table->data[1][0] .= html_print_image('images/spinner.png', true);
|
||||
$table->data[1][0] .= '</span>';
|
||||
$table->data[1][1] = html_print_select (array(),'id_agents[]', 0, false, '', '', true, true);
|
||||
|
||||
if (empty($id_agents)) {
|
||||
|
@ -155,10 +165,17 @@ else {
|
|||
$alert_templates = agents_get_alerts_simple ($id_agents);
|
||||
}
|
||||
$table->data[2][0] = __('Alert templates');
|
||||
$table->data[2][0] .= '<span id="template_loading" class="invisible">';
|
||||
$table->data[2][0] .= html_print_image('images/spinner.png', true);
|
||||
$table->data[2][0] .= '</span>';
|
||||
$table->data[2][1] = html_print_select (index_array ($alert_templates, 'id_alert_template', 'template_name'), 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0);
|
||||
$table->data[2][2] = __('When select agents');
|
||||
$table->data[2][2] .= '<br>';
|
||||
$table->data[2][2] .= html_print_select (
|
||||
array('common' => __('Show common modules'),
|
||||
'all' => __('Show all modules'),'unknown' => __('Show unknown and not init modules')),
|
||||
'modules_selection_mode',
|
||||
'common', false, '', '', true);
|
||||
$table->data[2][3] = html_print_select (array(), 'module[]',
|
||||
$modules_select, false, '', '', true, true, false);
|
||||
|
||||
|
||||
$actions = alerts_get_alert_actions ();
|
||||
$table->data[3][0] = __('Action');
|
||||
|
@ -221,6 +238,12 @@ $(document).ready (function () {
|
|||
update_alerts();
|
||||
});
|
||||
|
||||
$("#id_alert_templates").change(alert_templates_changed_by_multiple_agents_with_alerts);
|
||||
|
||||
$("#modules_selection_mode").click(function () {
|
||||
$("#id_alert_templates").trigger("change");
|
||||
});
|
||||
|
||||
function update_alerts() {
|
||||
var idAgents = Array();
|
||||
jQuery.each ($("#id_agents option:selected"), function (i, val) {
|
||||
|
|
|
@ -373,6 +373,78 @@ function agent_changed_by_multiple_agents_with_alerts (event, id_agent, selected
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill up select box with id "module" with modules with alerts of one or more templates
|
||||
* before agent has been selected, but this not empty the select box.s
|
||||
*
|
||||
* @param event that has been triggered
|
||||
* @param id_agent Agent ID that has been selected
|
||||
* @param selected Which module(s) have to be selected
|
||||
*/
|
||||
function alert_templates_changed_by_multiple_agents_with_alerts (event, id_agent, selected) {
|
||||
var idAgents = Array();
|
||||
|
||||
jQuery.each ($("#id_agents option:selected"), function (i, val) {
|
||||
//val() because the var is same <option val="NNN"></option>
|
||||
idAgents.push($(val).val());
|
||||
});
|
||||
|
||||
var selection_mode = $('#modules_selection_mode').val();
|
||||
if(selection_mode == undefined) {
|
||||
selection_mode = 'common';
|
||||
}
|
||||
|
||||
templates = Array();
|
||||
jQuery.each ($("#id_alert_templates option:selected"), function (i, val) {
|
||||
//val() because the var is same <option val="NNN"></option>
|
||||
templates.push($(val).val());
|
||||
});
|
||||
|
||||
console.log(templates);
|
||||
|
||||
$('#module').attr ('disabled', 1);
|
||||
$('#module').empty ();
|
||||
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
|
||||
jQuery.post ('ajax.php',
|
||||
{"page": "operation/agentes/ver_agente",
|
||||
"get_agent_modules_alerts_json_for_multiple_agents": 1,
|
||||
"templates[]": templates,
|
||||
"id_agent[]": idAgents,
|
||||
"selection_mode": selection_mode
|
||||
},
|
||||
function (data) {
|
||||
$('#module').empty ();
|
||||
|
||||
if (typeof($(document).data('text_for_module')) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html ($(document).data('text_for_module')).attr("value", 0).prop('selected', true));
|
||||
}
|
||||
else {
|
||||
if (typeof(data['any_text']) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html (data['any_text']).attr ("value", 0).prop('selected', true));
|
||||
}
|
||||
else {
|
||||
var anyText = $("#any_text").html(); //Trick for catch the translate text.
|
||||
|
||||
if (anyText == null) {
|
||||
anyText = 'Any';
|
||||
}
|
||||
|
||||
$('#module').append ($('<option></option>').html (anyText).attr ("value", 0).prop('selected', true));
|
||||
}
|
||||
}
|
||||
jQuery.each (data, function (i, val) {
|
||||
s = js_html_entity_decode(val);
|
||||
$('#module').append ($('<option></option>').html (s).attr ("value", val));
|
||||
$('#module').fadeIn ('normal');
|
||||
});
|
||||
if (selected != undefined)
|
||||
$('#module').attr ('value', selected);
|
||||
$('#module').removeAttr('disabled');
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill up select box with id "agent" with agents after module has been selected, but this not empty the select box.s
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ if (is_ajax ()) {
|
|||
$get_modules_group_json = (bool) get_parameter ("get_modules_group_json");
|
||||
$get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents");
|
||||
$get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents");
|
||||
$get_agent_modules_multiple_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_multiple_alerts_json_for_multiple_agents");
|
||||
$get_agents_json_for_multiple_modules = (bool) get_parameter("get_agents_json_for_multiple_modules");
|
||||
$get_agent_modules_json_for_multiple_agents_id = (bool) get_parameter("get_agent_modules_json_for_multiple_agents_id");
|
||||
$get_agentmodule_status_tooltip = (bool) get_parameter ("get_agentmodule_status_tooltip");
|
||||
|
@ -273,6 +274,46 @@ if (is_ajax ()) {
|
|||
}
|
||||
|
||||
if ($get_agent_modules_alerts_json_for_multiple_agents) {
|
||||
$idAgents = (array) get_parameter('id_agent');
|
||||
$templates = (array) get_parameter('templates');
|
||||
|
||||
$selection_mode = get_parameter('selection_mode','common');
|
||||
|
||||
$sql = 'SELECT DISTINCT(nombre)
|
||||
FROM tagente_modulo t1, talert_template_modules t2
|
||||
WHERE t2.id_agent_module = t1.id_agente_modulo
|
||||
AND delete_pending = 0
|
||||
AND id_alert_template IN (' . implode(',', $templates) . ')
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')';
|
||||
|
||||
if ($selection_mode == 'common') {
|
||||
$sql .= ' AND (
|
||||
SELECT count(nombre)
|
||||
FROM tagente_modulo t3, talert_template_modules t4
|
||||
WHERE t4.id_agent_module = t3.id_agente_modulo
|
||||
AND delete_pending = 0 AND t1.nombre = t3.nombre
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')
|
||||
AND id_alert_template IN (' . implode(',', $templates) . ')) = (' . count($idAgents) . ')';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY t1.nombre';
|
||||
|
||||
$nameModules = db_get_all_rows_sql($sql);
|
||||
|
||||
if ($nameModules == false) {
|
||||
$nameModules = array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($nameModules as $nameModule) {
|
||||
$result[] = io_safe_output($nameModule['nombre']);
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_agent_modules_multiple_alerts_json_for_multiple_agents) {
|
||||
$idAgents = get_parameter('id_agent');
|
||||
$id_template = get_parameter('template');
|
||||
|
||||
|
|
Loading…
Reference in New Issue