Merge branch 'ent-12594-mejorar-vista-de-scheduled-reports' into 'develop'

Ent 12594 mejorar vista de scheduled reports

See merge request artica/pandorafms!6975
This commit is contained in:
Rafael Ameijeiras 2024-03-12 08:58:05 +00:00
commit 623095146e
7 changed files with 642 additions and 25 deletions

View File

@ -159,4 +159,8 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` (
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
ALTER TABLE `tserver` ADD COLUMN `disabled` BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE `tuser_task_scheduled` ADD COLUMN `id_report` INT NULL AFTER `id_user_task`;
ALTER TABLE `tuser_task_scheduled` ADD COLUMN `name` VARCHAR(255) NULL AFTER `id_user_task`;
COMMIT;

View File

@ -0,0 +1,343 @@
<?php
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars.
global $config;
// Check ACL.
if (!check_acl($config['id_user'], 0, 'RW')
&& !check_acl($config['id_user'], 0, 'RM')
) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access SNMP Filter Management'
);
include 'general/noaccess.php';
return;
}
require 'include/functions_cron.php';
// Header.
ui_print_standard_header(
__('Schedule'),
'images/op_snmp.png',
false,
'',
false,
[],
[
[
'link' => '',
'label' => __('Reporting'),
],
[
'link' => '',
'label' => __('Custom Reports'),
],
]
);
$id_task = get_parameter('id_task', null);
$name = '';
$id_report = '';
$task = '';
$group = 0;
$schedule = '';
$console = '';
$date = '';
$time = '';
$args = '';
if (isset($id_task) === true) {
$row = db_get_row('tuser_task_scheduled', 'id', $id_task);
$name = $row['name'];
$id_report = $row['id_report'];
$task = $row['id_user_task'];
$group = $row['id_grupo'];
$schedule = $row['scheduled'];
$console = $row['id_console'];
$args = unserialize($row['args']);
$date = date('Y/m/d', $args['first_execution']);
$time = date('H:i:s', $args['first_execution']);
}
$table = new stdClass();
$traps_generator = '<form id="form_manage" class="max_floating_element_size" method="POST" action="index.php?sec=custom_report&sec2=godmode/reporting/schedule">';
$table->id = 'table_manage';
$table->width = '100%';
$table->class = 'filter-table-adv databox';
$table->size = [];
$table->data = [];
$table->size[0] = '50%';
$table->size[1] = '50%';
$table->data[0][0] = html_print_label_input_block(
__('Name'),
html_print_input_text(
'name',
$name,
'',
50,
255,
true
)
);
$reports = db_get_all_rows_sql('SELECT id_report, name FROM treport');
if ($reports !== false) {
$array_reports = [];
foreach ($reports as $row) {
$array_reports[$row['id_report']] = $row['name'];
}
}
$table->data[0][1] = html_print_label_input_block(
__('Report'),
html_print_select(
$array_reports,
'id_report',
$id_report,
'',
__('Select'),
-1,
true,
false,
true,
'w100p'
)
);
// Remove Send csv log in list new console task.
$tasks = get_tasks();
// Unset to take just Reports ones.
unset($tasks[4], $tasks[5], $tasks[6], $tasks[7]);
if (($key = array_search('Send csv log', $tasks)) !== false) {
unset($tasks[$key]);
}
$table->data[1][0] = html_print_label_input_block(
__('Task'),
html_print_select(
$tasks,
'id_user_task',
$task,
'',
__('Select'),
-1,
true,
false,
false,
'',
false,
'width: 100%'
)
);
$table->data[1][1] = html_print_label_input_block(
__('Group'),
html_print_select_groups(
false,
'AR',
true,
'group',
$group,
'',
'',
'',
true,
false,
true,
'',
false,
'width: 100%',
false,
false,
false,
false,
false,
false,
false,
false,
true
)
);
$table->data[2][0] = html_print_label_input_block(
__('Scheduled'),
html_print_select(
cron_get_scheduled_options(),
'scheduled',
$schedule,
'',
'',
0,
true,
false,
false,
'',
false,
'width: 100%'
)
);
$table->data[2][1] = html_print_label_input_block(
__('Console'),
html_print_select(
$registered_consoles_opts,
'console',
$console,
'',
__('Any'),
0,
true,
false,
false,
'',
false,
'width: 100%'
)
);
$table->data[3][0] = html_print_label_input_block(
__('Next execution'),
html_print_input_text(
'date',
$date,
'',
50,
255,
true
)
);
$table->data[3][1] = html_print_label_input_block(
__('Hour'),
html_print_input_text(
'time',
$time,
'',
50,
255,
true
)
);
$table->colspan[4][0] = 2;
$table->data[4][0] = html_print_label_input_block(__('Parameters'), cron_render_parameters($task, $args, $id_report, true));
$traps_generator .= html_print_table($table, true);
if (isset($id_task) === true) {
$buttons[] = html_print_submit_button(
__('Update schedule'),
'btn_generate_trap',
false,
[
'class' => 'sub ok submitButton',
'icon' => 'next',
],
true
).html_print_input_hidden('update_schedule', 1, true).html_print_input_hidden('id', $id_task, true);
} else {
$buttons[] = html_print_submit_button(
__('Create schedule'),
'btn_generate_trap',
false,
[
'class' => 'sub ok submitButton',
'icon' => 'next',
],
true
).html_print_input_hidden('new_schedule', 1, true);
}
$buttons[] = html_print_button(
__('Go back'),
'button_back',
false,
'',
[
'icon' => 'back',
'mode' => 'secondary',
],
true
);
$traps_generator .= '<div class="action-buttons">'.html_print_action_buttons(implode('', $buttons), ['type' => 'form_action'], true).'</div>';
unset($table);
$traps_generator .= '</form>';
echo $traps_generator;
ui_require_css_file('datepicker');
ui_include_time_picker();
ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/');
?>
<script type="text/javascript">
$(document).ready(function() {
$('#text-time').timepicker({
showSecond: true,
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
timeText: '<?php echo __('Time'); ?>',
hourText: '<?php echo __('Hour'); ?>',
minuteText: '<?php echo __('Minute'); ?>',
secondText: '<?php echo __('Second'); ?>',
currentText: '<?php echo __('Now'); ?>',
closeText: '<?php echo __('Close'); ?>'});
$('#text-date').datepicker ({
dateFormat: '<?php echo DATE_FORMAT_JS; ?>',
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
firstDay: "<?php echo $config['datepicker_first_day']; ?>",
});
$('#id_user_task, #id_report').on('change', function() {
$.ajax({
url: 'ajax.php',
data: {
"page" : "enterprise/include/ajax/ConsoleTasks.ajax",
"get_task_parameters": 1,
"id_user_task": $('#id_user_task :selected').val(),
"id_report": $('#id_report :selected').val(),
},
type: 'POST',
success: function (data) {
$('#table_manage-4-0').find('table').html("");
$('#table_manage-4-0').append(data);
}
});
});
$('#button-btn_generate_trap').on('click', function() {
event.preventDefault();
var name = $('#text-name').val();
var report = $('#id_report :selected').val();
var task = $('#id_user_task :selected').val();
var group = $('#group :selected').val();
if (name !== '' && report !== '-1' && task !== '-1' && group !== '') {
$('#form_manage').submit();
} else {
confirmDialog({
title: "<?php echo __('Error'); ?>",
message: "<?php echo __('Name, Report, Task and Group are required.'); ?>",
hideCancelButton: true,
});
}
})
});
$('#button-button_back').on('click', function(){
window.location = '<?php echo ui_get_full_url('index.php?sec=custom_report&sec2=godmode/reporting/schedule'); ?>';
});
</script>

View File

@ -1282,24 +1282,6 @@ switch ($action) {
);
}
$discovery_tasklist = new DiscoveryTaskList();
$report_task_data = $discovery_tasklist->showListConsoleTask(true);
if (is_array($report_task_data) === true || (strpos($report_task_data, 'class="nf"') === false && $report_task_data !== -1)) {
$task_table = '<div class="mrgn_top_15px white_box">';
$task_table .= '<span class="white_table_graph_header">'.__('Report tasks');
$task_table .= ui_print_help_tip(__('To schedule a report, do it from the editing view of each report.'), true);
$task_table .= '</span><div>';
$task_table .= $report_task_data;
$task_table .= '</div></div>';
echo $task_table;
} else {
if ($report_task_data === -1) {
$report_task_data = '';
}
ui_print_info_message($report_task_data.__('To schedule a report, do it from the editing view of each report.'));
}
if (check_acl($config['id_user'], 0, 'RW')
|| check_acl($config['id_user'], 0, 'RM')
) {

View File

@ -0,0 +1,271 @@
<?php
/**
* Report item list.
*
* @category Reporting
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2023 Pandora FMS
* Please see https://pandorafms.com/community/ for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
global $config;
// Login check.
check_login();
if (!check_acl($config['id_user'], 0, 'RW')
&& !check_acl($config['id_user'], 0, 'RM')
) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access report builder'
);
include 'general/noaccess.php';
exit;
}
require_once $config['homedir'].'/include/functions_agents.php';
enterprise_include_once('include/functions_metaconsole.php');
// Header.
ui_print_standard_header(
__('Schedule'),
'images/op_reporting.png',
false,
'',
false,
[],
[
[
'link' => '',
'label' => __('Reporting'),
],
[
'link' => '',
'label' => __('Custom reports'),
],
]
);
$delete_task = get_parameter('delete_task', false);
if ($delete_task !== false) {
db_process_sql(sprintf('DELETE FROM tuser_task_scheduled WHERE id = %s', $delete_task));
ui_print_result_message(
true,
__('Successfully deleted')
);
}
$update_schedule = get_parameter('update_schedule', false);
if ($update_schedule === '1') {
enterprise_include_once('/godmode/wizards/ConsoleTasks.class.php');
$task = new ConsoleTasks(0, 'Default message. Not set.', '/images/wizard/consoletasks.png', 'Report Tasks', true);
$task->updateTask();
ui_print_result_message(
true,
__('Successfully updated')
);
}
$new_schedule = get_parameter('new_schedule', false);
if ($new_schedule === '1') {
$name = get_parameter('name', null);
$sql = sprintf('SELECT * FROM tuser_task_scheduled WHERE name = "%s"', $name);
if (db_get_all_rows_sql($sql) === false) {
enterprise_include_once('/godmode/wizards/ConsoleTasks.class.php');
$task = new ConsoleTasks(0, 'Default message. Not set.', '/images/wizard/consoletasks.png', 'Report Tasks', true);
$result = $task->createTask();
} else {
$result = false;
$_SESSION['report_task_msg'] = __('The schedule name is already in use.');
}
ui_print_result_message(
$result,
__('Successfully created'),
$_SESSION['report_task_msg']
);
}
$id_group = get_parameter('id_group', 0);
$search = get_parameter('search', '');
$table_aux = new stdClass();
$table_aux->width = '100%';
$table_aux->class = 'filter-table-adv';
$table_aux->size[0] = '50%';
$table_aux->size[1] = '50%';
$table_aux->data[0][0] = html_print_label_input_block(
__('Group'),
html_print_select_groups(
false,
$access,
true,
'id_group',
$id_group,
'',
'',
'',
true,
false,
true,
'',
false,
'',
false,
false,
'id_grupo'
)
);
$table_aux->data[0][1] = html_print_label_input_block(
__('Free text for search: ').ui_print_help_tip(
__('Search by report name or description, list matches.'),
true
),
html_print_input_text(
__('search'),
$search,
'',
30,
'',
true
)
);
$where = '';
if ((bool) users_is_admin() === false) {
$where = sprintf(' AND id_usuario = "%s"', $config['id_user']);
}
$sql = 'SELECT * FROM tuser_task_scheduled WHERE id_user_task IN (1,2,3,4) '.$where;
$reports = db_get_all_rows_sql($sql);
if ($reports !== false) {
$table = new stdClass();
$table->class = 'info_table';
$table->width = '100%';
$table->data = [];
$table->head[0] = __('Name');
$table->head[1] = __('Report');
$table->head[2] = __('Type');
$table->head[3] = __('Schedule / Day');
$table->head[4] = __('Action');
$table->head[5] = __('Operations');
foreach ($reports as $row) {
$table->cellclass[][5] = 'table_action_buttons';
$function_name = db_get_value(
'name',
'tuser_task',
'id',
$row['id_user_task']
);
$params = unserialize($row['args']);
$id_report = ($row['id_report'] ?? $params[0]);
$report_name = db_get_value(
'name',
'treport',
'id_report',
$id_report
);
$data = [];
$data[0] = ($row['name'] ?? __('No name'));
$data[1] = $report_name;
$data[2] = $function_name;
$data[3] = date('Y/m/d H:i:s', $params['first_execution']);
$data[4] = cron_get_scheduled_string($row['scheduled']);
$data[5] = '';
if (check_acl($config['id_user'], 0, 'RW')) {
$data[5] .= html_print_anchor(
[
'href' => ui_get_full_url(
sprintf(
'index.php?sec=reporting&sec2=godmode/reporting/manage_schedule&id_task=%s',
$row['id']
)
),
'content' => html_print_image(
'images/edit.svg',
true,
[
'title' => __('Edit'),
'class' => 'main_menu_icon invert_filter',
]
),
],
true
);
$data[5] .= html_print_anchor(
[
'href' => sprintf(
'index.php?sec=custom_report&sec2=godmode/reporting/schedule&delete_task=%s',
$row['id']
),
'onClick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;',
'content' => html_print_image(
'images/delete.svg',
true,
[
'title' => __('Delete'),
'class' => 'main_menu_icon invert_filter',
]
),
],
true
);
}
array_push($table->data, $data);
}
html_print_table($table);
} else {
ui_print_info_message(
__('No data to show')
);
}
if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')
) {
$buttonsOutput = [];
// Create form.
$buttonsOutput[] = '<form method="post" action="index.php?sec=reporting&sec2=godmode/reporting/manage_schedule">';
$buttonsOutput[] = html_print_submit_button(
__('Create report'),
'create',
false,
[ 'icon' => 'next' ],
true
);
$buttonsOutput[] = '</form>';
echo html_print_action_buttons(
implode('', $buttonsOutput),
[
'type' => 'form_action',
'right_content' => $tablePagination,
],
true
);
}

View File

@ -153,6 +153,14 @@ function menu_print_menu(&$menu)
if (empty($operation) === false) {
$sec2 = $sec2.'&operation='.$operation;
}
} else if ($sec2 === 'godmode/reporting/reporting_builder') {
$tab = (string) get_parameter('tab', '');
$action = (string) get_parameter('action', '');
if ($tab === 'template' && $action === 'list_template') {
$sec2 = $sec2.'&tab=template&action=list_template';
}
} else if ($sec2 === 'godmode/reporting/manage_schedule') {
$sec2 = 'godmode/reporting/schedule';
} else if ($sec2 === 'godmode/users/configure_user') {
$sec2 = 'godmode/users/user_list';
} else if ($sec2 === 'godmode/modules/manage_inventory_modules_form') {

View File

@ -460,13 +460,20 @@ if ($access_console_node === true) {
$sub = [];
$sub['godmode/reporting/reporting_builder']['text'] = __('Custom reporting');
$sub['godmode/reporting/reporting_builder']['id'] = 'Custom_reporting';
// Set godomode path.
$sub['godmode/reporting/reporting_builder']['subsecs'] = [
'godmode/reporting/reporting_builder',
'operation/reporting/reporting_viewer',
];
$sub['custom_report']['text'] = __('Custom Reports');
$sub['custom_report']['id'] = 'Custom_reporting';
$sub['custom_report']['type'] = 'direct';
$sub['custom_report']['subtype'] = 'nolink';
$sub['custom_report']['refr'] = 0;
$sub2 = [];
$sub2['godmode/reporting/reporting_builder']['text'] = __('Reports');
$sub2['godmode/reporting/reporting_builder&tab=template&action=list_template']['text'] = __('Templates');
if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')) {
$sub2['godmode/reporting/schedule']['text'] = __('Schedule');
}
$sub['custom_report']['sub2'] = $sub2;
$sub['godmode/reporting/graphs']['text'] = __('Custom graphs');

View File

@ -3885,6 +3885,8 @@ CREATE TABLE IF NOT EXISTS `tuser_task_scheduled` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_usuario` VARCHAR(255) NOT NULL DEFAULT '0',
`id_user_task` INT UNSIGNED NOT NULL DEFAULT 0,
`id_report` INT NULL,
`name` VARCHAR(255) NULL,
`args` TEXT,
`scheduled` ENUM('no','hourly','daily','weekly','monthly','yearly','custom') DEFAULT 'no',
`last_run` INT UNSIGNED DEFAULT 0,