Apache Camel SNMP Component

0

currently I am working on a project where I receive OPC UA data and send them via SNMP to a PRTG monitoring system. I already created the routes between OPC UA datapoints and a SNMP client (with an unique OID). The problem here is the connection to the PRTG monitoring system. When I start the connection I get a NullPointer Exception on the the SnmpTrapProducer. It seems like I cannot create a trap of type PDU in SNMPTrapProducer.java

I figured out that the PDU trap that is created in SnmpTrapProducer.process(Exchange exchange) returns the NullPointerException(you can see the parts of the class in the picture). I tried different approaches like changing message body types or different ports as well as on ip addresses. But I still get the NullPointerException.

What do I have to configure, so the trap doesn't return a NullPointer Exception?

Image of parts of the code

SnmpTrapProducer.java

...
PDU trap = exchange.getIn().getBody(PDU.class);

trap.setErrorIndex(0);
trap.setErrorStatus(0);
trap.setMaxRepetitions(0);
...

The following code is the configuration of the Camel Route

from("milo-client:opc.tcp://"
                + OpcConfiguration.getIpAdress() + ":"
                + OpcConfiguration.getPort()
                + "?node=RAW(" + snmpOidDataStructure.getOpcDataStructure().getNodeId() + ")&allowedSecurityPolicies=None")
                .to("stream:out")
                .to("snmp://10.3.248.12:5700?protocol=udp&type=TRAP&snmpVersion=1&oids=" + snmpOidDataStructure.getOid());

The message body from the OPC component looks like that:

{value=Variant{value=[LocalizedText{text=CP, locale=de}, LocalizedText{text=Video, locale=de}, LocalizedText{text=Notfallsäule, locale=de}, LocalizedText{text=CP Notruf 2 [Gleis 2], locale=de}, LocalizedText{text=, locale=de}]}, status=StatusCode{name=Good, value=0x00000000, quality=good}, sourceTime=DateTime{utcTime=131999719975360000, javaDate=Wed Apr 17 12:53:17 CEST 2019}, serverTime=DateTime{utcTime=132164793099138549, javaDate=Fri Oct 25 14:15:09 CEST 2019}}

Error Message:

java.lang.NullPointerException: null
        at org.apache.camel.component.snmp.SnmpTrapProducer.process(SnmpTrapProducer.java:112) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.apache.camel.component.milo.client.MiloClientConsumer.handleValueUpdate(MiloClientConsumer.java:78) [Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaMonitoredItem.lambda$setValueConsumer$0(OpcUaMonitoredItem.java:133) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaMonitoredItem.onValueArrived(OpcUaMonitoredItem.java:191) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager.lambda$null$39(OpcUaSubscriptionManager.java:700) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:107) ~[Schnittstellenadapter-1.0-SNAPSHOT-shaded.jar:1.0-SNAPSHOT]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[na:1.8.0_221]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_221]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_221]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_221]
        at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_221]

Any help is greatly appreciated

java
nullpointerexception
apache-camel
snmp4j
asked on Stack Overflow Jan 31, 2020 by Stefan Lederer • edited Feb 27, 2020 by Stefan Lederer

1 Answer

0

The class SnmpTrapProducer throws a NPE because the message body seems to be empty.

As your picture shows, the problem is that the variable trap stays null. It should become an object on this line.

PDU trap = exchange.getIn().getBody(PDU.class);

The line gets the message body content and it wants it to be an instance of org.snmp4j.PDU.

Unfortunately you don't show the code that populates the message body, but I assume the message body is simply empty.

Try to log out the message body in your route before you pass it on to the SNMP component

 .log("Message body: ${body}") 

The other option would be that the message body is of another type than org.snmp4j.PDU, but I think then it would throw a TypeConversionException.

answered on Stack Overflow Feb 7, 2020 by burki • edited Feb 26, 2020 by burki

User contributions licensed under CC BY-SA 3.0