From 9816488b3c779b85e285956e8a920bfceac43840 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Thu, 1 Jun 2017 14:39:24 +0700 Subject: [PATCH] snmp plugin: Added res->errstat check Collectd does not check for `res->errstat` value after `snmp_sess_synch_response()` call. In case of error, there is no any data in `res->variables` actually, but variables are tried to be processed as usual. Suffix calculation will fail, so all subtrees will be marked as failed, not only one subtree which caused an error. The csnmp_instance_list_add() call will fail too, and, as result, `csnmp_read_table` will finish it's work without any data submission. The log message like "snmp plugin: host HOSTNAME: csnmp_instance_list_add failed", which is put into logs in this case, also has no enough diagnostic data. Added code to proper check for `res->errstat` and to try to get available data. Issue: #2291 --- src/snmp.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/snmp.c b/src/snmp.c index aa3c9dda..2b1dd044 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1388,6 +1388,38 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) { break; } + if (res->errstat != SNMP_ERR_NOERROR) { + if (res->errindex != 0 && res->errindex < oid_list_len) { + /* Find the OID which caused error */ + for (i = 1, vb = res->variables; vb != NULL && i != res->errindex; + vb = vb->next_variable, i++) + /* do nothing */; + + char oid_buffer[1024] = {0}; + snprint_objid(oid_buffer, sizeof(oid_buffer) - 1, vb->name, + vb->name_length); + NOTICE("snmp plugin: host %s; data %s: OID `%s` failed: %s", + host->name, data->name, oid_buffer, + snmp_errstring(res->errstat)); + + /* Skip that OID */ + i = res->errindex - 1; + while ((i < oid_list_len) && !oid_list_todo[i]) + i++; + + oid_list_todo[i] = 0; + + snmp_free_pdu(res); + res = NULL; + continue; + } + + ERROR("snmp plugin: host %s; data %s: response error: %s (%li) ", + host->name, data->name, snmp_errstring(res->errstat), res->errstat); + status = -1; + break; + } + for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++) { /* Calculate value index from todo list */ -- 2.11.0