Source
xxxxxxxxxx
static void compare_trap(const char *date, const char *trap, int snmp_timestamp, const char *snmp_id_bin, int *skip)
/*
** 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 int trap_fd = -1;
static off_t trap_lastsize;
static ino_t trap_ino = 0;
static char *buffer = NULL;
static int offset = 0;
static int force = 0;
static void db_update_lastsize(void)
{
zbx_db_begin();
zbx_db_execute("update globalvars set value=" ZBX_FS_I64 " where name='snmp_lastsize'",
(zbx_int64_t)trap_lastsize);
zbx_db_commit();
}
/******************************************************************************
* *
* Purpose: adds trap to all matching items for specified interface *
* *
* Return value: SUCCEED - matching item was found *
* FAIL - no matching item was found (including fallback items) *
* *
******************************************************************************/
static int process_trap_for_interface(zbx_uint64_t interfaceid, char *trap, zbx_timespec_t *ts)
{
zbx_dc_item_t *items = NULL;
const char *regex;
char error[ZBX_ITEM_ERROR_LEN_MAX];
int ret = FAIL, fb = -1, value_type, regexp_ret;
AGENT_REQUEST request;
zbx_vector_expression_t regexps;
zbx_dc_um_handle_t *um_handle;
zbx_vector_expression_create(®exps);
um_handle = zbx_dc_open_user_macros();
size_t num = zbx_dc_config_get_snmp_items_by_interfaceid(interfaceid, &items);
zbx_uint64_t *itemids = (zbx_uint64_t *)zbx_malloc(NULL, sizeof(zbx_uint64_t) * num);
int *lastclocks = (int *)zbx_malloc(NULL, sizeof(int) * num),
*errcodes = (int *)zbx_malloc(NULL, sizeof(int) * num);
AGENT_RESULT *results = (AGENT_RESULT *)zbx_malloc(NULL, sizeof(AGENT_RESULT) * num);
for (size_t i = 0; i < num; i++)
{
zbx_init_agent_result(&results[i]);
errcodes[i] = FAIL;
items[i].key = zbx_strdup(items[i].key, items[i].key_orig);
if (SUCCEED != zbx_substitute_key_macros(&items[i].key, NULL, &items[i], NULL, NULL,
ZBX_MACRO_TYPE_ITEM_KEY, error, sizeof(error)))
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, error));
errcodes[i] = NOTSUPPORTED;
continue;