Source
static int trends_parse_timeshift(time_t from, const char *timeshift, zbx_time_unit_t min_time_unit, struct tm *tm,
/*
** 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/>.
**/
static char *trends_errors[ZBX_TREND_STATE_COUNT] = {
"unknown error",
NULL,
"not enough data",
"value is too large"
};
/******************************************************************************
* *
* Purpose: parse largest period base from function parameters *
* *
* Parameters: shift - [IN] period shift parameter *
* base - [OUT] period shift base (now/?) *
* error - [OUT] error message if parsing failed *
* *
* Return value: SUCCEED - period was parsed successfully *
* FAIL - invalid time period was specified *
* *
******************************************************************************/
static int trends_parse_base(const char *period_shift, zbx_time_unit_t *base, char **error)
{
zbx_time_unit_t time_unit = ZBX_TIME_UNIT_UNKNOWN;
const char *ptr;
for (ptr = period_shift; NULL != (ptr = strchr(ptr, '/'));)
{
zbx_time_unit_t tu;
if (ZBX_TIME_UNIT_UNKNOWN == (tu = zbx_tm_str_to_unit(++ptr)))
{
*error = zbx_strdup(*error, "invalid period shift cycle");
return FAIL;
}
if (tu > time_unit)
time_unit = tu;
}
if (ZBX_TIME_UNIT_UNKNOWN == time_unit)
{
*error = zbx_strdup(*error, "invalid period shift expression");
return FAIL;
}
*base = time_unit;
return SUCCEED;
}
/******************************************************************************
* *
* Purpose: parse largest period base from function parameters *
* *
* Parameters: params - [IN] function parameters *
* base - [OUT] period shift base (now/?) *
* error - [OUT] error message if parsing failed *
* *
* Return value: SUCCEED - period was parsed successfully *
* FAIL - invalid time period was specified *
* *
******************************************************************************/
int zbx_trends_parse_base(const char *params, zbx_time_unit_t *base, char **error)
{
const char *period_shift;
if (NULL == (period_shift = strchr(params, ':')))
{
*error = zbx_strdup(*error, "missing period shift parameter");
return FAIL;
}