summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-08-27 19:54:09 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-08-27 19:54:09 +0200
commitbd6cff7f9ce4e03ee1d8d624c9e3f4c923467a73 (patch)
treec991b96d65ed07be33edbdcd44a1d490726d0b81 /plugins/check_snmp.c
parentd3e1c0314d94e9f97c822fc80659c7234308045f (diff)
downloadmonitoring-plugins-bd6cff7f9ce4e03ee1d8d624c9e3f4c923467a73.tar.gz
check_snmp: use snmp v2c if community is given
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c8
1 files changed, 8 insertions, 0 deletions
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) {
516 char *port = NULL; 516 char *port = NULL;
517 char *miblist = NULL; 517 char *miblist = NULL;
518 char *connection_prefix = NULL; 518 char *connection_prefix = NULL;
519 bool snmp_version_set_explicitely = false;
519 // TODO error checking 520 // TODO error checking
520 while (true) { 521 while (true) {
521 int option_char = getopt_long( 522 int option_char = getopt_long(
@@ -567,6 +568,8 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
567 } else { 568 } else {
568 die(STATE_UNKNOWN, "invalid SNMP version/protocol: %s", optarg); 569 die(STATE_UNKNOWN, "invalid SNMP version/protocol: %s", optarg);
569 } 570 }
571 snmp_version_set_explicitely = true;
572
570 break; 573 break;
571 case 'N': /* SNMPv3 context name */ 574 case 'N': /* SNMPv3 context name */
572 config.snmp_session.contextName = optarg; 575 config.snmp_session.contextName = optarg;
@@ -858,6 +861,11 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
858 setenv("MIBS", miblist, 1); 861 setenv("MIBS", miblist, 1);
859 } 862 }
860 863
864 // Historical default is SNMP v2c
865 if (!snmp_version_set_explicitely && config.snmp_session.community != NULL) {
866 config.snmp_session.version = SNMP_VERSION_2c;
867 }
868
861 if ((config.snmp_session.version == SNMP_VERSION_1) || 869 if ((config.snmp_session.version == SNMP_VERSION_1) ||
862 (config.snmp_session.version == SNMP_VERSION_2c)) { /* snmpv1 or snmpv2c */ 870 (config.snmp_session.version == SNMP_VERSION_2c)) { /* snmpv1 or snmpv2c */
863 /* 871 /*