Source
xxxxxxxxxx
static int scheduler_parse_filter_r(zbx_scheduler_filter_t **filter, const char *text, int *len, int min, int max,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
typedef struct
{
int start_day; /* day of week when period starts */
int end_day; /* day of week when period ends, included */
int start_time; /* number of seconds from the beginning of the day when period starts */
int end_time; /* number of seconds from the beginning of the day when period ends, not included */
}
zbx_time_period_t;
typedef struct zbx_scheduler_filter
{
int start;
int end;
int step;
struct zbx_scheduler_filter *next;
}
zbx_scheduler_filter_t;
typedef struct zbx_scheduler_interval
{
zbx_scheduler_filter_t *mdays;
zbx_scheduler_filter_t *wdays;
zbx_scheduler_filter_t *hours;
zbx_scheduler_filter_t *minutes;
zbx_scheduler_filter_t *seconds;
int filter_level;
struct zbx_scheduler_interval *next;
}
zbx_scheduler_interval_t;
typedef struct zbx_flexible_interval
{
zbx_time_period_t period;
int delay;
struct zbx_flexible_interval *next;
}
zbx_flexible_interval_t;
struct zbx_custom_interval
{
zbx_flexible_interval_t *flexible;
zbx_scheduler_interval_t *scheduling;
};
/******************************************************************************
* *
* Purpose: checks if current time is within given period *
* *
* Parameters: period - [IN] preprocessed time period *
* tm - [IN] broken-down time for comparison *
* *
* Return value: FAIL - out of period, SUCCEED - within the period *
* *
******************************************************************************/
static int check_time_period(const zbx_time_period_t period, const struct tm *tm)
{
int day, time;
day = 0 == tm->tm_wday ? 7 : tm->tm_wday;
time = SEC_PER_HOUR * tm->tm_hour + SEC_PER_MIN * tm->tm_min + tm->tm_sec;
return period.start_day <= day && day <= period.end_day && period.start_time <= time && time < period.end_time ?
SUCCEED : FAIL;