Snmp v3 walk throws null pointer exception

Hi Frank

I created user for v3 walk (created vacm group, view and usm local user and auth). I am not quite sure where the NullPointerException is coming from. Is it unable to retrieve user? Could you shed the light?
Thanks

$ snmpwalk -v3 -u snmpuser2 -l authNoPriv -a sha -A 12345abcde 127.0.0.1 1.3.6.1.2.1.10.127.1.3.3.1.9
Timeout: No Response from 127.0.0.1

[DEBUG] 11-Feb-2020::11:34:24,136  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 64: 30:3e:02:01:03:30:11:02:04:40:23:a5:5b:02:03:00:ff:e3:04:01:04:02:01:03:04:10:30:0e:04:00:02:01:00:02:01:00:04:00:04:00:04:00:30:14:04:00:04:00:a0:0e:02:04:00:b3:2b:37:02:01:00:02:01:00:30:00
[DEBUG] 11-Feb-2020::11:34:24,137  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077915, msgMaxSize=65507, msgFlags=04, secModel=3
[DEBUG] 11-Feb-2020::11:34:24,137  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - RFC3414 §3.2.3 Unknown engine ID: 
[DEBUG] 11-Feb-2020::11:34:24,137  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Adding cache entry: StateReference[msgID=1076077915,pduHandle=PduHandle[1873017354],securityEngineID=,securityModel=org.snmp4j.security.USM@72422f4f,securityName=,securityLevel=1,contextEngineID=,contextName=,retryMsgIDs=null]
[DEBUG] 11-Feb-2020::11:34:24,137  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Removed cache entry: StateReference[msgID=1076077915,pduHandle=null,securityEngineID=,securityModel=org.snmp4j.security.USM@72422f4f,securityName=,securityLevel=1,contextEngineID=,contextName=,retryMsgIDs=null]
[DEBUG] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - RFC3414 §3.1.4.b Outgoing message is not encrypted
[DEBUG] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Sending message to 127.0.0.1/60387 with length 88: 30:56:02:01:03:30:11:02:04:40:23:a5:5b:02:03:00:ff:ff:04:01:00:02:01:03:04:15:30:13:04:05:33:32:34:37:33:02:01:00:02:01:00:04:00:04:00:04:00:30:27:04:05:33:32:34:37:33:04:00:a8:1c:02:01:00:02:01:00:02:01:00:30:11:30:0f:06:0a:2b:06:01:06:03:0f:01:01:04:00:41:01:02
[INFO] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Message from 127.0.0.1/60387 not dispatched, reason: statusInfo=1.3.6.1.6.3.15.1.1.4.0 = 2, status=1410
[DEBUG] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:5a:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:00:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:0f:f2:91:c5:e4:b3:f5:1f:ac:e3:df:ea:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077914, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:24,138  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException
[DEBUG] 11-Feb-2020::11:34:25,139  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:5c:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:01:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:8b:ef:23:63:56:fb:9a:b4:a8:07:8e:56:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:25,139  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077916, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:25,140  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:25,140  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException
[DEBUG] 11-Feb-2020::11:34:26,140  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:5d:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:02:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:3a:84:ed:6d:43:0a:64:8d:ca:8d:8f:d6:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:26,141  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077917, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:26,141  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:26,141  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException
[DEBUG] 11-Feb-2020::11:34:27,141  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:5e:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:03:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:e0:5e:1d:12:36:3c:69:8e:4b:f0:5a:0f:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:27,142  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077918, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:27,142  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:27,142  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException
[DEBUG] 11-Feb-2020::11:34:28,143  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:5f:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:04:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:5e:d8:2d:0c:b8:8d:b4:eb:40:d6:b2:68:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:28,143  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077919, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:28,143  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:28,143  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException
[DEBUG] 11-Feb-2020::11:34:29,144  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - Received message from /127.0.0.1/60387 with length 106: 30:68:02:01:03:30:11:02:04:40:23:a5:60:02:03:00:ff:e3:04:01:05:02:01:03:04:2a:30:28:04:05:33:32:34:37:33:02:01:00:02:01:05:04:09:73:6e:6d:70:75:73:65:72:32:04:0c:53:36:71:d4:a5:58:d7:da:c3:08:01:ca:04:00:30:24:04:05:33:32:34:37:33:04:00:a1:19:02:04:00:b3:2b:36:02:01:00:02:01:00:30:0b:30:09:06:05:2b:06:01:02:01:05:00
[DEBUG] 11-Feb-2020::11:34:29,144  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - SNMPv3 header decoded: msgId=1076077920, msgMaxSize=65507, msgFlags=05, secModel=3
[DEBUG] 11-Feb-2020::11:34:29,144  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - getUser(engineID=33:32:34:37:33, securityName=snmpuser2)
[ERROR] 11-Feb-2020::11:34:29,144  Log4j2LogAdapter DefaultUDPTransportMapping_0:0:0:0:0:0:0:0/161: - java.lang.NullPointerException

