My favorites | Sign in
Project Logo
                
Feeds:
People details
Project owners:
  jmdoyle

Sunlamp v2.0.1 is now available and is fully compatible with SNMP4J v1.10.2

Sunlamp is a simplified SNMP library based on the SNMP4J project. It allows you to continue using all of the basic SNMP4J classes, while at the same time dramatically reducing the amount of SNMP4J boilerplate code you need to write. To get an idea of what Sunlamp can do, take a look at this excerpt from Examples.java :

		/* Initialize some basic stuff */
		final InetAddress localhost = InetAddress.getByName("127.0.0.1");
		final OctetString community = new OctetString("community");
		final OctetString securityName = new OctetString("admin");
		final OctetString authEngineId = new OctetString();

		/* Let's use SNMP4J to make an SNMPv1 GET request */
		Address address = new UdpAddress(localhost, DEFAULT_COMMAND_RESPONDER_PORT);
		CommunityTarget communityTarget = new CommunityTarget(address, community);
		communityTarget.setVersion(version1);
		PDUFactory pduFactory = new DefaultPDUFactory(PDU.GET);
		PDU requestPdu = pduFactory.createPDU(communityTarget);
		requestPdu.add(new VariableBinding(sysDescr));
		Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
		snmp.listen();
		ResponseEvent responseEvent = snmp.send(requestPdu, communityTarget);
		VariableBinding[] bindings = responseEvent.getResponse().toArray();
		printVariableBindings(bindings);
		snmp.close();

		/* Now we'll make that same request using Sunlamp */
		SnmpV1Sender v1Sender = new SnmpV1SenderImpl(community);
		responseEvent = v1Sender.getSync(localhost, sysDescr);
		bindings = responseEvent.getResponse().toArray();
		printVariableBindings(bindings);

		/* Next let's try an SNMPv2 GETBULK request */
		communityTarget.setVersion(version2c);
		pduFactory = new DefaultPDUFactory(PDU.GETBULK);
		requestPdu = pduFactory.createPDU(communityTarget);
		requestPdu.setMaxRepetitions(4);
		requestPdu.setNonRepeaters(0);
		OID sysOrid = new OID("1.3.6.1.2.1.1.9.1.3");
		requestPdu.add(new VariableBinding(sysOrid));
		snmp = new Snmp(new DefaultUdpTransportMapping());
		snmp.listen();
		responseEvent = snmp.getBulk(requestPdu, communityTarget);
		bindings = responseEvent.getResponse().toArray();
		printVariableBindings(bindings);
		snmp.close();

		/* And the same request using Sunlamp */
		SnmpV2Sender v2Sender = new SnmpV2SenderImpl(community);
		responseEvent = v2Sender.getBulkSync(localhost, 4, 0, sysOrid);
		bindings = responseEvent.getResponse().toArray();
		printVariableBindings(bindings);

		/* Finally, we'll perform a simple walk using SNMPv3 */
		UsmUser usmUser = new UsmUser(securityName, null, null, null, null);
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
		usm.addUser(securityName, authEngineId, usmUser);
		SecurityModels.getInstance().addSecurityModel(usm);
		snmp = new Snmp(new DefaultUdpTransportMapping());
		TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
		UserTarget userTarget = new UserTarget(address, securityName, authEngineId.getValue(), SecurityLevel.NOAUTH_NOPRIV);
		userTarget.setSecurityModel(SecurityModel.SECURITY_MODEL_USM);
		userTarget.setVersion(version3);
		snmp.listen();
		List<TreeEvent> treeEvents = treeUtils.getSubtree(userTarget, sysOrid);
		printTreeEvents(treeEvents);

		/* And with Sunlamp */
		SnmpV3Sender v3Sender = new SnmpV3SenderImpl(usmUser, authEngineId);
		treeEvents = v3Sender.walkSync(localhost, sysOrid);
		printTreeEvents(treeEvents);








Hosted by Google Code