Skip to content

Commit

Permalink
Merge pull request #47 from CHERTS/ZBX-22234
Browse files Browse the repository at this point in the history
[ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (dgoloscapov)
  • Loading branch information
CHERTS authored Sep 14, 2023
2 parents f68b649 + cda77b4 commit 2b915e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ A......... [ZBX-21332] fixed runtime errors when linking items from two template
.......PS. [ZBX-22026] fixed SNMP agent item going to unsupported state on NULL result (vso)
.......PS. [ZBX-22032] added cookie engine to HTTP check (askolmeisters)
........S. [ZBX-22215] fixed incorrectly quoted function parameter parsing (wiper)
........S. [ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (dgoloscapov)
.......PS. [ZBX-22304] fixed duplication in web scenario error message, when curl could not resolve host (mprihodko)
...G...... [ZBX-22452] fixed Windows Zabbix agent web.page.* unsupported item keys (akozlovs)
...G...... [ZBX-22470] fixed hang on logging when establishing an encrypted connection in Zabbix agent 2 (kprutkovs)
Expand Down
1 change: 1 addition & 0 deletions PATCHLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
[ZBX-22026] fixed SNMP agent item going to unsupported state on NULL result (https://support.zabbix.com/browse/ZBX-22026)
[ZBX-22032] added cookie engine to HTTP check (https://support.zabbix.com/browse/ZBX-22032)
[ZBX-22215] fixed incorrectly quoted function parameter parsing (https://support.zabbix.com/browse/ZBX-22215)
[ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (https://support.zabbix.com/browse/ZBX-22234)
[ZBX-22304] fixed duplication in web scenario error message, when curl could not resolve host (https://support.zabbix.com/browse/ZBX-22304)
[ZBX-22452] fixed Windows Zabbix agent web.page.* unsupported item keys (https://support.zabbix.com/browse/ZBX-22452)
[ZBX-22470] fixed hang on logging when establishing an encrypted connection in Zabbix agent 2 (https://support.zabbix.com/browse/ZBX-22470)
Expand Down
22 changes: 18 additions & 4 deletions src/zabbix_server/poller/checks_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ static int zbx_snmp_print_oid(char *buffer, size_t buffer_len, const oid *objid,
}

static int zbx_snmp_choose_index(char *buffer, size_t buffer_len, const oid *objid, size_t objid_len,
size_t root_string_len, size_t root_numeric_len)
size_t root_string_len, size_t root_numeric_len, char *root_oid)
{
oid parsed_oid[MAX_OID_LEN];
size_t parsed_oid_len = MAX_OID_LEN;
Expand Down Expand Up @@ -868,7 +868,19 @@ static int zbx_snmp_choose_index(char *buffer, size_t buffer_len, const oid *obj

if (NULL == strchr(printed_oid, '"') && NULL == strchr(printed_oid, '\''))
{
zbx_strlcpy(buffer, printed_oid + root_string_len + 1, buffer_len);
if (0 != strncmp(printed_oid, root_oid, strlen(root_oid)))
{
size_t offset = 0;
char *sep;

if (NULL != (sep = strstr(printed_oid, "::")))
offset = sep - printed_oid + 2;

zbx_strlcpy(buffer, printed_oid + offset, buffer_len);
}
else
zbx_strlcpy(buffer, printed_oid + root_string_len + 1, buffer_len);

return SUCCEED;
}

Expand Down Expand Up @@ -1009,7 +1021,7 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha
struct snmp_pdu *pdu, *response;
oid anOID[MAX_OID_LEN], rootOID[MAX_OID_LEN];
size_t anOID_len = MAX_OID_LEN, rootOID_len = MAX_OID_LEN, root_string_len, root_numeric_len;
char oid_index[MAX_STRING_LEN];
char oid_index[MAX_STRING_LEN], root_oid[MAX_STRING_LEN];
struct variable_list *var;
int status, level, running, num_vars, check_oid_increase = 1, ret = SUCCEED;
AGENT_RESULT snmp_result;
Expand Down Expand Up @@ -1038,6 +1050,8 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha

root_string_len = strlen(oid_index);

zbx_strlcpy(root_oid, oid_index, sizeof(root_oid));

if (-1 == zbx_snmp_print_oid(oid_index, sizeof(oid_index), rootOID, rootOID_len, ZBX_OID_INDEX_NUMERIC))
{
zbx_snprintf(error, max_error_len, "zbx_snmp_print_oid(): cannot print OID \"%s\""
Expand Down Expand Up @@ -1174,7 +1188,7 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha
}

if (SUCCEED != zbx_snmp_choose_index(oid_index, sizeof(oid_index), var->name,
var->name_length, root_string_len, root_numeric_len))
var->name_length, root_string_len, root_numeric_len, root_oid))
{
zbx_snprintf(error, max_error_len, "zbx_snmp_choose_index():"
" cannot choose appropriate index while walking for"
Expand Down

0 comments on commit 2b915e5

Please sign in to comment.