Source
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: get events and flags that indicate what was filled in *
* ZBX_DB_EVENT structure *
* *
* Parameters: eventids - [IN] requested event ids *
* events - [OUT] the array of events *
* *
* Comments: use 'zbx_db_free_event' function to release allocated memory *
* *
******************************************************************************/
void zbx_db_get_events_by_eventids(zbx_vector_uint64_t *eventids, zbx_vector_db_event_t *events)
{
zbx_db_result_t result;
zbx_db_row_t row;
char *sql = NULL;
size_t sql_alloc = 0, sql_offset = 0;
zbx_vector_uint64_t tagged_eventids, triggerids;
int i, index;
zbx_vector_uint64_create(&tagged_eventids);
zbx_vector_uint64_create(&triggerids);
zbx_vector_uint64_sort(eventids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
zbx_vector_uint64_uniq(eventids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
/* read event data */
zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset,
"select eventid,source,object,objectid,clock,value,acknowledged,ns,name,severity"
" from events"
" where");
zbx_db_add_condition_alloc(&sql, &sql_alloc, &sql_offset, "eventid", eventids->values, eventids->values_num);
zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, " order by eventid");
result = zbx_db_select("%s", sql);
while (NULL != (row = zbx_db_fetch(result)))
{
zbx_db_event *event = NULL;