From bd6cff7f9ce4e03ee1d8d624c9e3f4c923467a73 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 27 Aug 2025 19:54:09 +0200 Subject: check_snmp: use snmp v2c if community is given --- plugins/check_snmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'plugins/check_snmp.c') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 7851631c..35e1f339 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -516,6 +516,7 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) { char *port = NULL; char *miblist = NULL; char *connection_prefix = NULL; + bool snmp_version_set_explicitely = false; // TODO error checking while (true) { int option_char = getopt_long( @@ -567,6 +568,8 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) { } else { die(STATE_UNKNOWN, "invalid SNMP version/protocol: %s", optarg); } + snmp_version_set_explicitely = true; + break; case 'N': /* SNMPv3 context name */ config.snmp_session.contextName = optarg; @@ -858,6 +861,11 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) { setenv("MIBS", miblist, 1); } + // Historical default is SNMP v2c + if (!snmp_version_set_explicitely && config.snmp_session.community != NULL) { + config.snmp_session.version = SNMP_VERSION_2c; + } + if ((config.snmp_session.version == SNMP_VERSION_1) || (config.snmp_session.version == SNMP_VERSION_2c)) { /* snmpv1 or snmpv2c */ /* -- cgit v1.2.3-74-g34f1