davsclaus commented on code in PR #27242:
URL: https://github.com/apache/camel/pull/27242#discussion_r4163317446
##########
components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java:
##########
@@ -143,24 +144,34 @@ public void process(final Exchange exchange) throws
Exception {
while (matched) {
ResponseEvent responseEvent = snmp.send(this.pdu,
this.target);
if (responseEvent == null ||
responseEvent.getResponse() == null) {
- break;
+ throw new TimeoutException("SNMP Producer
Timeout");
}
PDU response = responseEvent.getResponse();
- String nextOid = null;
- List<? extends VariableBinding> variableBindings =
response.getVariableBindings();
- for (int i = 0; i < variableBindings.size(); i++) {
- VariableBinding variableBinding =
variableBindings.get(i);
- nextOid =
variableBinding.getOid().toDottedString();
- if (!nextOid.startsWith(oid.toDottedString())) {
+ if (response.getErrorStatus() == PDU.noSuchName) {
+ // SNMPv1 signals the end of the MIB view with
noSuchName
+ break;
+ }
+ if (response.getErrorStatus() != PDU.noError) {
+ throw new CamelExchangeException(
+ "SNMP walk of " + oid + " failed: " +
response.getErrorStatusText(), exchange);
+ }
+ OID requestedOid = this.pdu.get(0).getOid();
+ VariableBinding next = null;
+ for (VariableBinding variableBinding :
response.getVariableBindings()) {
+ // compare the OIDs, not their strings:
1.3.6.1.4.1.20 is not in the subtree of 1.3.6.1.4.1.2
+ if (!variableBinding.getOid().startsWith(oid)) {
matched = false;
break;
}
+ next = variableBinding;
}
- if (!matched) {
+ // endOfMibView (SNMPv2c/v3) ends the walk, and so
does an OID that does not increase,
+ // otherwise the same OID would be requested again
forever
+ if (!matched || next == null || next.isException() ||
next.getOid().compareTo(requestedOid) <= 0) {
Review Comment:
Nit (optional, non-blocking): when the agent returns an OID inside the
subtree that does not increase, the walk now ends quietly with a successful
(possibly truncated) result. net-snmp's `snmpwalk` reports this as an error
("OID not increasing"). Since this PR already fails on timeouts and agent
errors, would it be more consistent to throw a `CamelExchangeException` here
too, so a misbehaving agent doesn't produce a silently partial result? Fine to
keep as is if you prefer the lenient behaviour; maybe just mention it in the
upgrade guide note.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]