[monitoring-plugins] check_snmp: fix two build failures against ...

GitHub git at monitoring-plugins.org
Mon Aug 10 15:30:13 CEST 2026


    Module: monitoring-plugins
    Branch: master
    Commit: 09c05ab8d1838c7a39654cfef00eccfc105feb95
    Author: Daeho Ro <40587651+daeho-ro at users.noreply.github.com>
 Committer: GitHub <noreply at github.com>
      Date: Mon Aug 10 22:25:18 2026 +0900
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=09c05ab8

check_snmp: fix two build failures against net-snmp (#2319)

* check_snmp: use MOPL_USE_OPENSSL in _np_state_generate_key

The rename of USE_OPENSSL to MOPL_USE_OPENSSL (#2253) missed this site, so
_np_state_generate_key always compiles the gnulib branch. lib/utils_base.h only
includes sha256.h when MOPL_USE_OPENSSL is undefined, so building check_snmp
against OpenSSL fails:

  check_snmp_helpers.c:918:20: error: variable has incomplete type 'struct sha256_ctx'
  check_snmp_helpers.c:920:22: error: use of undeclared identifier 'this_monitoring_plugin'
  check_snmp_helpers.c:921:3: error: use of undeclared identifier 'sha256_process_bytes'
  check_snmp_helpers.c:924:2: error: use of undeclared identifier 'sha256_finish_ctx'

While here, update the stale name in the matching #endif comment.

* check_snmp: don't rely on the legacy DEFAULT_SNMP_VERSION alias

net-snmp defines DEFAULT_SNMP_VERSION in net-snmp-config.h only when
NETSNMP_NO_LEGACY_DEFINITIONS is unset. Against a net-snmp that sets it (for
example Homebrew's net-snmp 5.9.5) the build fails:

  check_snmp_helpers.c:130:41: error: use of undeclared identifier 'DEFAULT_SNMP_VERSION'

The alias is also the wrong kind of value here: it expands to the human readable
version number (1, 2 or 3), while netsnmp_session.version expects the
SNMP_VERSION_* encoding, in which SNMP_VERSION_1 is 0 and SNMP_VERSION_2c is 1.
Only version 3 happens to match, so a net-snmp configured with
--with-default-snmp-version=2 would leave the session at an undefined version.

Use SNMP_VERSION_3, which is what the net-snmp default expands to. This only
affects the initial value: -P sets the version explicitly, and check_snmp falls
back to SNMP_VERSION_2c when a community is set.

---

 plugins/check_snmp.d/check_snmp_helpers.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugins/check_snmp.d/check_snmp_helpers.c b/plugins/check_snmp.d/check_snmp_helpers.c
index 0b188289..5a02d9b7 100644
--- a/plugins/check_snmp.d/check_snmp_helpers.c
+++ b/plugins/check_snmp.d/check_snmp_helpers.c
@@ -127,7 +127,7 @@ check_snmp_config check_snmp_config_init() {
 	snmp_sess_init(&tmp.snmp_params.snmp_session);
 
 	tmp.snmp_params.snmp_session.retries = DEFAULT_RETRIES;
-	tmp.snmp_params.snmp_session.version = DEFAULT_SNMP_VERSION;
+	tmp.snmp_params.snmp_session.version = SNMP_VERSION_3;
 	tmp.snmp_params.snmp_session.securityLevel = SNMP_SEC_LEVEL_NOAUTH;
 	tmp.snmp_params.snmp_session.community = (unsigned char *)"public";
 	tmp.snmp_params.snmp_session.community_len = strlen("public");
@@ -898,7 +898,7 @@ state_key np_enable_state(char *keyname, int expected_data_version, const char *
 char *_np_state_generate_key(int argc, char **argv) {
 	unsigned char result[256];
 
-#ifdef USE_OPENSSL
+#ifdef MOPL_USE_OPENSSL
 	/*
 	 * This code path is chosen if openssl is available (which should be the most common
 	 * scenario). Alternatively, the gnulib implementation/
@@ -922,7 +922,7 @@ char *_np_state_generate_key(int argc, char **argv) {
 	}
 
 	sha256_finish_ctx(&ctx, result);
-#endif // FOUNDOPENSSL
+#endif // MOPL_USE_OPENSSL
 
 	char keyname[41];
 	for (int i = 0; i < 20; ++i) {



More information about the Commits mailing list