Source
static void check_events_condition(const zbx_vector_ptr_t *esc_events, unsigned char source, zbx_condition_t *condition)
/*
** Zabbix
** Copyright (C) 2001-2022 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.
**/
/******************************************************************************
* *
* Function: compare_events *
* *
* Purpose: compare events by objectid *
* *
* Parameters: d1 - [IN] event structure to compare to d2 *
* d2 - [IN] event structure to compare to d1 *
* *
* Return value: 0 - equal *
* not 0 - otherwise *
* *
******************************************************************************/
static int compare_events(const void *d1, const void *d2)
{
const DB_EVENT *p1 = *(const DB_EVENT **)d1;
const DB_EVENT *p2 = *(const DB_EVENT **)d2;
ZBX_RETURN_IF_NOT_EQUAL(p1->objectid, p2->objectid);
ZBX_RETURN_IF_NOT_EQUAL(p1->object, p2->object);
return 0;
}
/******************************************************************************
* *
* Function: add_condition_match *
* *
* Purpose: save eventids that match condition *
* *
* Parameters: esc_events - [IN] events to check *
* condition - [IN/OUT] condition for matching, outputs *
* event ids that match condition *
* objectid - [IN] object id, for example trigger or item id *
* object - [IN] object, for example EVENT_OBJECT_TRIGGER *
******************************************************************************/
static void add_condition_match(const zbx_vector_ptr_t *esc_events, zbx_condition_t *condition,
zbx_uint64_t objectid, int object)
{
int index;
const DB_EVENT event_search = {.objectid = objectid, .object = object};
if (FAIL != (index = zbx_vector_ptr_bsearch(esc_events, &event_search, compare_events)))
{
const DB_EVENT *event = (DB_EVENT *)esc_events->values[index];
int i;
zbx_vector_uint64_append(&condition->eventids, event->eventid);
for (i = index - 1; 0 <= i; i--)
{
event = esc_events->values[i];
if (event->objectid != objectid || event->object != object)
break;
zbx_vector_uint64_append(&condition->eventids, event->eventid);
}
for (i = index + 1; i < esc_events->values_num; i++)
{
event = (DB_EVENT *)esc_events->values[i];