100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Added wildcard functionality for SNMP
Michael Rademaker6663eaaeb3fa
diff --git a/agent/src/main/java/org/openremote/agent/protocol/snmp/SNMPClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/snmp/SNMPClientProtocol.javaindex 5d3af7e48..b1d381b35 100644--- a/agent/src/main/java/org/openremote/agent/protocol/snmp/SNMPClientProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/snmp/SNMPClientProtocol.java@@ -1,5 +1,6 @@package org.openremote.agent.protocol.snmp;+import com.fasterxml.jackson.databind.node.ObjectNode;import org.apache.camel.builder.RouteBuilder;import org.apache.camel.component.snmp.SnmpMessage;import org.openremote.agent.protocol.AbstractProtocol;@@ -10,6 +11,7 @@ import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.attribute.AttributeState;import org.openremote.model.syslog.SyslogCategory;+import org.openremote.model.value.Values;import org.snmp4j.PDU;import java.util.HashMap;@@ -66,7 +68,19 @@ public class SNMPClientProtocol extends AbstractProtocol<SNMPClientAgent, SNMPCl.routeId(getProtocolName() + getAgent().getId()).process(exchange -> {SnmpMessage msg = exchange.getIn(SnmpMessage.class);+ LOG.fine(String.format("Message received: %s", msg));+PDU pdu = msg.getSnmpMessage();++ AttributeRef wildCardAttributeRef;+ if ((wildCardAttributeRef = oidMap.get("*")) != null) {+ ObjectNode wildCardValue = Values.createJsonObject();+ pdu.getVariableBindings().forEach(variableBinding -> {+ wildCardValue.put(variableBinding.getOid().format(), variableBinding.toValueString());+ });+ updateLinkedAttribute(new AttributeState(wildCardAttributeRef, wildCardValue));+ }+pdu.getVariableBindings().forEach(variableBinding -> {AttributeRef attributeRef = oidMap.get(variableBinding.getOid().format());if (attributeRef != null) {@@ -93,6 +107,12 @@ public class SNMPClientProtocol extends AbstractProtocol<SNMPClientAgent, SNMPClreturn new IllegalArgumentException(msg);});+ if (oid.equals("*") && oidMap.get("*") != null) {+ String msg = "Attribute with wildcard OID already provided for protocol: " + this;+ LOG.info(msg);+ throw new IllegalArgumentException(msg);+ }+oidMap.put(oid, new AttributeRef(assetId, attribute.getName()));}