Source
xxxxxxxxxx
static int trends_parse_timeshift(time_t from, const char *timeshift, zbx_time_unit_t min_time_unit, struct tm *tm,
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
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] the period shift parameter *
* base - [OUT] the period shift base (now/?) *
* error - [OUT] the 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] the function parameters *
* base - [OUT] the period shift base (now/?) *
* error - [OUT] the 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;