From 26200b0787025a3534df52d2f5d0ab0b69fdfac0 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Fri, 9 Aug 2024 19:23:22 +0200 Subject: [PATCH] Issue #366: Recognize '2c' as a valid SNMP version option * Updated SnmpConfiguration to accept '2c' as a valid SNMP version. --- .../metricshub/extension/snmp/SnmpConfiguration.java | 7 ++++++- .../extension/snmp/SnmpConfigurationTest.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/metricshub-snmp-extension/src/main/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfiguration.java b/metricshub-snmp-extension/src/main/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfiguration.java index 4ae6e9514..14b1d2cf1 100644 --- a/metricshub-snmp-extension/src/main/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfiguration.java +++ b/metricshub-snmp-extension/src/main/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfiguration.java @@ -108,7 +108,12 @@ public static SnmpVersion interpretValueOf(@NonNull final String version) { return V1; } - if ("2".equals(lowerCaseVersion) || "v2".equals(lowerCaseVersion) || "v2c".equals(lowerCaseVersion)) { + if ( + "2".equals(lowerCaseVersion) || + "v2".equals(lowerCaseVersion) || + "v2c".equals(lowerCaseVersion) || + "2c".equals(lowerCaseVersion) + ) { return V2C; } diff --git a/metricshub-snmp-extension/src/test/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfigurationTest.java b/metricshub-snmp-extension/src/test/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfigurationTest.java index fd767a55b..c165ccff0 100644 --- a/metricshub-snmp-extension/src/test/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfigurationTest.java +++ b/metricshub-snmp-extension/src/test/java/org/sentrysoftware/metricshub/extension/snmp/SnmpConfigurationTest.java @@ -1,5 +1,6 @@ package org.sentrysoftware.metricshub.extension.snmp; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -99,4 +100,14 @@ void testValidateConfiguration() { assertThrows(InvalidConfigurationException.class, () -> snmpConfig.validateConfiguration(resourceKey)); } } + + @Test + void testSnmpVersionInterpretValueOf() { + assertEquals(SnmpVersion.V1, SnmpVersion.interpretValueOf("1")); + assertEquals(SnmpVersion.V1, SnmpVersion.interpretValueOf("v1")); + assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("2")); + assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("v2")); + assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("v2c")); + assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("2c")); + } }