Réda BENKIRANE
From: [email protected] To: [email protected] Subject: RE: [SNMP4J] Is it possible to create an OID in the agent (server) MIB from the manager (client)? Date: Thu, 29 Oct 2015 14:55:08 +0000 Hi Frank, Thank you very much for your clear answer. I tried to gather what you told me and what I understood to continue building my Agent. What I want exactly is to create a conceptual table that has zero (or one "test" unuseful row) at the beginning and then, to be able to send a SET from the Manager. I want a structure of columns like that : { IPAddress IPAdd, Integer32 NodeID, Integer32 Counter }. => For IP Adresses that already exist in the MIB, I will simply increment the counter by sending a SET. => For IP Addresses that doesn't exist I want to CREATE a NEW row by sending a SET. Do you think that this is possible ? Particularly, what do you think is the best way to increment the counter ? I have thought about GET-ting the value and then SET-ting it but I don't know if this operation is safe (If another client thread tries to do the same thing at the same time). For what I have done till now, it unfortunately doesn't work. When I run the Agent, everything is okay, the conceptual table is created (Verified with an SNMP Walk on the root OID "1.3.6.1.2.1.3" using Paessler SNMP Tester 5.2.1). The problem occurs when I send the SET to the agent FROM the client (manager) (Please see the SET Implementation below). I get this error in the Agent Side : java.lang.Exception: Error 'Inconsistent naming used' generated at: 1.3.6.1.2.1.3.1 = 192.168.1.12 at org.snmp4j.agent.request.SnmpRequest$SnmpSubRequest.requestStatusChanged(SnmpRequest.java:621) at (...) at java.lang.Thread.run(Thread.java:745) I get this error in the Manager (Client) Side : java.io.IOException: Unexpected end of input stream at position 82 at org.snmp4j.asn1.BERInputStream.read(BERInputStream.java:58) at (...) at java.lang.Thread.run(Thread.java:745) Why it tries to write at "1.3.5.1.2.1.3.1" while I want it to write in a NEW row ? Here it would be "1.3.5.1.2.1.3.1.3" When I try to rather write at "1.3.5.1.2.1.3.x.3" (Non Existing Sub-OID) (x = 1, 2 or 3, depends on the column), I get this error (even if I have set ACCESS for the table to ACCESS_READ_CREATE) : Agent Side Error : java.lang.Exception: Error 'Not writable' generated at: 1.3.6.1.2.1.3.1.3 = 192.168.1.12 at org.snmp4j.agent.request.SnmpRequest$SnmpSubRequest.requestStatusChanged(SnmpRequest.java:621) at (...) at java.lang.Thread.run(Thread.java:745)Client Side Error : java.io.IOException: Unexpected end of input stream at position 85 at org.snmp4j.asn1.BERInputStream.read(BERInputStream.java:58) at (...) at java.lang.Thread.run(Thread.java:745) Even when I try to write at Existing-Row OID : "1.3.5.1.2.1.3.x.1", I get the same error ('Not Writeable'). So, regarding all of this, how can I create a new row and increment the counter ? What did I do wrong ? Thank you very much for your help, Please see below the simplified implementations of my agent's main and addViews, and my client's main Reda PS : To understand, here are the implementations : Here is a simplified "Main" of my Agent : public static void main(String[] Args) {final OID customTable = new OID(".1.3.6.1.2.1.3");Agent agent = new Agent("172.24.167.61/161");agent.start(); /* Here we create the conceptual table with ordered values in the MIB * "1.3.6.1.2.1.3.1.x" => 1st column * "1.3.6.1.2.1.3.2.x" => 2nd column * "1.3.6.1.2.1.3.3.x" => 3rd column*/MOTableBuilder customBuilder = new MOTableBuilder(customTable) .addColumnType(1, SMIConstants.SYNTAX_OCTET_STRING, MOAccessImpl.ACCESS_READ_CREATE) .addColumnType(2, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_CREATE) .addColumnType(3, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_CREATE) .addRowValue(new OctetString("192.168.1.10")) .addRowValue(new Integer32(0)) .addRowValue(new Integer32(100)) .addRowValue(new OctetString("192.168.1.11")) .addRowValue(new Integer32(0)) .addRowValue(new Integer32(200)); agent.registerManagedObject(customBuilder.build()); while(true) { System.out.println("Agent running..."); Thread.sleep(5000); }} Here is the minimal view based Access Control method AddViews(VacmMIB vacm) /** * 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); vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile); vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3.6.1.2.1.3"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile); vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3.6.1.2.1.3"), new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile); } And finally here is the simplified "Main" of my SnmpSet Sample (Client) : private static String ipAddress = "172.24.167.61";private static String port = "161"; /* * Root of the 1st column (OctetString IPAddress) : ".1.3.6.1.2.1.3.1" * Root of the 2nd column (Integer32 NodeID) : ".1.3.6.1.2.1.3.2" * Root of the 3rd column (Integer32 Counter) : ".1.3.6.1.2.1.3.3" */final static OID[] customTable = new OID[]{new OID(".1.3.6.1.2.1.3.1"), new OID(".1.3.6.1.2.1.3.2"), new OID(".1.3.6.1.2.1.3.3")}; private static int snmpVersion = SnmpConstants.version2c; private static String community = "public"; public static void main(String[] args) throws Exception { TransportMapping transport = new DefaultUdpTransportMapping(); transport.listen(); CommunityTarget comtarget = new CommunityTarget(); comtarget.setCommunity(new OctetString(community)); comtarget.setVersion(snmpVersion); comtarget.setAddress(new UdpAddress(ipAddress + "/" + port)); comtarget.setRetries(2); comtarget.setTimeout(1500); /* Here we want to SEND a SET in order to CREATE a new ROW in the TABLE * customTable[0] => corresponds to the OID where to put the IP Address (here simply in OctetString format) * customTable[1] => corresponds to the OID where to put the Node-ID (I need a Node ID for my application) * customTable[2] => corresponds to the OID where to put the Counter (Here it is set to 125 but what I want finally * is to INCREMENT the counter, in order to have a Statistic). */PDU customTablePDU = new PDU(); customTablePDU.addAll(new VariableBinding[]{new VariableBinding(customTable[0],new OctetString("192.168.1.12")), new VariableBinding(customTable[1],new Integer32(0)), new VariableBinding(customTable[2],new Integer32(125))});customTablePDU.setType(PDU.SET);Snmp customSnmp = new Snmp(transport); System.out.println("Request:\nSending CustomTable Snmp Set Request to Agent (CREATE a new row)...");ResponseEvent customTableResponse = customSnmp.set(customTablePDU, comtarget);} Réda BENKIRANE > To: [email protected] > From: [email protected] > Date: Thu, 22 Oct 2015 18:33:53 +0200 > Subject: Re: [SNMP4J] Is it possible to create an OID in the agent (server) > MIB from the manager (client)? > > Hi Réda, > > If you have the MIB specification, the steps to do are (for a production > grade system): > > 1. Write or generate using AgenPro, the ManagedObject implementations > for the MIB specification. > 2. Instrument the ManagedObjects (i.e., MOScalars and MOMutableTableRows). > 3. Compile the agent and run it > 4. Set variable binding you want to change. > 5. The agent instrumentation code will be called and can then act upon > the new value. > > As a consequence from the above, you will not be able to create totally > new MIB objects in an agent. > Means, MIB object instances for MIB object definitions, that the authors > of the agent did not implement. > > However, the SNMP standard allows to define SNMP tables. Tables can > contain zero rows. To create > a new row, typically using the RowStatus column of that table, you > simple SET the RowStatus column > of the new row to createAndWait(5). You will have to define/find out a > valid row index (the row "name") > for the new row. That row index OID is then appended to the OID of the > column you SET. > > With the above approach you are able to create "new" objects in an > agent, the agent did not had before. > However, the structure of those objectzs must be already known at > compile time to the agent. > > All the above, is true for product grade agents. > > If you want to simulate an agent and simply provide/put data in an agent > without implementing any > functionality based on that data, then you can also create totally new > object VBs at runtime. > The AgenPro built-in simulation agent does that by dynamically load new > MIB specifications. > You can use the SimMOFactory by implementing the AgentppSimulationMib in > your agent, for instance. > > Hope this helps. > > Best regards, > Frank > > Am 22.10.2015 um 17:27 schrieb Réda BENKIRANE: > > I am using SNMP4J Framework and it implements and makes possible the > > standard SET, GET, GET-NEXT, etc. messages.For example, with a SET, I can > > update the value of the MIB OID "1.3.6.1.2.50.0". This works perfectly for > > me. I can do that using org.snmp4j.Snmp.set(PDU pdu, Target target)What I > > want to do now is to CREATE a custom MIB OID (as "1.3.6.1.2.100.0") FROM > > the client and assign a value to it and not simply update an existing MIB > > OID value.Is there any standard SNMP way to do that easily ? > > Réda BENKIRANE > > _______________________________________________ > > SNMP4J mailing list > > [email protected] > > https://oosnmp.net/mailman/listinfo/snmp4j > > -- > --- > AGENT++ > Maximilian-Kolbe-Str. 10 > 73257 Koengen, Germany > https://agentpp.com > Phone: +49 7024 8688230 > Fax: +49 7024 8688231 > > _______________________________________________ > SNMP4J mailing list > [email protected] > https://oosnmp.net/mailman/listinfo/snmp4j _______________________________________________ SNMP4J mailing list [email protected] https://oosnmp.net/mailman/listinfo/snmp4j
