Merge branch 'ent-9884-Carga-restauracion-de-filtros-en-la-vista-de-monitores' into 'develop'
implement filter save and load feature in monitor view See merge request artica/pandorafms!5431
This commit is contained in:
commit
35aa64b281
|
@ -2,6 +2,26 @@ START TRANSACTION;
|
|||
|
||||
ALTER TABLE `tserver` ADD COLUMN `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
|
||||
`id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_name` VARCHAR(600) NOT NULL,
|
||||
`id_group_filter` INT NOT NULL DEFAULT 0,
|
||||
`ag_group` INT NOT NULL DEFAULT 0,
|
||||
`recursion` TEXT,
|
||||
`status` INT NOT NULL DEFAULT -1,
|
||||
`ag_modulename` TEXT,
|
||||
`ag_freestring` TEXT,
|
||||
`tag_filter` TEXT,
|
||||
`moduletype` TEXT,
|
||||
`module_option` INT DEFAULT 1,
|
||||
`modulegroup` INT NOT NULL DEFAULT -1,
|
||||
`min_hours_status` TEXT,
|
||||
`datatype` TEXT,
|
||||
`not_condition` TEXT,
|
||||
`ag_custom_fields` TEXT,
|
||||
PRIMARY KEY (`id_filter`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tsesion_filter` (
|
||||
`id_filter` INT NOT NULL AUTO_INCREMENT,
|
||||
`id_name` TEXT NULL,
|
||||
|
|
|
@ -68,6 +68,12 @@ if (check_login()) {
|
|||
0
|
||||
);
|
||||
|
||||
$load_filter_modal = get_parameter('load_filter_modal', 0);
|
||||
$save_filter_modal = get_parameter('save_filter_modal', 0);
|
||||
$get_monitor_filters = get_parameter('get_monitor_filters', 0);
|
||||
$save_monitor_filter = get_parameter('save_monitor_filter', 0);
|
||||
$update_monitor_filter = get_parameter('update_monitor_filter', 0);
|
||||
|
||||
if ($get_agent_modules_json_by_name === true) {
|
||||
$agent_name = get_parameter('agent_name');
|
||||
|
||||
|
@ -1661,6 +1667,534 @@ if (check_login()) {
|
|||
}
|
||||
|
||||
echo json_encode($children_selected);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Saves an event filter.
|
||||
if ($save_monitor_filter) {
|
||||
$values = [];
|
||||
$values['id_name'] = get_parameter('id_name');
|
||||
$values['id_group_filter'] = get_parameter('id_group_filter');
|
||||
$values['ag_group'] = get_parameter('ag_group');
|
||||
$values['modulegroup'] = get_parameter('modulegroup');
|
||||
$values['recursion'] = get_parameter('recursion');
|
||||
$values['status'] = get_parameter('status');
|
||||
$values['ag_modulename'] = get_parameter('ag_modulename');
|
||||
$values['ag_freestring'] = get_parameter('ag_freestring');
|
||||
$values['tag_filter'] = json_encode(get_parameter('tag_filter'));
|
||||
$values['moduletype'] = get_parameter('moduletype');
|
||||
$values['module_option'] = get_parameter('module_option');
|
||||
$values['min_hours_status'] = get_parameter('min_hours_status');
|
||||
$values['datatype'] = get_parameter('datatype');
|
||||
$values['not_condition'] = get_parameter('not_condition');
|
||||
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
|
||||
|
||||
$exists = (bool) db_get_value_filter(
|
||||
'id_filter',
|
||||
'tmonitor_filter',
|
||||
$values
|
||||
);
|
||||
|
||||
if ($exists === true) {
|
||||
echo 'duplicate';
|
||||
} else {
|
||||
$result = db_process_sql_insert('tmonitor_filter', $values);
|
||||
|
||||
if ($result === false) {
|
||||
echo 'error';
|
||||
} else {
|
||||
echo $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($update_monitor_filter) {
|
||||
$values = [];
|
||||
$id = get_parameter('id');
|
||||
|
||||
$values['ag_group'] = get_parameter('ag_group');
|
||||
$values['modulegroup'] = get_parameter('modulegroup');
|
||||
$values['recursion'] = get_parameter('recursion');
|
||||
$values['status'] = get_parameter('status');
|
||||
$values['ag_modulename'] = get_parameter('ag_modulename');
|
||||
$values['ag_freestring'] = get_parameter('ag_freestring');
|
||||
$values['tag_filter'] = json_encode(get_parameter('tag_filter'));
|
||||
$values['moduletype'] = get_parameter('moduletype');
|
||||
$values['module_option'] = get_parameter('module_option');
|
||||
$values['min_hours_status'] = get_parameter('min_hours_status');
|
||||
$values['datatype'] = get_parameter('datatype');
|
||||
$values['not_condition'] = get_parameter('not_condition');
|
||||
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
|
||||
|
||||
$result = db_process_sql_update(
|
||||
'tmonitor_filter',
|
||||
$values,
|
||||
['id_filter' => $id]
|
||||
);
|
||||
|
||||
if ($result === false) {
|
||||
echo 'error';
|
||||
} else {
|
||||
echo 'ok';
|
||||
}
|
||||
}
|
||||
|
||||
if ($get_monitor_filters) {
|
||||
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
|
||||
|
||||
$monitor_filters = db_get_all_rows_sql($sql);
|
||||
|
||||
$result = [];
|
||||
|
||||
if ($monitor_filters !== false) {
|
||||
foreach ($monitor_filters as $monitor_filter) {
|
||||
$result[$monitor_filter['id_filter']] = $monitor_filter['id_name'];
|
||||
}
|
||||
}
|
||||
|
||||
echo io_json_mb_encode($result);
|
||||
}
|
||||
|
||||
if ((int) $load_filter_modal === 1) {
|
||||
$user_groups = users_get_groups(
|
||||
$config['id_user'],
|
||||
'AR',
|
||||
users_can_manage_group_all(),
|
||||
true
|
||||
);
|
||||
|
||||
$sql = 'SELECT id_filter, id_name
|
||||
FROM tmonitor_filter
|
||||
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
|
||||
|
||||
$event_filters = db_get_all_rows_sql($sql);
|
||||
|
||||
$filters = [];
|
||||
foreach ($event_filters as $event_filter) {
|
||||
$filters[$event_filter['id_filter']] = $event_filter['id_name'];
|
||||
}
|
||||
|
||||
echo '<div id="load-filter-select" class="load-filter-modal">';
|
||||
echo '<form method="post" id="form_load_filter" action="index.php?sec=view&sec2=operation/agentes/status_monitor&pure=">';
|
||||
|
||||
$table = new StdClass;
|
||||
$table->id = 'load_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->cellspacing = 4;
|
||||
$table->cellpadding = 4;
|
||||
$table->class = 'databox';
|
||||
if (is_metaconsole()) {
|
||||
$table->cellspacing = 0;
|
||||
$table->cellpadding = 0;
|
||||
$table->class = 'databox filters';
|
||||
}
|
||||
|
||||
$table->styleTable = 'font-weight: bold; color: #555; text-align:left;';
|
||||
$filter_id_width = '200px';
|
||||
if (is_metaconsole()) {
|
||||
$filter_id_width = '150px';
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$table->rowid[3] = 'update_filter_row1';
|
||||
$data[0] = __('Load filter').$jump;
|
||||
$data[0] .= html_print_select(
|
||||
$filters,
|
||||
'filter_id',
|
||||
$current,
|
||||
'',
|
||||
__('None'),
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'margin-left:5px; width:'.$filter_id_width.';'
|
||||
);
|
||||
$data[1] = html_print_submit_button(
|
||||
__('Load filter'),
|
||||
'load_filter',
|
||||
false,
|
||||
'class="sub upd"',
|
||||
true
|
||||
);
|
||||
$data[1] .= html_print_input_hidden('load_filter', 1, true);
|
||||
$table->data[] = $data;
|
||||
$table->rowclass[] = '';
|
||||
|
||||
html_print_table($table);
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
function show_filter() {
|
||||
$("#load-filter-select").dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: false,
|
||||
closeOnEscape: true,
|
||||
width: 450
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
show_filter();
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
if ($save_filter_modal) {
|
||||
echo '<div id="save-filter-select">';
|
||||
if (check_acl($config['id_user'], 0, 'AW')) {
|
||||
echo '<div id="#info_box"></div>';
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->cellspacing = 4;
|
||||
$table->cellpadding = 4;
|
||||
$table->class = 'databox';
|
||||
if (is_metaconsole()) {
|
||||
$table->class = 'databox filters';
|
||||
$table->cellspacing = 0;
|
||||
$table->cellpadding = 0;
|
||||
}
|
||||
|
||||
$table->styleTable = 'font-weight: bold; text-align:left;';
|
||||
if (!is_metaconsole()) {
|
||||
$table->style[0] = 'width: 50%; width:50%;';
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$table->rowid[0] = 'update_save_selector';
|
||||
$data[0] = html_print_radio_button(
|
||||
'filter_mode',
|
||||
'new',
|
||||
'',
|
||||
true,
|
||||
true
|
||||
).__('New filter').'';
|
||||
|
||||
$data[1] = html_print_radio_button(
|
||||
'filter_mode',
|
||||
'update',
|
||||
'',
|
||||
false,
|
||||
true
|
||||
).__('Update filter').'';
|
||||
|
||||
$table->data[] = $data;
|
||||
$table->rowclass[] = '';
|
||||
|
||||
$data = [];
|
||||
$table->rowid[1] = 'save_filter_row1';
|
||||
$data[0] = __('Filter name').$jump;
|
||||
$data[0] .= html_print_input_text('id_name', '', '', 15, 255, true);
|
||||
if (is_metaconsole()) {
|
||||
$data[1] = __('Save in Group').$jump;
|
||||
} else {
|
||||
$data[1] = __('Filter group').$jump;
|
||||
}
|
||||
|
||||
$user_groups_array = users_get_groups_for_select(
|
||||
$config['id_user'],
|
||||
'AW',
|
||||
users_can_manage_group_all(),
|
||||
true
|
||||
);
|
||||
|
||||
$data[1] .= html_print_select(
|
||||
$user_groups_array,
|
||||
'id_group_filter_dialog',
|
||||
$id_group_filter,
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
'w130'
|
||||
);
|
||||
|
||||
$table->data[] = $data;
|
||||
$table->rowclass[] = '';
|
||||
|
||||
$data = [];
|
||||
$table->rowid[2] = 'save_filter_row2';
|
||||
|
||||
$table->data[] = $data;
|
||||
$table->rowclass[] = '';
|
||||
|
||||
$data = [];
|
||||
$table->rowid[3] = 'update_filter_row1';
|
||||
$data[0] = __('Overwrite filter').$jump;
|
||||
|
||||
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
|
||||
$monitor_filters = db_get_all_rows_sql($sql);
|
||||
|
||||
$_filters_update = [];
|
||||
|
||||
if ($monitor_filters !== false) {
|
||||
foreach ($monitor_filters as $monitor_filter) {
|
||||
$_filters_update[$monitor_filter['id_filter']] = $monitor_filter['id_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$data[0] .= html_print_select(
|
||||
$_filters_update,
|
||||
'overwrite_filter',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
true
|
||||
);
|
||||
$data[1] = html_print_submit_button(
|
||||
__('Update filter'),
|
||||
'update_filter',
|
||||
false,
|
||||
'class="sub upd" onclick="save_update_filter();"',
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[] = $data;
|
||||
$table->rowclass[] = '';
|
||||
|
||||
html_print_table($table);
|
||||
echo '<div>';
|
||||
echo html_print_submit_button(
|
||||
__('Save filter'),
|
||||
'save_filter',
|
||||
false,
|
||||
'class="sub upd float-right" onclick="save_new_filter();"',
|
||||
true
|
||||
);
|
||||
echo '</div>';
|
||||
} else {
|
||||
include 'general/noaccess.php';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function show_save_filter() {
|
||||
$('#save_filter_row1').show();
|
||||
$('#save_filter_row2').show();
|
||||
$('#update_filter_row1').hide();
|
||||
// Filter save mode selector
|
||||
$("[name='filter_mode']").click(function() {
|
||||
if ($(this).val() == 'new') {
|
||||
$('#save_filter_row1').show();
|
||||
$('#save_filter_row2').show();
|
||||
$('#submit-save_filter').show();
|
||||
$('#update_filter_row1').hide();
|
||||
}
|
||||
else {
|
||||
$('#save_filter_row1').hide();
|
||||
$('#save_filter_row2').hide();
|
||||
$('#update_filter_row1').show();
|
||||
$('#submit-save_filter').hide();
|
||||
}
|
||||
});
|
||||
$("#save-filter-select").dialog({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: false,
|
||||
closeOnEscape: true
|
||||
});
|
||||
}
|
||||
|
||||
function save_new_filter() {
|
||||
// If the filter name is blank show error
|
||||
if ($('#text-id_name').val() == '') {
|
||||
$('#show_filter_error').html("<h3 class='error'><?php echo __('Filter name cannot be left blank'); ?></h3>");
|
||||
|
||||
// Close dialog
|
||||
$('.ui-dialog-titlebar-close').trigger('click');
|
||||
return false;
|
||||
}
|
||||
|
||||
var custom_fields_values = $('input[name^="ag_custom_fields"]').map(function() {
|
||||
return this.value;
|
||||
}).get();
|
||||
|
||||
var custom_fields_ids = $("input[name^='ag_custom_fields']").map(function() {
|
||||
var name = $(this).attr("name");
|
||||
var number = name.match(/\[(.*?)\]/)[1];
|
||||
|
||||
return number;
|
||||
}).get();
|
||||
|
||||
var ag_custom_fields = custom_fields_ids.reduce(function(result, custom_fields_id, index) {
|
||||
result[custom_fields_id] = custom_fields_values[index];
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
var id_filter_save;
|
||||
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||
{
|
||||
"page" : "include/ajax/module",
|
||||
"save_monitor_filter" : 1,
|
||||
"id_name": $("#text-id_name").val(),
|
||||
"id_group_filter": $("#id_group_filter_dialog").val(),
|
||||
"ag_group" : $("#ag_group").val(),
|
||||
"modulegroup" : $("#modulegroup").val(),
|
||||
"recursion" : $("#checkbox-recursion").is(':checked'),
|
||||
"status" : $("#status").val(),
|
||||
"severity" : $("#severity").val(),
|
||||
"ag_modulename" : $("#text-ag_modulename").val(),
|
||||
"ag_freestring" : $("#text-ag_freestring").val(),
|
||||
"tag_filter" : $("#tag_filter").val(),
|
||||
"moduletype" : $("#moduletype").val(),
|
||||
"module_option" : $('#module_option').val(),
|
||||
"min_hours_status" : $('#text-min_hours_status').val(),
|
||||
"datatype" : $("#datatype").val(),
|
||||
"not_condition" : $("#not_condition_switch").is(':checked'),
|
||||
"ag_custom_fields": JSON.stringify(ag_custom_fields),
|
||||
},
|
||||
function (data) {
|
||||
$("#info_box").hide();
|
||||
if (data == 'error') {
|
||||
$("#info_box").filter(function(i, item) {
|
||||
if ($(item).data('type_info_box') == "error_create_filter") {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}).show();
|
||||
}
|
||||
else if (data == 'duplicate') {
|
||||
$("#info_box").filter(function(i, item) {
|
||||
if ($(item).data('type_info_box') == "duplicate_create_filter") {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}).show();
|
||||
}
|
||||
else {
|
||||
id_filter_save = data;
|
||||
|
||||
$("#info_box").filter(function(i, item) {
|
||||
if ($(item).data('type_info_box') == "success_create_filter") {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}).show();
|
||||
}
|
||||
|
||||
// Close dialog.
|
||||
$("#save-filter-select").dialog('close');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function save_update_filter() {
|
||||
var id_filter_update = $("#overwrite_filter").val();
|
||||
var name_filter_update = $("#overwrite_filter option[value='"+id_filter_update+"']").text();
|
||||
|
||||
var custom_fields_values = $('input[name^="ag_custom_fields"]').map(function() {
|
||||
return this.value;
|
||||
}).get();
|
||||
|
||||
var custom_fields_ids = $("input[name^='ag_custom_fields']").map(function() {
|
||||
var name = $(this).attr("name");
|
||||
var number = name.match(/\[(.*?)\]/)[1];
|
||||
|
||||
return number;
|
||||
}).get();
|
||||
|
||||
var ag_custom_fields = custom_fields_ids.reduce(function(result, custom_fields_id, index) {
|
||||
result[custom_fields_id] = custom_fields_values[index];
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||
{
|
||||
"page" : "include/ajax/module",
|
||||
"update_monitor_filter" : 1,
|
||||
"id" : $("#overwrite_filter").val(),
|
||||
"ag_group" : $("#ag_group").val(),
|
||||
"modulegroup" : $("#modulegroup").val(),
|
||||
"recursion" : $("#checkbox-recursion").is(':checked'),
|
||||
"status" : $("#status").val(),
|
||||
"severity" : $("#severity").val(),
|
||||
"ag_modulename" : $("#text-ag_modulename").val(),
|
||||
"ag_freestring" : $("#text-ag_freestring").val(),
|
||||
"tag_filter" : $("#tag_filter").val(),
|
||||
"moduletype" : $("#moduletype").val(),
|
||||
"module_option" : $('#module_option').val(),
|
||||
"min_hours_status" : $('#text-min_hours_status').val(),
|
||||
"datatype" : $("#datatype").val(),
|
||||
"not_condition" : $("#not_condition_switch").is(':checked'),
|
||||
"ag_custom_fields": JSON.stringify(ag_custom_fields),
|
||||
},
|
||||
function (data) {
|
||||
$(".info_box").hide();
|
||||
if (data == 'ok') {
|
||||
$(".info_box").filter(function(i, item) {
|
||||
if ($(item).data('type_info_box') == "success_update_filter") {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}).show();
|
||||
}
|
||||
else {
|
||||
$(".info_box").filter(function(i, item) {
|
||||
if ($(item).data('type_info_box') == "error_create_filter") {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
|
||||
// First remove all options of filters select
|
||||
$('#filter_id').find('option').remove().end();
|
||||
// Add 'none' option the first
|
||||
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('none')."'"; ?> ).attr ("value", 0));
|
||||
// Reload filters select
|
||||
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||
{
|
||||
"page" : "include/ajax/module",
|
||||
"get_monitor_filters" : 1
|
||||
},
|
||||
function (data) {
|
||||
jQuery.each (data, function (i, val) {
|
||||
s = js_html_entity_decode(val);
|
||||
if (i == id_filter_update) {
|
||||
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
|
||||
}
|
||||
else {
|
||||
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
|
||||
}
|
||||
});
|
||||
},
|
||||
"json"
|
||||
);
|
||||
|
||||
// Close dialog
|
||||
$('.ui-dialog-titlebar-close').trigger('click');
|
||||
|
||||
// Update the info with the loaded filter
|
||||
$("#hidden-id_name").val($('#text-id_name').val());
|
||||
$('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update);
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
show_save_filter();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ if (! defined('METACONSOLE')) {
|
|||
}
|
||||
|
||||
$recursion = get_parameter_switch('recursion', false);
|
||||
|
||||
if ($recursion === false) {
|
||||
$recursion = get_parameter('recursion', false);
|
||||
}
|
||||
|
@ -132,7 +133,7 @@ $refr = (int) get_parameter('refr', 0);
|
|||
$offset = (int) get_parameter('offset', 0);
|
||||
$status = (int) get_parameter('status', 4);
|
||||
$modulegroup = (int) get_parameter('modulegroup', -1);
|
||||
$tag_filter = (int) get_parameter('tag_filter', 0);
|
||||
$tag_filter = get_parameter('tag_filter', [0]);
|
||||
$min_hours_status = (string) get_parameter('min_hours_status', '');
|
||||
// Sort functionality.
|
||||
$sortField = get_parameter('sort_field');
|
||||
|
@ -220,6 +221,71 @@ if (is_numeric($ag_group)) {
|
|||
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
|
||||
}
|
||||
|
||||
$load_filter_id = (int) get_parameter('filter_id', 0);
|
||||
|
||||
if ($load_filter_id > 0) {
|
||||
$user_groups_fl = users_get_groups(
|
||||
$config['id_user'],
|
||||
'AR',
|
||||
users_can_manage_group_all(),
|
||||
true
|
||||
);
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT id_filter, id_name
|
||||
FROM tmonitor_filter
|
||||
WHERE id_filter = %d AND id_group_filter IN (%s)',
|
||||
$load_filter_id,
|
||||
implode(',', array_keys($user_groups_fl))
|
||||
);
|
||||
|
||||
$loaded_filter = db_get_row_sql($sql);
|
||||
}
|
||||
|
||||
if ($loaded_filter['id_filter'] > 0) {
|
||||
$query_filter['id_filter'] = $load_filter_id;
|
||||
$filter = db_get_row_filter('tmonitor_filter', $query_filter, false);
|
||||
if ($filter !== false) {
|
||||
$ag_group = $filter['ag_group'];
|
||||
$recursion = $filter['recursion'];
|
||||
$status = $filter['status'];
|
||||
$modulegroup = $filter['modulegroup'];
|
||||
$ag_modulename = $filter['ag_modulename'];
|
||||
$ag_freestring = $filter['ag_freestring'];
|
||||
$tag_filter = $filter['tag_filter'];
|
||||
$moduletype = $filter['moduletype'];
|
||||
$module_option = $filter['module_option'];
|
||||
$min_hours_status = $filter['min_hours_status'];
|
||||
$datatype = $filter['datatype'];
|
||||
$not_condition = $filter['not_condition'];
|
||||
$ag_custom_fields = $filter['ag_custom_fields'];
|
||||
|
||||
if ($not_condition === 'false') {
|
||||
$not_condition = '';
|
||||
}
|
||||
|
||||
if ($not_condition !== '') {
|
||||
$is_none = 'None';
|
||||
$not_condition = 'NOT';
|
||||
}
|
||||
|
||||
if ($not_condition !== '') {
|
||||
$condition_query = '!=';
|
||||
}
|
||||
|
||||
if (is_array($tag_filter) === false) {
|
||||
$tag_filter = json_decode($tag_filter, true);
|
||||
}
|
||||
if ($tag_filter === '') {
|
||||
$tag_filter = [0 => 0];
|
||||
}
|
||||
|
||||
if (is_array($ag_custom_fields) === false) {
|
||||
$ag_custom_fields = json_decode(io_safe_output($ag_custom_fields), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Agent group selector.
|
||||
if (!$is_metaconsole) {
|
||||
if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) {
|
||||
|
@ -370,19 +436,21 @@ if (!empty($ag_custom_fields)) {
|
|||
}
|
||||
}
|
||||
|
||||
$all_tags = in_array(0, $tag_filter);
|
||||
|
||||
// Filter by tag.
|
||||
if ($tag_filter !== 0) {
|
||||
if ($is_metaconsole) {
|
||||
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN (
|
||||
SELECT ttag_module.id_agente_modulo
|
||||
FROM ttag_module
|
||||
WHERE ttag_module.id_tag '.$not_condition.' IN ('.$tag_filter.'))';
|
||||
} else {
|
||||
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN (
|
||||
SELECT ttag_module.id_agente_modulo
|
||||
FROM ttag_module
|
||||
WHERE ttag_module.id_tag '.$condition_query.' '.$tag_filter.')';
|
||||
if ($all_tags === false) {
|
||||
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN (
|
||||
SELECT ttag_module.id_agente_modulo
|
||||
FROM ttag_module
|
||||
WHERE 1=1';
|
||||
|
||||
if ($all_tags === false) {
|
||||
$sql_conditions .= ' AND ttag_module.id_tag '.$not_condition.' IN ('.implode(',', $tag_filter).'))';
|
||||
}
|
||||
} else if ($not_condition === 'NOT') {
|
||||
// Match nothing if not condition has been selected along with all tags selected (none).
|
||||
$sql_conditions .= ' AND 0=0';
|
||||
}
|
||||
|
||||
|
||||
|
@ -475,13 +543,14 @@ $table->data[0][1] .= html_print_select_groups(
|
|||
false,
|
||||
$not_condition
|
||||
);
|
||||
|
||||
$table->data[0][1] .= '</div><div>';
|
||||
$table->data[0][1] .= html_print_input(
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'name' => 'recursion',
|
||||
'return' => true,
|
||||
'checked' => $recursion,
|
||||
'checked' => ($recursion === true || $recursion === 'true' || $recursion === '1') ? 'checked' : false,
|
||||
'value' => 1,
|
||||
]
|
||||
);
|
||||
|
@ -556,13 +625,13 @@ if (empty($tags)) {
|
|||
} else {
|
||||
$table->data[1][5] = html_print_select(
|
||||
$tags,
|
||||
'tag_filter',
|
||||
'tag_filter[]',
|
||||
$tag_filter,
|
||||
'',
|
||||
__($is_none),
|
||||
'',
|
||||
__('All'),
|
||||
0,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
|
@ -666,7 +735,6 @@ $table2->data[1][0] = '<span id="datatypetittle"';
|
|||
$table2->data[1][0] .= '>'.__('Data type').'</span>';
|
||||
$table2->data[1][1] .= '<div id="datatypebox">';
|
||||
|
||||
|
||||
switch ($moduletype) {
|
||||
case 1:
|
||||
$sql = sprintf(
|
||||
|
@ -771,7 +839,7 @@ $table2->data[1][3] = html_print_div(
|
|||
'type' => 'switch',
|
||||
'name' => 'not_condition',
|
||||
'return' => false,
|
||||
'checked' => $check_not_condition,
|
||||
'checked' => ($check_not_condition === true || $check_not_condition === 'true' || $check_not_condition === '1') ? 'checked' : false,
|
||||
'value' => 'NOT',
|
||||
'id' => 'not_condition_switch',
|
||||
'onclick' => 'changeNotConditionStatus(this)',
|
||||
|
@ -855,9 +923,30 @@ $table->data[3][0] = ui_toggle(
|
|||
'white_table_graph'
|
||||
);
|
||||
|
||||
$table->colspan[4][0] = 7;
|
||||
$table->colspan[4][0] = 2;
|
||||
$table->cellstyle[4][0] = 'padding-top: 0px;';
|
||||
$table->data[4][0] = html_print_submit_button(
|
||||
$table->data[4][0] = html_print_button(
|
||||
__('Load filter'),
|
||||
'load-filter',
|
||||
false,
|
||||
'',
|
||||
'class="float-left margin-right-2 sub config"',
|
||||
true
|
||||
);
|
||||
|
||||
$table->cellstyle[4][0] .= 'padding-top: 0px;';
|
||||
$table->data[4][0] .= html_print_button(
|
||||
__('Save filter'),
|
||||
'save-filter',
|
||||
false,
|
||||
'',
|
||||
'class="float-left margin-right-2 sub wand"',
|
||||
true
|
||||
);
|
||||
|
||||
$table->colspan[4][2] = 5;
|
||||
$table->cellstyle[4][2] = 'padding-top: 0px;';
|
||||
$table->data[4][2] = html_print_submit_button(
|
||||
__('Show'),
|
||||
'uptbutton',
|
||||
false,
|
||||
|
@ -2017,16 +2106,76 @@ if (!empty($result)) {
|
|||
}
|
||||
|
||||
|
||||
// End Build List Result.
|
||||
echo "<div id='monitor_details_window'></div>";
|
||||
// End Build List Result.
|
||||
echo "<div id='monitor_details_window'></div>";
|
||||
|
||||
enterprise_hook('close_meta_frame');
|
||||
// Load filter div for dialog.
|
||||
echo '<div id="load-modal-filter" style="display:none"></div>';
|
||||
echo '<div id="save-modal-filter" style="display:none"></div>';
|
||||
|
||||
ui_require_javascript_file('pandora_modules');
|
||||
enterprise_hook('close_meta_frame');
|
||||
|
||||
ui_require_javascript_file('pandora_modules');
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
var loading = 0;
|
||||
|
||||
/* Filter management */
|
||||
$('#button-load-filter').click(function (event) {
|
||||
// event.preventDefault();
|
||||
|
||||
if($('#load-filter-select').length) {
|
||||
$('#load-filter-select').dialog();
|
||||
} else {
|
||||
if (loading == 0) {
|
||||
loading = 1
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '<?php echo ui_get_full_url('ajax.php'); ?>',
|
||||
data: {
|
||||
page: 'include/ajax/module',
|
||||
load_filter_modal: 1
|
||||
},
|
||||
success: function (data){
|
||||
$('#load-modal-filter')
|
||||
.empty()
|
||||
.html(data);
|
||||
|
||||
loading = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#button-save-filter').click(function (){
|
||||
// event.preventDefault();
|
||||
if($('#save-filter-select').length) {
|
||||
$('#save-filter-select').dialog();
|
||||
} else {
|
||||
if (loading == 0) {
|
||||
loading = 1
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '<?php echo ui_get_full_url('ajax.php'); ?>',
|
||||
data: {
|
||||
page: 'include/ajax/module',
|
||||
save_filter_modal: 1,
|
||||
current_filter: $('#latest_filter_id').val()
|
||||
},
|
||||
success: function (data){
|
||||
$('#save-modal-filter')
|
||||
.empty()
|
||||
.html(data);
|
||||
loading = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(!document.getElementById('not_condition_switch').checked){
|
||||
document.getElementById("select2-ag_group-container").innerHTML = "None";
|
||||
|
||||
|
@ -2149,12 +2298,10 @@ function changeNotConditionStatus() {
|
|||
$("#modulegroup").select2().val(["None"]).trigger("change");
|
||||
$("#tag_filter").select2().val(["None"]).trigger("change");
|
||||
|
||||
|
||||
document.getElementById("select2-status-container").innerHTML = "None";
|
||||
document.getElementById("select2-moduletype-container").innerHTML = "None";
|
||||
document.getElementById("select2-ag_group-container").innerHTML = "None";
|
||||
document.getElementById("select2-modulegroup-container").innerHTML = "None";
|
||||
document.getElementById("select2-tag_filter-container").innerHTML = "None";
|
||||
|
||||
}else {
|
||||
$('select[name=datatypebox] > option:first-child').val('All');
|
||||
|
@ -2176,7 +2323,6 @@ function changeNotConditionStatus() {
|
|||
document.getElementById("select2-moduletype-container").innerHTML = "All";
|
||||
document.getElementById("select2-ag_group-container").innerHTML = "All";
|
||||
document.getElementById("select2-modulegroup-container").innerHTML = "All";
|
||||
document.getElementById("select2-tag_filter-container").innerHTML = "All";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4154,3 +4154,26 @@ CREATE TABLE IF NOT EXISTS `tbackup` (
|
|||
`filepath` VARCHAR(512) DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
-- ---------------------------------------------------------------------
|
||||
-- Table `tmonitor_filter`
|
||||
-- ---------------------------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
|
||||
`id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_name` VARCHAR(600) NOT NULL,
|
||||
`id_group_filter` INT NOT NULL DEFAULT 0,
|
||||
`ag_group` INT NOT NULL DEFAULT 0,
|
||||
`recursion` TEXT,
|
||||
`status` INT NOT NULL DEFAULT -1,
|
||||
`ag_modulename` TEXT,
|
||||
`ag_freestring` TEXT,
|
||||
`tag_filter` TEXT,
|
||||
`moduletype` TEXT,
|
||||
`module_option` INT DEFAULT 1,
|
||||
`modulegroup` INT NOT NULL DEFAULT -1,
|
||||
`min_hours_status` TEXT,
|
||||
`datatype` TEXT,
|
||||
`not_condition` TEXT,
|
||||
`ag_custom_fields` TEXT,
|
||||
PRIMARY KEY (`id_filter`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
|
Loading…
Reference in New Issue