Hello community, here is the log from the commit of package cacti-spine for openSUSE:Factory checked in at 2020-02-18 13:29:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/cacti-spine (Old) and /work/SRC/openSUSE:Factory/.cacti-spine.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "cacti-spine" Tue Feb 18 13:29:41 2020 rev:25 rq:774965 version:1.2.9 Changes: -------- --- /work/SRC/openSUSE:Factory/cacti-spine/cacti-spine.changes 2020-02-06 13:08:28.204344138 +0100 +++ /work/SRC/openSUSE:Factory/.cacti-spine.new.26092/cacti-spine.changes 2020-02-18 13:29:44.860742454 +0100 @@ -1,0 +2,11 @@ +Sat Feb 15 18:43:52 UTC 2020 - Andreas Stieger <[email protected]> + +- cacti-spine 1.2.9: + * works with cacti 1.2.9 + * Improve logging of snmp multiple OID get function + * PCOMMAND Device[XXXX] WARNING: Recache Event Detected for Device + * Segmentation Fault triggered by a lot of errors + * Replace function gethostbyname with thread safe getaddrinfo + * removed strip_alpha for "Wrong-Type" SNMP-Answer + +------------------------------------------------------------------- Old: ---- cacti-spine-1.2.8.tar.gz New: ---- cacti-spine-1.2.9.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ cacti-spine.spec ++++++ --- /var/tmp/diff_new_pack.0Yhh6c/_old 2020-02-18 13:29:45.280743270 +0100 +++ /var/tmp/diff_new_pack.0Yhh6c/_new 2020-02-18 13:29:45.284743279 +0100 @@ -17,7 +17,7 @@ Name: cacti-spine -Version: 1.2.8 +Version: 1.2.9 Release: 0 Summary: Threaded poller for Cacti written in C License: LGPL-2.1-or-later ++++++ cacti-spine-1.2.8.tar.gz -> cacti-spine-1.2.9.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/CHANGELOG new/cacti-spine-1.2.9/CHANGELOG --- old/cacti-spine-1.2.8/CHANGELOG 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/CHANGELOG 2020-02-13 21:48:35.000000000 +0100 @@ -1,5 +1,12 @@ The Cacti Group | spine +1.2.9 +-issue#124: Improve logging of snmp multiple OID get function +-issue#129: PCOMMAND Device[XXXX] WARNING: Recache Event Detected for Device +-issue#130: Segmentation Fault triggered by a lot of errors +-issue#131: Replace function gethostbyname with thread safe getaddrinfo +-issue#139: removed strip_alpha for "Wrong-Type" SNMP-Answer + 1.2.8 -issue#119: When calling bootstrap, an invalid error claiming config.h.in is missing can appear on first compile diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/configure.ac new/cacti-spine-1.2.9/configure.ac --- old/cacti-spine-1.2.8/configure.ac 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/configure.ac 2020-02-13 21:48:35.000000000 +0100 @@ -1,5 +1,5 @@ AC_PREREQ(2.53) -AC_INIT(Spine Poller, 1.2.8, http://www.cacti.net/issues.php) +AC_INIT(Spine Poller, 1.2.9, http://www.cacti.net/issues.php) AC_CONFIG_AUX_DIR(config) AC_SUBST(ac_aux_dir) @@ -98,27 +98,7 @@ AC_CHECK_PROG([HELP2MAN], [help2man], [help2man]) AM_CONDITIONAL([HAVE_HELP2MAN], [test x$HELP2MAN = xhelp2man]) -# On some systems, gethostbyname() is thread-safe -AC_ARG_ENABLE(threadsafe_gethostbyname, - AC_HELP_STRING( - [--enable-threadsafe-gethostbyname], - [Assume gethostbyname() is threadsafe] - ) -) - -# Check if the user told use gethostbyname() is thread-safe. -AC_MSG_CHECKING([for threadsafe gethostbyname()]) -if test "x$enable_threadsafe_gethostbyname" = "xyes" ; then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_GETHOSTBYNAME_THREADSAFE, 1, - [Define if gethostbyname is threadsafe]) - HAVE_GETHOSTBYNAME_THREADSAFE=yes -else - AC_MSG_RESULT(no) -fi - # Checks for libraries. -AC_CHECK_LIB(nls, gethostbyname_r) AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(m, floor) AC_CHECK_LIB(dl, dlclose) @@ -437,68 +417,6 @@ AC_MSG_RESULT([no]) fi -# ****************** gethostbyname_r Check *********************** -# Linux Variant -AC_MSG_CHECKING([for glibc gethostbyname_r]) -AC_TRY_LINK([#include <netdb.h>], - [struct hostent result_buf; - char buf[1024]; - struct hostent *result; - int h_erropp; - gethostbyname_r("localhost", - &result_buf, - buf, - sizeof(buf), - &result, - &h_erropp); - ], - [AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_GETHOSTBYNAME_R_GLIBC, 1, [Using glibc versionf of gethostbyname_r()]) - HAVE_GETHOSTBYNAME_R=yes - ], - [AC_MSG_RESULT([no])] -) - -# Solaris or Irix Check -AC_MSG_CHECKING([for Solaris/Irix gethostbyname_r]) -AC_TRY_LINK([#include <netdb.h>], - [struct hostent result; - char buf[1024]; - int h_errnop; - gethostbyname_r("localhost", - &result, - buf, - sizeof(buf), - &h_errnop); - ], - [AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_GETHOSTBYNAME_R_SOLARIS, 1, [Using Solaris gethostbyname_r()]) - HAVE_GETHOSTBYNAME_R=yes - ], - [AC_MSG_RESULT([no])] -) - -# HP-UX Check -AC_MSG_CHECKING([for HP-UX gethostbyname_r]) -AC_TRY_LINK([#include <netdb.h>], - [struct hostent result; - char buf[1024]; - gethostbyname_r("localhost", - &result, - buf); - ], - [AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_GETHOSTBYNAME_R_HPUX, 1, [Using HPUX gethostbyname_r()]) - HAVE_GETHOSTBYNAME_R=yes], - [AC_MSG_RESULT([no])] -) - -# Not Found, Use Mutex Locking -if test -z "$HAVE_GETHOSTBYNAME_R"; then - AC_DEFINE(HAVE_GETHOSTBYNAME_R_MUTEX_LOCK, 1, [Using traditional of gethostbyname_r()]) - HAVE_GETHOSTBYNAME_R=yes -fi - # See if we can support backtracing AC_MSG_CHECKING([if we can support backtracing]) AC_TRY_LINK( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/ping.c new/cacti-spine-1.2.9/ping.c --- old/cacti-spine-1.2.8/ping.c 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/ping.c 2020-02-13 21:48:35.000000000 +0100 @@ -842,60 +842,35 @@ * */ int init_sockaddr(struct sockaddr_in *name, const char *hostname, unsigned short int port) { - struct hostent *hostinfo; - int retry_count; - #if !defined(H_ERRNO_DECLARED) && !defined(_AIX) - extern int h_errno; - #endif + struct addrinfo hints, *hostinfo, *p; + int rv, retry_count; - name->sin_family = AF_INET; - name->sin_port = htons (port); + // Initialize the hints structure + memset(&hints, 0, sizeof hints); + // This should be AF_UNSPEC and we should work out if we are using + // AF_INET or AF_INET6 later, but without checking the rest of spine + // for IPv6 compatibility, lets first make it work with IPv4 only + hints.ai_family = AF_INET; retry_count = 0; - - #ifdef HAVE_THREADSAFE_GETHOSTBYNAME - retry: - hostinfo = gethostbyname(hostname); - - if (!hostinfo) { - if (h_errno == TRY_AGAIN && retry_count < 3) { - retry_count++; - usleep(50000); - goto retry; - } else { - return NULL; - } - } else { - name->sin_addr = *(struct in_addr *) hostinfo->h_addr; - } - - #else - #ifdef HAVE_GETHOSTBYNAME_R_GLIBC - struct hostent result_buf; - size_t len = 1024; - char *buf; - int herr; - int rv; - - buf = malloc(len*sizeof(char)); - memset(buf, 0, len*sizeof(char)); + rv = 0; while (1) { - rv = gethostbyname_r(hostname, &result_buf, buf, len, - &hostinfo, &herr); + rv = getaddrinfo(hostname, NULL, &hints, &hostinfo); + if (rv) { + if (rv == TRY_AGAIN && retry_count < 3) { + if (hostinfo != NULL) { + freeaddrinfo(hostinfo); + } - if (!hostinfo) { - if (rv == ERANGE) { - len *= 2; - buf = realloc(buf, len*sizeof(char)); - - continue; - } else if (herr == TRY_AGAIN && retry_count < 3) { retry_count++; usleep(50000); continue; } else { - free(buf); + SPINE_LOG(("WARNING: Error resolving host %s (%s)", hostname, gai_strerror(rv))); + if (hostinfo != NULL) { + freeaddrinfo(hostinfo); + } return FALSE; } } else { @@ -903,80 +878,17 @@ } } - name->sin_addr = *(struct in_addr *) hostinfo->h_addr; - - free(buf); - #else - #ifdef HAVE_GETHOSTBYNAME_R_SOLARIS - size_t len = 8192; - char *buf = NULL; - struct hostent result; - - buf = malloc(len*sizeof(char)); - memset(buf, 0, sizeof(buf)); - - while (1) { - hostinfo = gethostbyname_r(hostname, &result, buf, len, &h_errno); - if (!hostinfo) { - if (errno == ERANGE) { - len += 1024; - buf = realloc(buf, len*sizeof(char)); - memset(buf, 0, sizeof(buf)); - - continue; - } else if (h_errno == TRY_AGAIN && retry_count < 3) { - retry_count++; - usleep(50000); - continue; - } else { - free(buf); - return NULL; - } - } else { - break; - } - } - - name->sin_addr = *(struct in_addr *) hostinfo->h_addr; - - free(buf); - #else - #ifdef HAVE_GETHOSTBYNAME_R_HPUX - struct hostent hostent; - struct hostent_data buf; - int rv; - - rv = gethostbyname_r(hostname, &hostent, &buf); - if (!rv) { - name->sin_addr = *(struct in_addr *) hostent->h_addr; - } - - #else - retry: - thread_mutex_lock(LOCK_GHBN); - hostinfo = gethostbyname(hostname); - if (!hostinfo) { - thread_mutex_unlock(LOCK_GHBN); - if (h_errno == TRY_AGAIN && retry_count < 3) { - retry_count++; - usleep(50000); - goto retry; - } else { - hostinfo = NULL; - } - } else { - name->sin_addr = *(struct in_addr *) hostinfo->h_addr; - thread_mutex_unlock(LOCK_GHBN); - } - #endif - #endif - #endif - #endif - if (hostinfo == NULL) { SPINE_LOG(("WARNING: Unknown host %s", hostname)); return FALSE; } else { + // Copy socket details + name->sin_family = hostinfo->ai_family; + name->sin_addr = ((struct sockaddr_in *)hostinfo->ai_addr)->sin_addr; + name->sin_port = htons(port); + + // Free results var + freeaddrinfo(hostinfo); return TRUE; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/poller.c new/cacti-spine-1.2.9/poller.c --- old/cacti-spine-1.2.8/poller.c 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/poller.c 2020-02-13 21:48:35.000000000 +0100 @@ -139,6 +139,8 @@ int result_length; char temp_result[RESULTS_BUFFER]; int errors = 0; + int *buf_errors; + int *buf_size; char *error_string; int error_len = 0; @@ -188,6 +190,11 @@ snmp_oids_t *snmp_oids; error_string = malloc(DBL_BUFSIZE); + buf_size = malloc(sizeof(int)); + buf_errors = malloc(sizeof(int)); + + *buf_size = 0; + *buf_errors = 0; MYSQL mysql; MYSQL mysqlr; @@ -249,7 +256,8 @@ "rrd_num, snmp_port, snmp_timeout, " "snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_engine_id " " FROM poller_item" - " WHERE host_id=%i" + " WHERE host_id = %i" + " AND deleted = ''" " ORDER BY snmp_port %s", host_id, limits); /* host structure for uptime checks */ @@ -264,7 +272,8 @@ "total_polls, failed_polls, availability, snmp_sysUpTimeInstance, snmp_sysDescr, snmp_sysObjectID, " "snmp_sysContact, snmp_sysName, snmp_sysLocation" " FROM host" - " WHERE id=%i", host_id); + " WHERE id=%i" + " AND deleted = ''", host_id); /* data query structure for reindex detection */ snprintf(query4, BUFSIZE, @@ -335,7 +344,8 @@ "total_polls, failed_polls, availability, snmp_sysUpTimeInstance, snmp_sysDescr, snmp_sysObjectID, " "snmp_sysContact, snmp_sysName, snmp_sysLocation" " FROM host" - " WHERE id=%i", host_id); + " WHERE id=%i" + " AND deleted = ''", host_id); /* data query structure for reindex detection */ snprintf(query4, BUFSIZE, @@ -700,9 +710,7 @@ if (row[2] != NULL) snprintf(reindex->op, sizeof(reindex->op), "%s", row[2]); - if (row[3] != NULL) { - db_escape(&mysql, reindex->assert_value, sizeof(reindex->assert_value), row[3]); - } + if (row[3] != NULL) snprintf(reindex->assert_value, sizeof(reindex->assert_value), "%s", row[3]); if (row[4] != NULL) snprintf(reindex->arg1, sizeof(reindex->arg1), "%s", row[4]); @@ -830,7 +838,7 @@ SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE ASSERT FAILED: '%s=%s'", host->id, host_thread, reindex->data_query_id, reindex->assert_value, poll_result)); } assert_fail = FALSE; - } else if ((!strcmp(reindex->op, "=")) && (strcmp(reindex->assert_value,poll_result))) { + } else if ((!strcmp(reindex->op, "=")) && (strcmp(reindex->assert_value, poll_result))) { if (is_debug_device(host->id) || set.spine_log_level == 2) { SPINE_LOG(("Device[%i] HT[%i] DQ[%i] RECACHE ASSERT FAILED: '%s=%s'", host->id, host_thread, reindex->data_query_id, reindex->assert_value, poll_result)); } else { @@ -1128,7 +1136,7 @@ (!STRMATCH(last_snmp_engine_id, poller_items[i].snmp_engine_id))))) { if (num_oids > 0) { - snmp_get_multi(host, snmp_oids, num_oids); + snmp_get_multi(host, poller_items, snmp_oids, num_oids); for (j = 0; j < num_oids; j++) { if (host->ignore_host) { @@ -1142,11 +1150,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* continue */ @@ -1163,11 +1167,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* is valid output, continue */ @@ -1185,11 +1185,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } SET_UNDEFINED(snmp_oids[j].result); @@ -1235,7 +1231,7 @@ } if (num_oids >= host->max_oids) { - snmp_get_multi(host, snmp_oids, num_oids); + snmp_get_multi(host, poller_items, snmp_oids, num_oids); for (j = 0; j < num_oids; j++) { if (host->ignore_host) { @@ -1249,11 +1245,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* continue */ @@ -1270,11 +1262,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* is valid output, continue */ @@ -1292,11 +1280,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } SET_UNDEFINED(snmp_oids[j].result); @@ -1343,11 +1327,7 @@ poller_items[i].arg1, poller_items[i].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[i].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[i].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[i].local_data_id, false); } } else if ((is_numeric(poll_result)) || (is_multipart_output(trim(poll_result)))) { snprintf(poller_items[i].result, RESULTS_BUFFER, "%s", poll_result); @@ -1366,11 +1346,7 @@ poller_items[i].arg1, poller_items[i].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[i].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[i].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[i].local_data_id, false); } SET_UNDEFINED(poller_items[i].result); @@ -1407,11 +1383,7 @@ poller_items[i].arg1, poller_items[i].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[i].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[i].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[i].local_data_id, false); } } else if ((is_numeric(poll_result)) || (is_multipart_output(trim(poll_result)))) { snprintf(poller_items[i].result, RESULTS_BUFFER, "%s", poll_result); @@ -1430,11 +1402,7 @@ poller_items[i].arg1, poller_items[i].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[i].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[i].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[i].local_data_id, false); } SET_UNDEFINED(poller_items[i].result); @@ -1469,7 +1437,7 @@ /* process last multi-get request if applicable */ if (num_oids > 0) { - snmp_get_multi(host, snmp_oids, num_oids); + snmp_get_multi(host, poller_items, snmp_oids, num_oids); for (j = 0; j < num_oids; j++) { if (host->ignore_host) { @@ -1483,11 +1451,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* continue */ @@ -1504,11 +1468,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } /* is valid output, continue */ @@ -1526,11 +1486,7 @@ poller_items[snmp_oids[j].array_position].arg1, snmp_oids[j].result)); } else if (set.spine_log_level == 1) { errors++; - if (error_len == 0) { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, "%i", poller_items[snmp_oids[j].array_position].local_data_id); - } else { - error_len += snprintf(error_string+error_len, DBL_BUFSIZE-error_len, ", %i", poller_items[snmp_oids[j].array_position].local_data_id); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, poller_items[snmp_oids[j].array_position].local_data_id, false); } SET_UNDEFINED(snmp_oids[j].result); @@ -1712,15 +1668,45 @@ SPINE_LOG_DEBUG(("Device[%i] HT[%i] DEBUG: HOST COMPLETE: About to Exit Device Polling Thread Function", host_id, host_thread)); } - if (error_len > 0) { - SPINE_LOG(("WARNING: Invalid Response(s), Errors[%i] Device[%i] Thread[%i] DS[%s]", errors, host_id, host_thread, error_string)); - } + buffer_output_errors(error_string, buf_size, buf_errors, host_id, host_thread, 0, true); free(error_string); + free(buf_size); + free(buf_errors); *host_errors = errors; } +/*! \fn void buffer_output_errors(local_data_id) { + * \brief buffers output errors and pushes those errors to standard + * output as required. + * \param char* buffer - pointer to the output buffer + * \param int device_id - the device id + * \param int thread id - the device thread + * \param int local_data_id - the local data id + * \param boolean flush - flush any part of buffer + */ +void buffer_output_errors(char *error_string, int *buf_size, int *buf_errors, int device_id, int thread_id, int local_data_id, bool flush) { + int error_len; + char tbuffer[SMALL_BUFSIZE]; + + if (flush && *buf_errors > 0) { + SPINE_LOG(("WARNING: Invalid Response(s), Errors[%i] Device[%i] Thread[%i] DS[%s]", *buf_errors, device_id, thread_id, error_string)); + } else if (!flush) { + snprintf(tbuffer, SMALL_BUFSIZE, *buf_errors > 0 ? ", %i" : "%i", local_data_id); + error_len = strlen(tbuffer); + if (*buf_size + error_len >= DBL_BUFSIZE) { + SPINE_LOG(("WARNING: Invalid Response(s), Errors[%i] Device[%i] Thread[%i] DS[%s]", *buf_errors, device_id, thread_id, error_string)); + *buf_errors = 1; + *buf_size = snprintf(error_string, DBL_BUFSIZE, "%i", local_data_id); + } else { + (*buf_errors)++; + snprintf(error_string + *buf_size, DBL_BUFSIZE, "%s", tbuffer); + *buf_size += error_len; + } + } +} + /*! \fn int is_multipart_output(char *result) * \brief validates the output syntax is a valid name value pair syntax * \param result the value to be checked for legality diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/poller.h new/cacti-spine-1.2.9/poller.h --- old/cacti-spine-1.2.8/poller.h 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/poller.h 2020-02-13 21:48:35.000000000 +0100 @@ -37,3 +37,4 @@ extern void get_system_information(host_t *host, MYSQL *mysql, int system); extern int is_multipart_output(char *result); extern int validate_result(char *result); +extern void buffer_output_errors(char * error_string, int * buf_size, int * buf_errors, int device_id, int thread_id, int local_data_id, bool flush); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/snmp.c new/cacti-spine-1.2.9/snmp.c --- old/cacti-spine-1.2.8/snmp.c 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/snmp.c 2020-02-13 21:48:35.000000000 +0100 @@ -629,7 +629,7 @@ } } -/*! \fn char *snmp_get_multi(host_t *current_host, snmp_oids_t *snmp_oids, int num_oids) +/*! \fn char *snmp_get_multi(host_t *current_host, target_t *poller_items, snmp_oids_t *snmp_oids, int num_oids) * \brief performs multiple OID snmp_get's in a single network call * * This function will a group of snmp OID's for a host. The host snmp @@ -637,7 +637,7 @@ * the snmp_oids array with the results from the snmp api call. * */ -void snmp_get_multi(host_t *current_host, snmp_oids_t *snmp_oids, int num_oids) { +void snmp_get_multi(host_t *current_host, target_t *poller_items, snmp_oids_t *snmp_oids, int num_oids) { struct snmp_pdu *pdu = NULL; struct snmp_pdu *response = NULL; struct variable_list *vars = NULL; @@ -659,7 +659,7 @@ namep->name_len = MAX_OID_LEN; if (!snmp_parse_oid(snmp_oids[i].oid, namep->name, &namep->name_len)) { - SPINE_LOG(("Device[%i] ERROR: Problems parsing Multi SNMP OID! (oid: %s), Set MAX_OIDS to 1 for this host to isolate bad OID", current_host->id, snmp_oids[i].oid)); + SPINE_LOG(("Device[%i] DS[%i] ERROR: Problems parsing Multi SNMP OID! (oid: %s), Set MAX_OIDS to 1 for this host to isolate bad OID", current_host->id, poller_items[snmp_oids[i].array_position].local_data_id, snmp_oids[i].oid)); /* Mark this OID as "bad" */ SET_UNDEFINED(snmp_oids[i].result); @@ -692,7 +692,7 @@ if (!IS_UNDEFINED(snmp_oids[i].result)) { snprint_value(temp_result, RESULTS_BUFFER, vars->name, vars->name_length, vars); - snprintf(snmp_oids[i].result, RESULTS_BUFFER, "%s", trim(strip_alpha(temp_result))); + snprintf(snmp_oids[i].result, RESULTS_BUFFER, "%s", trim(temp_result)); vars = vars->next_variable; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cacti-spine-1.2.8/snmp.h new/cacti-spine-1.2.9/snmp.h --- old/cacti-spine-1.2.8/snmp.h 2019-12-09 00:49:14.000000000 +0100 +++ new/cacti-spine-1.2.9/snmp.h 2020-02-13 21:48:35.000000000 +0100 @@ -38,5 +38,5 @@ extern char *snmp_get(host_t *current_host, char *snmp_oid); extern char *snmp_getnext(host_t *current_host, char *snmp_oid); extern int snmp_count(host_t *current_host, char *snmp_oid); -extern void snmp_get_multi(host_t *current_host, snmp_oids_t *snmp_oids, int num_oids); +extern void snmp_get_multi(host_t *current_host, target_t *poller_items, snmp_oids_t *snmp_oids, int num_oids); extern void snmp_snprint_value(char *obuf, size_t buf_len, const oid *objid, size_t objidlen, struct variable_list *variable);