USM user
created: usm local user snmpuser2 auth sha password 12345abcde priv des password 12345abcde
created: vacm
vacm group v3group1 member snmpuser2 sec-model [ usm ]
vacm group v3group1 access usm auth-no-priv read-view view1 write-view view1
vacm view view1 subtree 1.3.6.* included

[root@dev-vcap2 snmpapp]# snmpwalk -v2c -c public 127.0.0.1 snmpUSMMib
SNMP-USER-BASED-SM-MIB::usmStatsUnsupportedSecLevels.0 = Counter32: 0
SNMP-USER-BASED-SM-MIB::usmStatsNotInTimeWindows.0 = Counter32: 0
SNMP-USER-BASED-SM-MIB::usmStatsUnknownUserNames.0 = Counter32: 0
SNMP-USER-BASED-SM-MIB::usmStatsUnknownEngineIDs.0 = Counter32: 2
SNMP-USER-BASED-SM-MIB::usmStatsWrongDigests.0 = Counter32: 0
SNMP-USER-BASED-SM-MIB::usmStatsDecryptionErrors.0 = Counter32: 0
SNMP-USER-BASED-SM-MIB::usmUserSpinLock.0 = INTEGER: 0
SNMP-USER-BASED-SM-MIB::usmUserSecurityName.“32473”.“initial” = STRING: initial
SNMP-USER-BASED-SM-MIB::usmUserSecurityName.“32473”.“snmpuser2” = STRING: snmpuser2
SNMP-USER-BASED-SM-MIB::usmUserAuthProtocol.“32473”.“initial” = OID: SNMP-USER-BASED-SM-MIB::usmHMACSHAAuthProtocol
SNMP-USER-BASED-SM-MIB::usmUserAuthProtocol.“32473”.“snmpuser2” = OID: SNMP-USER-BASED-SM-MIB::usmHMACSHAAuthProtocol
SNMP-USER-BASED-SM-MIB::usmUserPrivProtocol.“32473”.“initial” = OID: SNMP-USER-BASED-SM-MIB::usmDESPrivProtocol
SNMP-USER-BASED-SM-MIB::usmUserPrivProtocol.“32473”.“snmpuser2” = OID: SNMP-USER-BASED-SM-MIB::usmDESPrivProtocol
SNMP-USER-BASED-SM-MIB::usmUserPublic.“32473”.“initial” = “”
SNMP-USER-BASED-SM-MIB::usmUserPublic.“32473”.“snmpuser2” = “”
SNMP-USER-BASED-SM-MIB::usmUserStorageType.“32473”.“initial” = INTEGER: nonVolatile(3)
SNMP-USER-BASED-SM-MIB::usmUserStorageType.“32473”.“snmpuser2” = INTEGER: nonVolatile(3)
SNMP-USER-BASED-SM-MIB::usmUserStatus.“32473”.“initial” = INTEGER: active(1)
SNMP-USER-BASED-SM-MIB::usmUserStatus.“32473”.“snmpuser2” = INTEGER: active(1)

Without a stack trace for the NullPointerException it is hard to guess what is causing it - with proper configuration, it should not happen though.

To get the RuntimeException forwarded, call in you main method or in static code:

SNMP4JSettings.setForwardRuntimeExceptions(true);

Frank
I was also wondering why there’s no stack trace. Hence, I reached out. However, I found the issue. After I changed the api to create UsmUser without giving the agent id, then everything started working as expected.
Thanks for the tip. I will enable that the next time I need to find stack trace.

Agnes

Agnes,

Ok, fine. Yes, the local engine ID is always a source a problems - if it changes. Therefore, the engine ID of the sample agents always change on reboot to make people aware of that.
In the latest SNMP4J 3.x I have already done some changes to avoid NullPointerExceptions if VACM/USM config does not match with the agent’s engine ID. But maybe I missed something. If you still have the stack trace, it would be great if you can share it here. I will then fix also this issue.

Best regards,
Frank

Hi Frank
We are using 2.8.x. Maybe that’s why? If I run into the same thing, I will be sure provide more info.

Thanks
Agnes