Source
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s %s", __func__, zbx_result_string(ret), ZBX_NULL2EMPTY_STR(*error));
/*
** 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.
**/
/******************************************************************************
* *
* Purpose: get baseline data for common period/season combinations *
* *
* Parameters: itemid - [IN] the item identifier *
* table - [IN] the trends table name *
* now - [IN] the current timestamp *
* period - [IN] the data period *
* season_num - [IN] the number of seasons *
* season_unit - [IN] the season time unit *
* skip - [IN] how many data periods to skip *
* values - [OUT] the average data period value in each *
* season *
* index - [OUT] the index of returned values, starting *
* with 0. It will have values be from 0 to *
* <seasons num> + 1 - <skip> with holes for *
* periods without data. *
* error - [OUT] the error message if parsing failed *
* *
* Return value: SUCCEED - data were retrieved successfully *
* FAIL - otherwise *
* *
******************************************************************************/
static int baseline_get_common_data(zbx_uint64_t itemid, const char *table, time_t now, const char *period,
int season_num, zbx_time_unit_t season_unit, int skip, zbx_vector_dbl_t *values,
zbx_vector_uint64_t *index, char **error)
{
int i, start, end;
double value_dbl;
struct tm tm, tm_now;
tm_now = *localtime(&now);
for (i = 0; i < season_num; i++)
{
if (FAIL == zbx_trends_parse_range(now, period, &start, &end, error))
return FAIL;
if (skip <= i)
{
zbx_trend_state_t state;
state = zbx_trends_get_avg(table, itemid, start, end, &value_dbl);
if (ZBX_TREND_STATE_NORMAL != state)
{
if (0 == i || ZBX_TREND_STATE_NODATA != state)
{
*error = zbx_strdup(NULL, zbx_trends_error(state));
return FAIL;
}
}
else
{
zbx_vector_dbl_append(values, value_dbl);
zbx_vector_uint64_append(index, (zbx_uint64_t)(i - skip));
}
}
tm = tm_now;
zbx_tm_sub(&tm, i + 1, season_unit);
if (-1 == (now = mktime(&tm)))
{
*error = zbx_dsprintf(*error, "cannot convert season start time: %s", zbx_strerror(errno));
return FAIL;