目前,我正在一个项目中,我接收OPC UA数据并将其通过SNMP发送到PRTG监视系统。我已经在OPC UA数据点和SNMP客户端(具有唯一的OID)之间创建了路由。这里的问题是与PRTG监视系统的连接。当我开始连接时,我在SnmpTrapProducer上收到一个NullPointer异常。看来我无法在SNMPTrapProducer.java中创建PDU类型的陷阱
我发现在SnmpTrapProducer.process(Exchange exchange)中创建的PDU陷阱返回NullPointerException(您可以在图片中看到该类的各个部分)。我尝试了不同的方法,例如更改邮件正文类型或不同的端口以及IP地址。但是我仍然得到NullPointerException。
我必须配置什么,以便陷阱不返回NullPointer异常?
Image of parts of the code
SnmpTrapProducer.java
...
PDU trap = exchange.getIn().getBody(PDU.class);
trap.setErrorIndex(0);
trap.setErrorStatus(0);
trap.setMaxRepetitions(0);
...
以下代码是骆驼路线的配置
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());
OPC组件的消息正文如下所示:
{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}}
错误信息:
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]
任何帮助是极大的赞赏
最佳答案
类SnmpTrapProducer
引发NPE,因为消息正文似乎为空。
如您的图片所示,问题在于变量trap
保持为null
。它应该成为这条线上的对象。
PDU trap = exchange.getIn().getBody(PDU.class);
该行获取消息正文内容,并且希望它是
org.snmp4j.PDU
的实例。不幸的是,您没有显示填充消息正文的代码,但我认为消息正文只是空的。
尝试注销路由中的消息正文,然后再将其传递给SNMP组件
.log("Message body: ${body}")
另一个选择是消息正文是
org.snmp4j.PDU
以外的其他类型,但是我认为这样会抛出TypeConversionException
。