Details
-
New Feature
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
3.0.0.M4
-
None
-
SnmpEndpoint.java>>
public Producer createProducer() throws Exception {
{ return new SnmpTrapProducer(this); }
if (this.type == SnmpActionType.TRAP)else
{ // return new SnmpProducer(this); return new SnmpProducer(this, this.type); // add the snmp walk }}
SnmpProducer.java>>
public class SnmpProducer extends DefaultProducer {
private SnmpEndpoint endpoint;
private Address targetAddress;
private USM usm;
private CommunityTarget target;
private PDU pdu;
private SnmpActionType actionType;public SnmpProducer(SnmpEndpoint endpoint)
{ super(endpoint); this.endpoint = endpoint; }public SnmpProducer(SnmpEndpoint endpoint, SnmpActionType actionType)
{ super(endpoint); this.endpoint = endpoint; this.actionType = actionType; }@Override
protected void doStart() throws Exception {
super.doStart();this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
log.debug("targetAddress: {}", targetAddress);this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(this.usm);// setting up target
this.target = new CommunityTarget();
this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
this.target.setAddress(this.targetAddress);
this.target.setRetries(this.endpoint.getRetries());
this.target.setTimeout(this.endpoint.getTimeout());
this.target.setVersion(this.endpoint.getSnmpVersion());this.pdu = new PDU();
{ this.pdu.add(new VariableBinding(oid)); }
// only POLL do
if (this.actionType == SnmpActionType.POLL) {
for (OID oid : this.endpoint.getOids())}
this.pdu.setErrorIndex(0);
this.pdu.setErrorStatus(0);
this.pdu.setMaxRepetitions(0);
// this.pdu.setType(PDU.GET);
// add the snmp walk
if (this.actionType == SnmpActionType.POLL)
this.pdu.setType(PDU.GET);
else if (this.actionType == SnmpActionType.GET_NEXT)
this.pdu.setType(PDU.GETNEXT);
else
this.pdu.setType(PDU.GET);
}@Override
protected void doStop() throws Exception {
super.doStop();try
{ SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); }finally
{ this.targetAddress = null; this.usm = null; this.target = null; this.pdu = null; }}
@Override
public void process(final Exchange exchange) throws Exception {
// load connection data only if the endpoint is enabled
Snmp snmp = null;
TransportMapping<? extends Address> transport = null;try {
log.debug("Starting SNMP producer on {}", this.endpoint.getAddress());// either tcp or udp
{ transport = new DefaultTcpTransportMapping(); }
if ("tcp".equals(this.endpoint.getProtocol()))else if ("udp".equals(this.endpoint.getProtocol()))
{ transport = new DefaultUdpTransportMapping(); }else
{ throw new IllegalArgumentException("Unknown protocol: " + this.endpoint.getProtocol()); }snmp = new Snmp(transport);
log.debug("Snmp: i am sending");
snmp.listen();
if (this.actionType == SnmpActionType.GET_NEXT) {
// snmp walk
List<SnmpMessage> smLst = new ArrayList<>();
for (OID oid : this.endpoint.getOids()) {
this.pdu.clear();
this.pdu.add(new VariableBinding(oid));boolean matched = true;
{ break; }
while (matched) {
ResponseEvent responseEvent = snmp.send(this.pdu, this.target);
if (responseEvent == null || responseEvent.getResponse() == null)
PDU response = responseEvent.getResponse();
String nextOid = null;
Vector<? extends VariableBinding> variableBindings = response.getVariableBindings();
for (int i = 0; i < variableBindings.size(); i++) {
VariableBinding variableBinding = variableBindings.elementAt;
Variable variable = variableBinding.getVariable();
nextOid = variableBinding.getOid().toDottedString();
if (!nextOid.startsWith(oid.toDottedString())) { matched = false; break; }
}
if (!matched) { break; }this.pdu.clear();
pdu.add(new VariableBinding(new OID(nextOid)));
smLst.add(new SnmpMessage(getEndpoint().getCamelContext(), response));
}
}
exchange.getIn().setBody(smLst);
} else {
// snmp get
ResponseEvent responseEvent = snmp.send(this.pdu, this.target);log.debug("Snmp: sended");
if (responseEvent.getResponse() != null)
{ exchange.getIn().setBody(new SnmpMessage(getEndpoint().getCamelContext(), responseEvent.getResponse())); }else
{ throw new TimeoutException("SNMP Producer Timeout"); }}
{ transport.close(); }
} finally {
trycatch (Exception e) { }
{ snmp.close(); }
trycatch (Exception e) { }
}
} //end process
}SnmpEndpoint.java>> public Producer createProducer() throws Exception { if (this.type == SnmpActionType.TRAP) { return new SnmpTrapProducer(this); } else { // return new SnmpProducer(this); return new SnmpProducer(this, this.type); // add the snmp walk } } SnmpProducer.java>> public class SnmpProducer extends DefaultProducer { private SnmpEndpoint endpoint; private Address targetAddress; private USM usm; private CommunityTarget target; private PDU pdu; private SnmpActionType actionType; public SnmpProducer(SnmpEndpoint endpoint) { super(endpoint); this.endpoint = endpoint; } public SnmpProducer(SnmpEndpoint endpoint, SnmpActionType actionType) { super(endpoint); this.endpoint = endpoint; this.actionType = actionType; } @Override protected void doStart() throws Exception { super.doStart(); this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); log.debug("targetAddress: {}", targetAddress); this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(this.usm); // setting up target this.target = new CommunityTarget(); this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity())); this.target.setAddress(this.targetAddress); this.target.setRetries(this.endpoint.getRetries()); this.target.setTimeout(this.endpoint.getTimeout()); this.target.setVersion(this.endpoint.getSnmpVersion()); this.pdu = new PDU(); // only POLL do if (this.actionType == SnmpActionType.POLL) { for (OID oid : this.endpoint.getOids()) { this.pdu.add(new VariableBinding(oid)); } } this.pdu.setErrorIndex(0); this.pdu.setErrorStatus(0); this.pdu.setMaxRepetitions(0); // this.pdu.setType(PDU.GET); // add the snmp walk if (this.actionType == SnmpActionType.POLL) this.pdu.setType(PDU.GET); else if (this.actionType == SnmpActionType.GET_NEXT) this.pdu.setType(PDU.GETNEXT); else this.pdu.setType(PDU.GET); } @Override protected void doStop() throws Exception { super.doStop(); try { SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID())); } finally { this.targetAddress = null; this.usm = null; this.target = null; this.pdu = null; } } @Override public void process(final Exchange exchange) throws Exception { // load connection data only if the endpoint is enabled Snmp snmp = null; TransportMapping<? extends Address> transport = null; try { log.debug("Starting SNMP producer on {}", this.endpoint.getAddress()); // either tcp or udp if ("tcp".equals(this.endpoint.getProtocol())) { transport = new DefaultTcpTransportMapping(); } else if ("udp".equals(this.endpoint.getProtocol())) { transport = new DefaultUdpTransportMapping(); } else { throw new IllegalArgumentException("Unknown protocol: " + this.endpoint.getProtocol()); } snmp = new Snmp(transport); log.debug("Snmp: i am sending"); snmp.listen(); if (this.actionType == SnmpActionType.GET_NEXT) { // snmp walk List<SnmpMessage> smLst = new ArrayList<>(); for (OID oid : this.endpoint.getOids()) { this.pdu.clear(); this.pdu.add(new VariableBinding(oid)); boolean matched = true; while (matched) { ResponseEvent responseEvent = snmp.send(this.pdu, this.target); if (responseEvent == null || responseEvent.getResponse() == null) { break; } PDU response = responseEvent.getResponse(); String nextOid = null; Vector<? extends VariableBinding> variableBindings = response.getVariableBindings(); for (int i = 0; i < variableBindings.size(); i++) { VariableBinding variableBinding = variableBindings.elementAt ; Variable variable = variableBinding.getVariable(); nextOid = variableBinding.getOid().toDottedString(); if (!nextOid.startsWith(oid.toDottedString())) { matched = false; break; } } if (!matched) { break; } this.pdu.clear(); pdu.add(new VariableBinding(new OID(nextOid))); smLst.add(new SnmpMessage(getEndpoint().getCamelContext(), response)); } } exchange.getIn().setBody(smLst); } else { // snmp get ResponseEvent responseEvent = snmp.send(this.pdu, this.target); log.debug("Snmp: sended"); if (responseEvent.getResponse() != null) { exchange.getIn().setBody(new SnmpMessage(getEndpoint().getCamelContext(), responseEvent.getResponse())); } else { throw new TimeoutException("SNMP Producer Timeout"); } } } finally { try { transport.close(); } catch (Exception e) { } try { snmp.close(); } catch (Exception e) { } } } //end process }
-
Patch Available
-
Unknown
Description
The current version, the SNMP Component can not support 'snmp walk'.
Although the source code has appear 'GET_NEXT' in SnmpActionType.java, but no found in processor.
Now, i add the 'snmp walk' and in my application it run successfully.
So, if it need add to the next camel version, please check.
Thanks!