简体   繁体   English

Apache Camel SNMP 组件

[英]Apache Camel SNMP Component

currently I am working on a project where I receive OPC UA data and send them via SNMP to a PRTG monitoring system.目前我正在做一个项目,我接收 OPC UA 数据并通过 SNMP 将它们发送到 PRTG 监控系统。 I already created the routes between OPC UA datapoints and a SNMP client (with an unique OID).我已经在 OPC UA 数据点和 SNMP 客户端(具有唯一的 OID)之间创建了路由。 The problem here is the connection to the PRTG monitoring system.这里的问题是与 PRTG 监控系统的连接。 When I start the connection I get a NullPointer Exception on the the SnmpTrapProducer.当我开始连接时,我在 SnmpTrapProducer 上收到 NullPointer 异常。 It seems like I cannot create a trap of type PDU in SNMPTrapProducer.java似乎我无法在 SNMPTrapProducer.java 中创建 PDU 类型的陷阱

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).我发现在 SnmpTrapProducer.process(Exchange exchange) 中创建的 PDU 陷阱返回 NullPointerException(您可以在图片中看到类的部分)。 I tried different approaches like changing message body types or different ports as well as on ip addresses.我尝试了不同的方法,例如更改消息正文类型或不同的端口以及 IP 地址。 But I still get the NullPointerException.但我仍然得到 NullPointerException。

What do I have to configure, so the trap doesn't return a NullPointer Exception?我必须配置什么才能使陷阱不返回 NullPointer 异常?

Image of parts of the code部分代码的图像

SnmpTrapProducer.java 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以下代码是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:来自 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}}

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任何帮助是极大的赞赏

The class SnmpTrapProducer throws a NPE because the message body seems to be empty .SnmpTrapProducer抛出 NPE,因为消息正文似乎是空的

As your picture shows, the problem is that the variable trap stays null .如您的图片所示,问题在于变量trap保持为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 .该行获取消息正文内容,并希望它是org.snmp4j.PDU一个实例。

Unfortunately you don't show the code that populates the message body, but I assume the message body is simply empty .不幸的是,您没有显示填充消息正文的代码,但我假设消息正文只是 empty

Try to log out the message body in your route before you pass it on to the SNMP component尝试在将路由中的消息正文传递给 SNMP 组件之前注销它

 .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 .另一种选择是消息正文的类型不同于org.snmp4j.PDU ,但我认为它会抛出TypeConversionException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM