Feature: Search by status module in bulk module delete/edit actions. Ticket: #4190

This commit is contained in:
m-lopez-f 2016-11-17 12:49:30 +01:00
parent 01a79da14d
commit 5f6aaa1d05
5 changed files with 99 additions and 6 deletions

View File

@ -460,7 +460,19 @@ $table->data['form_agents_2'][1] = html_print_select($status_list,
'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true);
$table->data['form_agents_2'][3] = '';
$table->rowclass['form_modules_3'] = '';
$table->data['form_modules_3'][0] = __('Module Status');
$table->colspan['form_modules_3'][1] = 2;
$status_list = array ();
$status_list[AGENT_MODULE_STATUS_NORMAL] = __('Normal');
$status_list[AGENT_MODULE_STATUS_WARNING] = __('Warning');
$status_list[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical');
$status_list[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown');
$status_list[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal');
$status_list[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init');
$table->data['form_modules_3'][1] = html_print_select($status_list,
'status_module', 'selected', '', __('All'), AGENT_MODULE_STATUS_ALL, true);
$table->data['form_modules_3'][3] = '';
$table->rowstyle['form_modules_2'] = 'vertical-align: top;';
$table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2';
@ -569,6 +581,10 @@ $(document).ready (function () {
if (this.value != '0')
params['id_tipo_modulo'] = this.value;
var status_module = $('#status_module').val();
if (status_module != '-1')
params['status_module'] = status_module;
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit2").hide ();
$("#module_name").attr ("disabled", "disabled")
@ -712,6 +728,16 @@ $(document).ready (function () {
return false;
}
});
$("#status_module").change(function() {
selector = $("#form_modules input[name=selection_mode]:checked").val();
if(selector == 'agents') {
$("#id_agents").trigger("change");
}
else if(selector == 'modules') {
$("#module_type").trigger("change");
}
});
});
/* ]]> */
</script>

View File

@ -288,6 +288,19 @@ $table->data['form_agents_1'][3] = __('Select all modules of this group') . ' '
'', 'style="margin-right: 40px;"', true);
$table->rowclass['form_modules_3'] = '';
$table->data['form_modules_3'][0] = __('Module Status');
$table->colspan['form_modules_3'][1] = 2;
$status_list = array ();
$status_list[AGENT_MODULE_STATUS_NORMAL] = __('Normal');
$status_list[AGENT_MODULE_STATUS_WARNING] = __('Warning');
$status_list[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical');
$status_list[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown');
$status_list[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal');
$status_list[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init');
$table->data['form_modules_3'][1] = html_print_select($status_list,
'status_module', 'selected', '', __('All'), AGENT_MODULE_STATUS_ALL, true);
$table->data['form_modules_3'][3] = '';
$table->rowstyle['form_modules_2'] = 'vertical-align: top;';
$table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2';
@ -304,10 +317,8 @@ $table->data['form_modules_2'][2] .= html_print_select (
$table->data['form_modules_2'][3] = html_print_select (array(), 'agents[]',
$agents_select, false, __('None'), 0, true, true, false);
$table->rowclass['form_agents_2'] = 'select_agents_row';
$table->data['form_agents_2'][0] = __('Status');
$table->data['form_agents_2'][0] = __('Agent Status');
$table->colspan['form_agents_2'][1] = 2;
$status_list = array ();
$status_list[AGENT_STATUS_NORMAL] = __('Normal');
@ -684,6 +695,10 @@ $(document).ready (function () {
if (this.value != '0')
params['id_tipo_modulo'] = this.value;
var status_module = $('#status_module').val();
if (status_module != '-1')
params['status_module'] = status_module;
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit2").hide ();
$("#module_name").attr ("disabled", "disabled")
@ -701,6 +716,7 @@ $(document).ready (function () {
"json"
);
});
function show_form() {
$("td#delete_table-0-1, " +
"td#delete_table-edit1-1, " +
@ -869,7 +885,7 @@ $(document).ready (function () {
$("#id_agents").change (show_form);
$("#form_edit input[name=selection_mode]").change (function () {
selector = this.value;
selector = $("#form_edit input[name=selection_mode]:checked").val();
clean_lists();
if(selector == 'agents') {
@ -966,6 +982,17 @@ $(document).ready (function () {
$("#status_agents").change(function() {
$("#groups_select").trigger("change");
});
$("#status_module").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
if(selector == 'agents') {
$("#id_agents").trigger("change");
}
else if(selector == 'modules') {
$("#module_type").trigger("change");
}
});
});
/* ]]> */
</script>

View File

@ -1169,6 +1169,9 @@ function agents_get_modules ($id_agent = null, $details = false,
break;
}
}
else if (preg_match('/\bin\b/i',$field)) {
array_push ($fields, $field.' '.$value);
}
else {
switch ($config["dbtype"]) {
case "mysql":

View File

@ -157,6 +157,15 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
}
}
var module_status = -1;
if (typeof $("#status_module") !== 'undefined') {
try {
module_status = $("#status_module").val();
}
catch (error) {
}
}
// Module name
var module_name = $("#text-module_filter").val();
@ -222,7 +231,8 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
"name": module_name,
"selection_mode": selection_mode,
"serialized": serialized,
"id_server": id_server
"id_server": id_server,
"status_module": module_status
},
function (data) {
$('#module').empty ();
@ -382,6 +392,15 @@ function module_changed_by_multiple_modules (event, id_module, selected) {
$('#agents').empty ();
$('#agents').append ($('<option></option>').html ("Loading...").attr ("value", 0));
var status_module = -1;
if (typeof $("#status_module") !== 'undefined') {
try {
status_module = $("#status_module").val();
}
catch (error) {
}
}
var selection_mode = $('#agents_selection_mode').val();
if(selection_mode == undefined) {
selection_mode = 'common';
@ -390,6 +409,7 @@ function module_changed_by_multiple_modules (event, id_module, selected) {
jQuery.post('ajax.php',
{"page": "operation/agentes/ver_agente",
"get_agents_json_for_multiple_modules": 1,
"status_module": status_module,
"module_name[]": idModules,
"selection_mode": selection_mode
},

View File

@ -145,6 +145,7 @@ if (is_ajax ()) {
if ($get_agents_json_for_multiple_modules) {
$nameModules = get_parameter('module_name');
$selection_mode = get_parameter('selection_mode','common');
$status_modulo = (int) get_parameter ('status_module', -1);
$groups = users_get_groups ($config["id_user"], "AW", false);
$group_id_list = ($groups ? join(",",array_keys($groups)):"0");
@ -155,6 +156,10 @@ if (is_ajax ()) {
AND t1.id_grupo IN (' . $group_id_list .')
AND t2.nombre IN (\'' . implode('\',\'', $nameModules) . '\')';
if ($status_modulo != -1) {
$sql .= ' AND t2.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = ' . $status_modulo . ') ';
}
if ($selection_mode == 'common') {
$sql .= 'AND (
SELECT count(t3.nombre)
@ -225,6 +230,7 @@ if (is_ajax ()) {
$selection_mode = get_parameter('selection_mode', 'common');
$serialized = get_parameter('serialized', '');
$id_server = (int) get_parameter('id_server', 0);
$status_modulo = (int) get_parameter ('status_module', -1);
$metaconsole_server_name = null;
if (!empty($id_server)) {
$metaconsole_server_name = db_get_value('server_name',
@ -261,6 +267,11 @@ if (is_ajax ()) {
}
}
if ($status_modulo != -1) {
$filter .= ' AND t1.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = ' . $status_modulo . ')';
}
if (is_metaconsole()) {
$result = array();
$nameModules = array();
@ -442,6 +453,7 @@ HAVING count(nombre) = (SELECT count(nombre) FROM tagente_modulo))';
$delete_pending = (int) get_parameter ('delete_pending', -1);
// Use 0 as not received
$id_tipo_modulo = (int) get_parameter ('id_tipo_modulo', 0);
$status_modulo = (int) get_parameter ('status_module', -1);
// Filter
$filter = array();
@ -454,6 +466,11 @@ HAVING count(nombre) = (SELECT count(nombre) FROM tagente_modulo))';
if (empty($filter))
$filter = false;
if ($status_modulo != -1) {
$filter['id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where estado = '.$status_modulo.') ';
}
$get_id_and_name = (bool) get_parameter ('get_id_and_name');
$get_distinct_name = (bool) get_parameter ('get_distinct_name');