Claus Ibsen created CAMEL-26055:
-----------------------------------

             Summary: camel-snmp - the producer without type sends no OIDs, and 
the trap producer fails for a body that is not a PDU
                 Key: CAMEL-26055
                 URL: https://issues.apache.org/jira/browse/CAMEL-26055
             Project: Camel
          Issue Type: Bug
          Components: camel-snmp
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of snmp (CAMEL-24961), checked with 
{{camel run}} with a small SNMP4J agent bean and trap consumers on localhost.

h4. 1. The producer without type sends no OIDs

{{createPdu}} adds the oids only for type=POLL ({{SnmpProducer}}, main 
5aac7df76b83, lines 82-87), but type has no default, and the producer without 
it, as in the docs ("It can also be used to request information using GET 
method."), sends a GET without variables. Checked on 4.24.0-SNAPSHOT with 
{{camel run}}: {{snmp:...?oids=1.3.6.1.2.1.1.1.0}} without type gave an empty 
{{<snmp></snmp>}}, with no error; with type=POLL the value.

*Proposed change*: default type to POLL for the producer, or add the oids for 
any GET.

h4. 2. The trap producer fails with a NullPointerException for a body that is 
not a PDU

The trap is {{getBody(PDU.class)}} ({{SnmpTrapProducer}}, line 101), and 
nothing converts to a PDU, so text, no body or the XML of a received trap fails 
at line 103 with {{NullPointerException: Cannot invoke 
"org.snmp4j.PDU.setErrorIndex(int)" because "trap" is null}}. Checked on 
4.24.0-SNAPSHOT with {{camel run}}.

*Proposed change*: use {{getMandatoryBody(PDU.class)}}, so the error says what 
the body must be.

h4. 3. type=GET_NEXT on a consumer fails at start

The consumer supports TRAP and POLL only and throws {{IllegalArgumentException: 
The type 'GET_NEXT' is not valid!}} for GET_NEXT ({{SnmpEndpoint}}, lines 
122-133), though the catalog offers GET_NEXT for the type of the endpoint. 
Checked on 4.24.0-SNAPSHOT with {{camel run}}.

*Proposed change*: say in the option that GET_NEXT is for the producer, or 
support a walk in the poller.

h4. 4. The SnmpMessage body of the producer does not convert to text

After a GET the body is a {{new SnmpMessage(..., response)}} (line 199), a 
Camel message as the body, and no type converter takes a Message to a String, 
so {{convertBodyTo String}} fails, where the consumer gives the XML text of the 
PDU. Checked on 4.24.0-SNAPSHOT with {{camel run}}: {{InvalidPayloadException: 
No body available of type: java.lang.String but has type: 
org.apache.camel.component.snmp.SnmpMessage}}.

*Proposed change*: set the body to the XML text, as the consumer does, or add a 
converter from SnmpMessage.

h4. Also read in the code, not run

* The PDU of a trap is not checked against snmpVersion (a PDUv1 for 0, a PDU 
for 1, a ScopedPDU for 3), and the producer changes the PDU of the body in 
place.
* An error answer of a GET (such as noSuchName) is given as a normal message: 
the XML has no error status.
* Without a port, the default is 161 only for POLL and 162 otherwise 
({{SnmpEndpoint}}, lines 267-272), so a GET_NEXT or untyped producer goes to 
162.
* The poller keeps one request PDU for all polls ({{SnmpOIDPoller}}, lines 51 
and 76), the CAMEL-25280 case, which was fixed in SnmpProducer only.
* {{poll()}} always returns 1 (line 144), so sendEmptyMessageWhenIdle and the 
backoff options do not work.
* Stopping one SNMPv3 endpoint removes the USM that all of them share.
* The docs give version2c and version3 as values of snmpVersion (they are 0, 1 
and 3), and say securityName and peerAddress are text (an OctetString and an 
Address).

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to