Hi, I tried using one static oid and its value. I'm still not able to retrieve the required value.
I copy and paste the TestAgent code. public class AgentUtil extends BaseAgent { static { LogFactory.setLogFactory(new Log4jLogFactory()); } private String address; public static boolean STOP=false; private Hashtable oid_values = new Hashtable(); public AgentUtil(String address,Hashtable oid_values) throws IOException { super(new File("conf.agent"), new File("bootCounter.agent"), new CommandProcessor(new OctetString(MPv3.createLocalEngineID()))); this.address = address; this.oid_values = oid_values; agent.setWorkerPool(ThreadPool.create("RequestPool", 4)); } @Override protected void registerManagedObjects() { } public void registerManagedObject(ManagedObject mo) { try { server.register(mo, null); } catch (DuplicateRegistrationException ex) { throw new RuntimeException(ex); } } public void registerCustomMO() { // String key = ""; try { // Iterator iterator = oid_values.keySet().iterator(); // while(iterator.hasNext()) { // key = (String) iterator.next(); server.register(createManagedObject(),null); // } } catch (DuplicateRegistrationException e) { e.printStackTrace(); } } private ManagedObject createManagedObject() { VariableBinding vb = new VariableBinding(new OID("0"),new OctetString("WinsXP")); StaticMOGroup group = new StaticMOGroup(new OID("1.2.3.4.5.6.7"),new VariableBinding[]{vb}); return group; } public void unregisterManagedObject(MOGroup moGroup) { moGroup.unregisterMOs(server, getContext(moGroup)); } /* * Empty implementation */ @Override protected void addNotificationTargets(SnmpTargetMIB targetMIB, SnmpNotificationMIB notificationMIB) { targetMIB.addDefaultTDomains(); } /** * Minimal View based Access Control * * http://www.faqs.org/rfcs/rfc2575.html */ @Override protected void addViews(VacmMIB vacm) { vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString( "cpublic"), new OctetString("v1v2group"), StorageType.nonVolatile); vacm.addAccess(new OctetString("v1v2group"), new OctetString("public"), SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"), new OctetString("fullWriteView"), new OctetString( "fullNotifyView"), StorageType.nonVolatile); vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile); } /** * User based Security Model, only applicable to * SNMP v.3 * */ protected void addUsmUser(USM usm) { } protected void initTransportMappings() throws IOException { transportMappings = new TransportMapping[1]; Address addr = GenericAddress.parse(address); TransportMapping tm = TransportMappings.getInstance() .createTransportMapping(addr); transportMappings[0] = tm; } /** * Start method invokes some initialization methods needed to * start the agent * @throws IOException */ public void start() throws IOException { init(); loadConfig(ImportModes.REPLACE_CREATE); addShutdownHook(); getServer().addContext(new OctetString("public")); finishInit(); registerCustomMO(); run(); sendColdStartNotification(); } protected void unregisterManagedObjects() { // here we should unregister those objects previously registered... } /** * The table of community strings configured in the SNMP * engine's Local Configuration Datastore (LCD). * * We only configure one, "public". */ protected void addCommunities(SnmpCommunityMIB communityMIB) { Variable[] com2sec = new Variable[] { new OctetString("public"), // community name new OctetString("cpublic"), // security name getAgent().getContextEngineID(), // local engine ID new OctetString("public"), // default context name new OctetString(), // transport tag new Integer32(StorageType.nonVolatile), // storage type new Integer32(RowStatus.active) // row status }; MOTableRow row = communityMIB.getSnmpCommunityEntry().createRow( new OctetString("public2public").toSubIndex(true), com2sec); communityMIB.getSnmpCommunityEntry().addRow(row); } public void runAgent() throws IOException, InterruptedException { while(!STOP) { System.out.println("Agent running..."); Thread.sleep(5000); } } } Here's my snmp tester print outs [Client] Target address : udp:127.0.0.1/162 [Client] Send PDU : GET[requestID=1075357385, errorStatus=Success(0), errorIndex=0, VBS[1.2.3.4.5.6.7 = Null]] [Client] RESPONSE from 127.0.0.1/162 : noSuchObject Here's some printout on the agent side WARN : org.snmp4j.agent.io.MOServerPersistence - Context 'public' is no longer supported by agent INFO : org.snmp4j.agent.DefaultMOServer - Registered MO StaticMOGroup[root=1.2.3.4.5.6.7,vbs={}] in default context with scope org.snmp4j.agent.DefaultMOScope[lowerBound=1.2.3.4.5.6.7,lowerIncluded=true,upperBound=1.2.3.4.5.6.8,upperIncluded=false] INFO : org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl - Notification 1.3.6.1.6.3.1.1.5.1 reported with [] for context Agent running... Agent running... Agent running... Agent running... Agent running... Agent running... Am I doing it correctly? Regards, Simon > Date: Thu, 17 Jun 2010 18:19:55 +0200 > From: f...@agentpp.com > To: simonsew2...@hotmail.com > CC: snmp4j@agentpp.org > Subject: Re: [SNMP4J] create snmp simulator > > Hi, > > (1) An object identifier (OID) does not start with a dot ("."). > That notation has been invented by the NET-SNMP > team, but is not standard conform and thus not > used by SNMP4J. > > (2) You can use StaticMOGroup instead individually > registering scalars (saves memory). > > Best regards, > Frank > > On 17.06.2010 10:07, simon simon wrote: > > Hi.. > > > > I tried the testAgent demo supplied by the Snmp4jAgent. > > Not really sure how it works yet. Kinda complicated at least for me. > > > > Anyway, > > I've created a simple apps. One is the agent and the other is client > > which sends the pdu and get the response from agent. > > From what I've told earlier, I would like to add in all the oids and > > its value to the agent. > > > > I've done that but not sure it's correct or incorrect (I can't find > > sample code for what I've wanted). The code for that is as follow > > > > public void registerCustomMO() { > > > > String key = ""; > > Iterator iterator = oid_values.keySet().iterator(); > > while(iterator.hasNext()) { > > key = (String) iterator.next(); > > try { > > server.register( new MOScalar(new OID("."+key), > > MOAccessImpl.ACCESS_READ_ONLY, > > new OctetString((String) oid_values.get(key))), > > new OctetString((String) oid_values.get(key))); > > } catch (DuplicateRegistrationException e) { > > e.printStackTrace(); > > } > > > > } > > } > > > > > > For example in my agent, I registered > > oid = 1.3.6.1.2.1.1.1.0 = Hardware: x86 Family 15 Model 6 Stepping 5 > > AT/AT COMPATIBLE - Software: Windows Version 5.2 (Build 3790 > > Multiprocessor Free) > > 1.3.6.1.2.1.1.3.0 = 65 days, 0:21:29.42 > > > > Once I've started the Agent. I ran the client. > > > > In the GET PDU, I requested value for oid "1.3.6.1.2.1.1.1.0". > > What I get is "Windows XP .....". > > > > For oid "1.3.6.1.2.1.1.3.0", I got like "0:00:3.xxxx". (Coincidentally > > reflect the duration that the agent has been running). > > > > So I guess it's still not registering or I'm doing something wrong here? > > Do guide me. > > > > Thx. > > Simon > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > Hotmail: Trusted email with powerful SPAM protection. Sign up now. > > <https://signup.live.com/signup.aspx?id=60969> > > -- > AGENT++ > http://www.agentpp.com > http://www.snmp4j.com > http://www.mibexplorer.com > http://www.mibdesigner.com > _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 _______________________________________________ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j