Fixed cron updating problem TICKETS #3329
In addition, linux agent send crontab token and in data modules, cron information is displayed grayed
This commit is contained in:
parent
23902bd60e
commit
b9875e8013
|
@ -469,6 +469,7 @@ sub parse_conf_modules($) {
|
|||
}
|
||||
} elsif ($line =~ /^\s*module_crontab\s+(((\*|(\d+(-\d+){0,1}))\s*){5}).*$/) {
|
||||
$module->{'cron'} = $1;
|
||||
chomp ($module->{'cron'});
|
||||
} elsif ($line =~ /^\s*module_cron_interval\s+(\d+).*$/) {
|
||||
$module->{'cron_interval'} = $1;
|
||||
} elsif ($line =~ /^\s*module_end\s*$/) {
|
||||
|
@ -1865,6 +1866,9 @@ sub write_module_xml ($@) {
|
|||
|
||||
# Module Alert template
|
||||
$Xml .= " <alert_template>" . $module->{'alert_template'} . "</alert_template>\n" if (defined ($module->{'alert_template'}));
|
||||
|
||||
# Module Alert template
|
||||
$Xml .= " <crontab>" . $module->{'cron'} . "</crontab>\n" if (defined ($module->{'cron'}) and ($module->{'cron'} ne ""));
|
||||
|
||||
# Data list
|
||||
if ($#data > 0) {
|
||||
|
|
|
@ -536,10 +536,18 @@ $table_advanced->data[10][0] = __('Unknown instructions'). ui_print_help_tip(__(
|
|||
$table_advanced->data[10][1] = html_print_textarea ('unknown_instructions', 2, 65, $unknown_instructions, '', true);
|
||||
$table_advanced->colspan[10][1] = 6;
|
||||
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
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);
|
||||
$table_advanced->colspan[11][1] = 6;
|
||||
if (isset($id_agente) && $moduletype == MODULE_DATA) {
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
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->colspan[11][1] = 6;
|
||||
}
|
||||
else {
|
||||
$table_advanced->data[11][0] = __('Cron') .
|
||||
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, false);
|
||||
$table_advanced->colspan[11][1] = 6;
|
||||
}
|
||||
|
||||
$table_advanced->data[12][0] = __('Timeout');
|
||||
$table_advanced->data[12][1] = html_print_input_text ('max_timeout', $max_timeout, '', 5, 10, true). ' ' . ui_print_help_tip (__('Seconds that agent will wait for the execution of the module.'), true);
|
||||
|
|
|
@ -22,7 +22,7 @@ include_once($config['homedir'] . "/include/functions_db.php");
|
|||
function cron_update_module_interval ($module_id, $cron) {
|
||||
|
||||
// Check for a valid cron
|
||||
if ($cron == '' || $cron == '* * * * *') {
|
||||
if (!cron_check_syntax($cron)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -160,4 +160,10 @@ function cron_next_execution_date ($cron, $cur_time = false) {
|
|||
return $cur_time + SECONDS_5MINUTES;
|
||||
}
|
||||
|
||||
// Check if cron is properly constructed
|
||||
function cron_check_syntax($cron) {
|
||||
|
||||
return preg_match("/^[\d|\*].* .*[\d|\*].* .*[\d|\*].* .*[\d|\*].* .*[\d|\*]$/", $cron);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -796,10 +796,11 @@ function html_print_extended_select_for_time ($name, $selected = '',
|
|||
* @param string Run month.
|
||||
* @param string Run day of the week.
|
||||
* @param bool Whether to return an output string or echo now (optional, echo by default).
|
||||
* @param bool Print cron grayed
|
||||
*
|
||||
* @return string HTML code if return parameter is true.
|
||||
*/
|
||||
function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday = '*', $month = '*', $wday = '*', $return = false) {
|
||||
function html_print_extended_select_for_cron ($hour = '*', $minute = '*', $mday = '*', $month = '*', $wday = '*', $return = false, $disabled = false) {
|
||||
|
||||
# Hours
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
|
@ -842,11 +843,11 @@ 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);
|
||||
$table->data[0][1] = html_print_select ($minutes, 'minute', $minute, '', __('Any'), '*', true, false, false);
|
||||
$table->data[0][2] = html_print_select ($mdays, 'mday', $mday, '', __('Any'), '*', true, false, false);
|
||||
$table->data[0][3] = html_print_select ($months, 'month', $month, '', __('Any'), '*', true, false, false);
|
||||
$table->data[0][4] = html_print_select ($wdays, 'wday', $wday, '', __('Any'), '*', true, false, false);
|
||||
$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);
|
||||
|
||||
return html_print_table ($table, $return);
|
||||
}
|
||||
|
|
|
@ -544,7 +544,7 @@ sub process_module_data ($$$$$$$$$) {
|
|||
'datalist' => 0, 'status' => 0, 'unit' => 0, 'timestamp' => 0, 'module_group' => 0, 'custom_id' => '',
|
||||
'str_warning' => '', 'str_critical' => '', 'critical_instructions' => '', 'warning_instructions' => '',
|
||||
'unknown_instructions' => '', 'tags' => '', 'critical_inverse' => 0, 'warning_inverse' => 0, 'quiet' => 0,
|
||||
'module_ff_interval' => 0, 'alert_template' => ''};
|
||||
'module_ff_interval' => 0, 'alert_template' => '', 'crontab' => ''};
|
||||
|
||||
# Other tags will be saved here
|
||||
$module_conf->{'extended_info'} = '';
|
||||
|
@ -631,6 +631,11 @@ sub process_module_data ($$$$$$$$$) {
|
|||
$initial_alert_template = $module_conf->{'alert_template'};
|
||||
delete $module_conf->{'alert_template'};
|
||||
}
|
||||
|
||||
if(cron_check_syntax ($module_conf->{'crontab'})) {
|
||||
$module_conf->{'cron_interval'} = $module_conf->{'crontab'};
|
||||
}
|
||||
delete $module_conf->{'crontab'};
|
||||
|
||||
# Create the module
|
||||
my $module_id = pandora_create_module_from_hash ($pa_config, $module_conf, $dbh);
|
||||
|
|
|
@ -64,6 +64,7 @@ our @EXPORT = qw(
|
|||
cron_get_closest_in_range
|
||||
cron_next_execution
|
||||
cron_next_execution_date
|
||||
cron_check_syntax
|
||||
pandora_daemonize
|
||||
logger
|
||||
pandora_rotate_logfile
|
||||
|
@ -1245,7 +1246,15 @@ sub cron_next_execution ($) {
|
|||
# Something went wrong, default to 5 minutes
|
||||
return 300;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Get the number of seconds left to the next execution of the given cron entry.
|
||||
###############################################################################
|
||||
sub cron_check_syntax ($) {
|
||||
my ($cron) = @_;
|
||||
|
||||
return 0 if !defined ($cron);
|
||||
return ($cron =~ m/^(\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+ (\d|\*|-)+$/);
|
||||
}
|
||||
###############################################################################
|
||||
# Get the next execution date for the given cron entry in seconds since epoch.
|
||||
###############################################################################
|
||||
|
|
Loading…
Reference in New Issue