[SNMP4J] Raw coding
Marco.Bresciani at alcatel-lucent.it
Marco.Bresciani at alcatel-lucent.it
Thu Apr 19 16:53:25 CEST 2007
Hello all,
I'm having few minor problems with respect to coding and discovering
SNMPv3 or SNMPv2.
In order to understand if I have an engineID or if I have a SNMPv2 device,
is this enough?
/**
* This will do the discovery... maybe!
*/
private void discovery() {
/* variables definition */
Address myAddress = GenericAddress.parse("udp:127.0.0.1/161");
TransportMapping myTransport = new DefaultUdpTransportMapping();
Snmp mySnmp = new Snmp(myTransport);
byte[] myEngine = mySnmp.discoverAuthoritativeEngineID(myAddress,
25000);
/* engine test */
if (myEngine == null) {
// SNMPv2 management
// same as now, I fortunately have it! :-)
} else {
// SNMPv3 management
this.mySnmpV3Management();
}
}
/**
* This will manage SNMPv3 configuration and management...
*
* @see SNMP4J Snmp Javadoc
*/
private void mySnmpV3Management() {
USM myUsm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()),
0);
SecurityModels.getInstance().addSecurityModel(myUsm);
myTransport.listen();
mySnmp.getUSM().addUser(new OctetString("MD5DES"),
new UsmUser(new OctetString("MD5DES"),
AuthMD5.ID,
new OctetString("MD5DESUserAuthPassword"),
PrivDES.ID,
new OctetString("MD5DESUserPrivPassword")));
UserTarget myTarget = new UserTarget();
myTarget.setAddress(myAddress);
myTarget.setRetries(1);
myTarget.setTimeout(5000);
myTarget.setVersion(SnmpConstants.version3);
myTarget.setSecurityLevel(SecurityLevel.AUTH_PRIV);
myTarget.setSecurityName(new OctetString("MD5DES"));
PDU myPdu = new ScopedPDU();
myPdu.add(new VariableBinding(new OID("1.3.6")));
myPdu.setType(PDU.GETNEXT);
ResponseEvent myResponse = mySnmp.send(pdu, target);
PDU myResponsePdu = myResponse.getResponse();
Address myPeerAddress = myResponse.getPeerAddress();
}
Sort of...
bye,
Ing. Marco Bresciani
Alcatel-Lucent
Java Developer
WTD R&D Software Competence Center
via Trento, 30; 20059 Vimercate (Mi); Italy
EMail: Marco.Bresciani at alcatel-lucent.it
Phone: +39 039 686 5546
Fax: +39 039 686 5546
More information about the SNMP4J
mailing list