Added new funtion to module cron interval with "from" and "to" forms. Ticket #246
This commit is contained in:
parent
7b95f9dbfe
commit
2cfce8979e
|
@ -1014,13 +1014,50 @@ if ($update_module || $create_module) {
|
|||
|
||||
$id_category = (int) get_parameter('id_category');
|
||||
|
||||
$hour = get_parameter('hour');
|
||||
$minute = get_parameter('minute');
|
||||
$mday = get_parameter('mday');
|
||||
$month = get_parameter('month');
|
||||
$wday = get_parameter('wday');
|
||||
|
||||
$cron_interval = "$minute $hour $mday $month $wday";
|
||||
$hour_from = get_parameter('hour_from');
|
||||
$minute_from = get_parameter('minute_from');
|
||||
$mday_from = get_parameter('mday_from');
|
||||
$month_from = get_parameter('month_from');
|
||||
$wday_from = get_parameter('wday_from');
|
||||
|
||||
$hour_to = get_parameter('hour_to');
|
||||
$minute_to = get_parameter('minute_to');
|
||||
$mday_to = get_parameter('mday_to');
|
||||
$month_to = get_parameter('month_to');
|
||||
$wday_to = get_parameter('wday_to');
|
||||
|
||||
if ($hour_to != "*") {
|
||||
$hour_to = "-" . $hour_to;
|
||||
}
|
||||
else {
|
||||
$hour_to = "";
|
||||
}
|
||||
if ($minute_to != "*") {
|
||||
$minute_to = "-" . $minute_to;
|
||||
}
|
||||
else {
|
||||
$minute_to = "";
|
||||
}
|
||||
if ($mday_to != "*") {
|
||||
$mday_to = "-" . $mday_to;
|
||||
}
|
||||
else {
|
||||
$mday_to = "";
|
||||
}
|
||||
if ($month_to != "*") {
|
||||
$month_to = "-" . $month_to;
|
||||
}
|
||||
else {
|
||||
$month_to = "";
|
||||
}
|
||||
if ($wday_to != "*") {
|
||||
$wday_to = "-" . $wday_to;
|
||||
}
|
||||
else {
|
||||
$wday_to = "";
|
||||
}
|
||||
|
||||
$cron_interval = $minute_from . $minute_to . " " . $hour_from . $hour_to . " " . $mday_from . $mday_to . " " . $month_from . $month_to . " " . $wday_from . $wday_to;
|
||||
if (!cron_check_syntax($cron_interval)) {
|
||||
$cron_interval = '';
|
||||
}
|
||||
|
|
|
@ -229,18 +229,53 @@ if ($id_agent_module) {
|
|||
|
||||
$cron_interval = explode (" ", $module['cron_interval']);
|
||||
if (isset ($cron_interval[4])) {
|
||||
$minute = $cron_interval[0];
|
||||
$hour = $cron_interval[1];
|
||||
$mday = $cron_interval[2];
|
||||
$month = $cron_interval[3];
|
||||
$wday = $cron_interval[4];
|
||||
$minute_from = $cron_interval[0];
|
||||
$min = explode("-", $minute_from);
|
||||
$minute_from = $min[0];
|
||||
if (isset($min[1])) {
|
||||
$minute_to = $min[1];
|
||||
}
|
||||
|
||||
$hour_from = $cron_interval[1];
|
||||
$h = explode("-", $hour_from);
|
||||
$hour_from = $h[0];
|
||||
if (isset($h[1])) {
|
||||
$hour_to = $h[1];
|
||||
}
|
||||
|
||||
$mday_from = $cron_interval[2];
|
||||
$md = explode("-", $mday_from);
|
||||
$mday_from = $md[0];
|
||||
if (isset($md[1])) {
|
||||
$mday_to = $md[1];
|
||||
}
|
||||
|
||||
$month_from = $cron_interval[3];
|
||||
$m = explode("-", $month_from);
|
||||
$month_from = $m[0];
|
||||
if (isset($m[1])) {
|
||||
$month_to = $m[1];
|
||||
}
|
||||
|
||||
$wday_from = $cron_interval[4];
|
||||
$wd = explode("-", $wday_from);
|
||||
$wday_from = $wd[0];
|
||||
if (isset($wd[1])) {
|
||||
$wday_to = $wd[1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$minute = '*';
|
||||
$hour = '*';
|
||||
$mday = '*';
|
||||
$month = '*';
|
||||
$wday = '*';
|
||||
$minute_from = '*';
|
||||
$hour_from = '*';
|
||||
$mday_from = '*';
|
||||
$month_from = '*';
|
||||
$wday_from = '*';
|
||||
|
||||
$minute_to = '*';
|
||||
$hour_to = '*';
|
||||
$mday_to = '*';
|
||||
$month_to = '*';
|
||||
$wday_to = '*';
|
||||
}
|
||||
|
||||
$module_macros = null;
|
||||
|
@ -322,11 +357,16 @@ else {
|
|||
$id_category = 0;
|
||||
|
||||
$cron_interval = '* * * * *';
|
||||
$hour = '*';
|
||||
$minute = '*';
|
||||
$mday = '*';
|
||||
$month = '*';
|
||||
$wday = '*';
|
||||
$hour_from = '*';
|
||||
$minute_from = '*';
|
||||
$mday_from = '*';
|
||||
$month_from = '*';
|
||||
$wday_from = '*';
|
||||
$hour_to = '*';
|
||||
$minute_to = '*';
|
||||
$mday_to = '*';
|
||||
$month_to = '*';
|
||||
$wday_to = '*';
|
||||
|
||||
$ff_interval = 0;
|
||||
|
||||
|
|
|
@ -578,41 +578,53 @@ $table_advanced->colspan[10][1] = 6;
|
|||
if (isset($id_agente) && $moduletype == MODULE_DATA) {
|
||||
$has_remote_conf = enterprise_hook('config_agents_has_remote_configuration',array($agent["id_agente"]));
|
||||
if ($has_remote_conf) {
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
$table_advanced->data[11][0] = __('Cron from') .
|
||||
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour, $minute, $mday, $month, $wday, true, $disabledBecauseInPolicy);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy);
|
||||
$table_advanced->colspan[11][1] = 6;
|
||||
|
||||
$table_advanced->data[12][0] = __('Cron to');
|
||||
$table_advanced->data[12][1] = html_print_extended_select_for_cron ($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, $disabledBecauseInPolicy, true);
|
||||
$table_advanced->colspan[12][1] = 6;
|
||||
}
|
||||
else {
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
$table_advanced->data[11][0] = __('Cron from') .
|
||||
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour, $minute, $mday, $month, $wday, true, true);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, true);
|
||||
$table_advanced->colspan[11][1] = 6;
|
||||
|
||||
$table_advanced->data[12][0] = __('Cron to');
|
||||
$table_advanced->data[12][1] = html_print_extended_select_for_cron ($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, true, true);
|
||||
$table_advanced->colspan[12][1] = 6;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
$table_advanced->data[11][0] = __('Cron from') .
|
||||
ui_print_help_tip (__('If cron is set the module interval is ignored and the module runs on the specified date and time'), true);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour, $minute, $mday, $month, $wday, true, $disabledBecauseInPolicy);
|
||||
$table_advanced->data[11][1] = html_print_extended_select_for_cron ($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy);
|
||||
$table_advanced->colspan[11][1] = 6;
|
||||
|
||||
$table_advanced->data[12][0] = __('Cron to');
|
||||
$table_advanced->data[12][1] = html_print_extended_select_for_cron ($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, $disabledBecauseInPolicy, true);
|
||||
$table_advanced->colspan[12][1] = 6;
|
||||
}
|
||||
|
||||
$table_advanced->data[12][0] = __('Timeout');
|
||||
$table_advanced->data[12][1] = html_print_input_text ('max_timeout', $max_timeout, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy). ' ' . ui_print_help_tip (__('Seconds that agent will wait for the execution of the module.'), true);
|
||||
$table_advanced->data[12][2] = '';
|
||||
$table_advanced->data[12][3] = __('Retries');
|
||||
$table_advanced->data[12][4] = html_print_input_text ('max_retries', $max_retries, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy). ' ' . ui_print_help_tip (__('Number of retries that the module will attempt to run.'), true);
|
||||
$table_advanced->colspan[12][4] = 3;
|
||||
$table_advanced->data[13][0] = __('Timeout');
|
||||
$table_advanced->data[13][1] = html_print_input_text ('max_timeout', $max_timeout, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy). ' ' . ui_print_help_tip (__('Seconds that agent will wait for the execution of the module.'), true);
|
||||
$table_advanced->data[13][2] = '';
|
||||
$table_advanced->data[13][3] = __('Retries');
|
||||
$table_advanced->data[13][4] = html_print_input_text ('max_retries', $max_retries, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy). ' ' . ui_print_help_tip (__('Number of retries that the module will attempt to run.'), true);
|
||||
$table_advanced->colspan[13][4] = 3;
|
||||
|
||||
if (check_acl ($config['id_user'], 0, "PM")) {
|
||||
$table_advanced->data[13][0] = __('Category');
|
||||
$table_advanced->data[13][1] = html_print_select(
|
||||
$table_advanced->data[14][0] = __('Category');
|
||||
$table_advanced->data[14][1] = html_print_select(
|
||||
categories_get_all_categories('forselect'), 'id_category', $id_category, '', __('None'), 0, true, false, true, "", $disabledBecauseInPolicy);
|
||||
$table_advanced->colspan[13][1] = 6;
|
||||
$table_advanced->colspan[14][1] = 6;
|
||||
}
|
||||
else {
|
||||
// Store in a hidden field if is not visible to avoid delete the value
|
||||
$table_advanced->data[12][4] .= html_print_input_hidden ('id_category', $id_category, true);
|
||||
$table_advanced->data[13][4] .= html_print_input_hidden ('id_category', $id_category, true);
|
||||
}
|
||||
|
||||
/* Advanced form part */
|
||||
|
|
|
@ -819,7 +819,7 @@ function html_print_extended_select_for_time ($name, $selected = '',
|
|||
*
|
||||
* @return string HTML code if return parameter is true.
|
||||
*/
|
||||
function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday = '*', $month = '*', $wday = '*', $return = false, $disabled = false) {
|
||||
function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday = '*', $month = '*', $wday = '*', $return = false, $disabled = false, $to = false) {
|
||||
|
||||
# Hours
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
|
@ -862,11 +862,20 @@ function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday
|
|||
$table->head[3] = __('Month');
|
||||
$table->head[4] = __('Week day');
|
||||
|
||||
$table->data[0][0] = html_print_select ($hours, 'hour', $hour, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][1] = html_print_select ($minutes, 'minute', $minute, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][2] = html_print_select ($mdays, 'mday', $mday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][3] = html_print_select ($months, 'month', $month, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][4] = html_print_select ($wdays, 'wday', $wday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
if ($to) {
|
||||
$table->data[0][0] = html_print_select ($hours, 'hour_to', $hour, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][1] = html_print_select ($minutes, 'minute_to', $minute, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][2] = html_print_select ($mdays, 'mday_to', $mday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][3] = html_print_select ($months, 'month_to', $month, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][4] = html_print_select ($wdays, 'wday_to', $wday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
}
|
||||
else {
|
||||
$table->data[0][0] = html_print_select ($hours, 'hour_from', $hour, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][1] = html_print_select ($minutes, 'minute_from', $minute, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][2] = html_print_select ($mdays, 'mday_from', $mday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][3] = html_print_select ($months, 'month_from', $month, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
$table->data[0][4] = html_print_select ($wdays, 'wday_from', $wday, '', __('Any'), '*', true, false, false,'',$disabled);
|
||||
}
|
||||
|
||||
return html_print_table ($table, $return);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue