Skip to content

Commit

Permalink
QA: Add constants, Add Hourly Schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWitness committed Dec 31, 2024
1 parent 06453b2 commit da90f42
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
8 changes: 4 additions & 4 deletions automation_networks.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,19 @@ function api_networks_save($post) {
$save['monthly_day'] = form_input_validate(isset($post['monthly_day']) ? implode(',', $post['monthly_day']) : '', 'monthly_day', '', true, 3);

/* check for bad rules */
if ($save['sched_type'] == '3') {
if ($save['sched_type'] == SCHEDULE_WEEKLY) {
if ($save['day_of_week'] == '') {
$save['enabled'] = '';
$_SESSION['automation_message'] = __esc('ERROR: You must specify the day of the week. Disabling Network %s!.', $save['name']);
raise_message('automation_message');
}
} elseif ($save['sched_type'] == '4') {
} elseif ($save['sched_type'] == SCHEDULE_MONTHLY) {
if ($save['month'] == '' || $save['day_of_month'] == '') {
$save['enabled'] = '';
$_SESSION['automation_message'] = __esc('ERROR: You must specify both the Months and Days of Month. Disabling Network %s!', $save['name']);
raise_message('automation_message');
}
} elseif ($save['sched_type'] == '5') {
} elseif ($save['sched_type'] == SCHEDULE_MONTHLY_ON_DAY) {
if ($save['month'] == '' || $save['monthly_day'] == '' || $save['monthly_week'] == '') {
$save['enabled'] = '';
$_SESSION['automation_message'] = __esc('ERROR: You must specify the Months, Weeks of Months, and Days of Week. Disabling Network %s!', $save['name']);
Expand Down Expand Up @@ -1227,7 +1227,7 @@ function networks() {
form_selectable_cell(number_format_i18n($updown['up']) . '/' . number_format_i18n($updown['snmp']), $network['id'], '', 'right');
form_selectable_cell(number_format_i18n($network['threads']), $network['id'], '', 'right');
form_selectable_cell(round($network['last_runtime'], 2), $network['id'], '', 'right');
form_selectable_cell($network['enabled'] == '' || $network['sched_type'] == '1' ? __('N/A') : ($network['next_start'] == '0000-00-00 00:00:00' ? substr($network['start_at'], 0, 16) : substr($network['next_start'], 0, 16)), $network['id'], '', 'right');
form_selectable_cell($network['enabled'] == '' || $network['sched_type'] == SCHEDULE_MANUAL ? __('N/A') : ($network['next_start'] == '0000-00-00 00:00:00' ? substr($network['start_at'], 0, 16) : substr($network['next_start'], 0, 16)), $network['id'], '', 'right');
form_selectable_cell($network['last_started'] == '0000-00-00 00:00:00' ? __('Never') : substr($network['last_started'], 0, 16), $network['id'], '', 'right');
form_checkbox_cell($network['name'], $network['id']);

Expand Down
11 changes: 6 additions & 5 deletions include/global_arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -3101,11 +3101,12 @@
);

$sched_types = array(
'1' => __('Manual'),
'2' => __('Daily'),
'3' => __('Weekly'),
'4' => __('Monthly'),
'5' => __('Monthly on Day')
SCHEDULE_MANUAL => __('Manual'),
SCHEDULE_HOURLY => __('Hourly'),
SCHEDULE_DAILY => __('Daily'),
SCHEDULE_WEEKLY => __('Weekly'),
SCHEDULE_MONTHLY => __('Monthly'),
SCHEDULE_MONTHLY_ON_DAY => __('Monthly on Day')
);

if ($config['cacti_server_os'] == 'unix') {
Expand Down
7 changes: 7 additions & 0 deletions include/global_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@

define('REPORTS_DEFAULT_MAX_SIZE', 10485760);

define('SCHEDULE_MANUAL', 1);
define('SCHEDULE_DAILY', 2);
define('SCHEDULE_WEEKLY', 3);
define('SCHEDULE_MONTHLY', 4);
define('SCHEDULE_MONTHLY_ON_DAY', 5);
define('SCHEDULE_HOURLY', 6);

# unless a hook for 'global_constants' is available, all DEFINEs go here
define('AGGREGATE_GRAPH_TYPE_KEEP', 0);
define('AGGREGATE_GRAPH_TYPE_KEEP_STACKED', 50);
Expand Down
36 changes: 21 additions & 15 deletions lib/api_scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function api_scheduler_form() {
'description' => __('Define the collection frequency.'),
'value' => '|arg1:sched_type|',
'array' => $sched_types,
'default' => 1
'default' => SCHEDULE_MANUAL
),
'start_at' => array(
'method' => 'textbox',
Expand Down Expand Up @@ -247,12 +247,18 @@ function api_scheduler_is_time_to_start($schedule) {
$now = time();

switch($schedule['sched_type']) {
case '1':
case SCHEDULE_MANUAL:
return false;

break;
case '2':
$recur = $schedule['recur_every'] * 86400; // days
case SCHEDULE_HOURLY:
case SCHEDULE_DAILY:
if ($schedule['sched_type']] == SCHEDULE_HOURLY) {
$recur = $schedule['recur_every'] * 3600; // days
} else {
$recur = $schedule['recur_every'] * 86400; // days
}

$start = strtotime($schedule['start_at']);
$next = strtotime($schedule['next_start']);

Expand All @@ -268,8 +274,8 @@ function api_scheduler_is_time_to_start($schedule) {
}

db_execute_prepared('UPDATE automation_networks
SET next_start = ?
WHERE id = ?',
SET next_start = ?
WHERE id = ?',
array(date('Y-m-d H:i', $target), $schedulework_id));

return true;
Expand All @@ -280,7 +286,7 @@ function api_scheduler_is_time_to_start($schedule) {
return false;

break;
case '3':
case SCHEDULE_WEEKLY:
$recur = $schedule['recur_every'] * 86400 * 7; // weeks
$start = strtotime($schedule['start_at']);
$next = strtotime($schedule['next_start']);
Expand Down Expand Up @@ -311,8 +317,8 @@ function api_scheduler_is_time_to_start($schedule) {
}

db_execute_prepared('UPDATE automation_networks
SET next_start = ?
WHERE id = ?',
SET next_start = ?
WHERE id = ?',
array(date('Y-m-d H:i', $target), $schedulework_id));

return true;
Expand All @@ -321,13 +327,13 @@ function api_scheduler_is_time_to_start($schedule) {
return false;

break;
case '4':
case '5':
case SCHEDULE_MONTHLY:
case SCHEDULE_MONTHLY_ON_DAY:
$next = api_scheduler_calculate_next_start($schedule, $now);

db_execute_prepared('UPDATE automation_networks
SET next_start = ?
WHERE id = ?',
SET next_start = ?
WHERE id = ?',
array(date('Y-m-d H:i', $next), $schedulework_id));

if ($schedule['next_start'] == '0000-00-00 00:00:00') {
Expand All @@ -351,7 +357,7 @@ function api_scheduler_calculate_next_start($schedule) {
$dates = array();

switch($schedule['sched_type']) {
case '4':
case SCHEDULE_MONTHLY:
$months = explode(',', $schedule['month']);
$days = explode(',', $schedule['day_of_month']);

Expand Down Expand Up @@ -417,7 +423,7 @@ function api_scheduler_calculate_next_start($schedule) {
}

break;
case '5':
case SCHEDULE_MONTHLY_ON_DAY:
$months = explode(',', $schedule['month']);
$weeks = explode(',', $schedule['monthly_week']);
$days = explode(',', $schedule['monthly_day']);
Expand Down

0 comments on commit da90f42

Please sign in to comment.