Date: Fri, 29 Mar 2024 00:46:37 +0000 (UTC) Message-ID: <859684900.141.1711673197890@2997b7dde346> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_140_1284586528.1711673197890" ------=_Part_140_1284586528.1711673197890 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Reading this article is recommended if you want to use SNMP4J-Agent Manged=
Objects (MIB) objects like MOScalar and MOTable with multiple SNMPv3 =
contexts in your agent.
In SNMPv3 the concept of using contexts is generally used to se= parate MIB data into different virtual MIBs named by the context name. As a= consequence, a basic requirement for the MIB instrumentation is, that the = data content is separated by the contexts. With SNMP4J-Agent you have basic= ally three options to realize this requirement:
For each context create a separate ManagedObject
instan=
ce and register it with the target context using MOServer.register.
MOScala= r myScalarObjAContext1 =3D new MyScalarObjA(..); MOScalar myScalarObjAContext2 =3D new MyScalarObjA(..); MOServer server =3D ..; server.register(myScalarObjAContext1, new OctetString("context1")); server.register(myScalarObjAContext2, new OctetString("context2"));
Use the same ManagedObject
instance for all target cont=
exts by calling MOServer.register
repeatedly for eac=
h context with the same instance. The single instance is then responsi=
ble to deliver and update its content (MIB data) based on the context infor=
mation given in the ManagedObject.get
, .next
, .commit
, .undo
, and .cl=
eanup
SubRequest
parameter in the MOScope
=
(in fact it is then a MOContextScope
) member.
OctetSt= ring context1 =3D new OctetString("context1"); OctetString context2 =3D new OctetString("context2"); MOScalar myScalarObjA =3D new MyScalarObjA(..) { =09public void get(SubRequest request) { =09=09if (request.getScope() instanceof MOContextScope) { =09=09=09MOContextScope scope =3D (MOContextScope)request.getScope(); =09=09=09if (context1.equals(scope.getContext()) { =09=09=09=09// return value from context1 =09=09=09=09.. =09=09=09} =09=09=09else if (context2.equals(scope.getContext()) {=09=09=09=09 =09=09=09=09// return value from context2 =09=09=09=09.. =09=09=09} =09=09=09else { =09=09=09=09// cannot be reached =09=09=09} =09=09} =09} } MOServer server =3D ..; server.register(myScalarObjA, context1); server.register(myScalarObjA, context2));
Define the context values you want to support in the agent:
//|:Age= nPro|=3Dmembers OctetString context1 =3D new OctetString("ctx1"); OctetString context2 =3D new OctetString("ctx2"); //|AgenPro:|
Add the contexts to the MOServer instance(s) you use in the agent:= p>
public = static void main(String[] args) { //|:AgenPro|=3Dmain server.addContext(context1); server.addContext(context2); defaultMain(args); //|AgenPro:| }
Register your MIB object instances for each context separately (as e= xplained above in the Background section):
prote= cted void registerMIBs() { //|:AgenPro|=3DregisterBefore try { =09// Create a new instance per generated MIB module (you can use different= MOFactory instances per context if needed): =09Snmp4jAgentTutorialMib tutorialMibCtx1 =3D new Snmp4jAgentTutorialM= ib(getFactory());=20 =09tutorialMibCtx1.registerMOs(server, context1); =09Snmp4jAgentTutorialMib tutorialMibCtx2 =3D new Snmp4jAgentTutorialM= ib(getFactory());=20 =09tutorialMibCtx2.registerMOs(server, context2); } catch (DuplicateRegistrationException drex) { =09logger.error("Duplicate registration: "+drex.getMessage()+"."+ " MIB object registration may be incomplete!", drex); } //|AgenPro:| .. }
Configure the SNMPv3 View-based Access Control Model (VACM) MIB to a= llow SNMPv3 (and/or SNMPv1/2vc) users to access the new non-default context= s:
public = void run() { // initialize agent before registering our own modules agent.initialize(); // this requires sysUpTime to be available. registerMIBs(); // add proxy forwarder agent.setupProxyForwarder(); // now continue agent setup and launch it. agent.run(); //|:AgenPro|=3Drun VacmMIB vacm =3D agent.getVacmMIB(); vacm.addAccess(new OctetString("v3group"), context1, SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("unrestrictedReadView"), new OctetString("unrestrictedWriteView"), new OctetString("unrestrictedNotifyView"), StorageType.nonVolatile); vacm.addAccess(new OctetString("v3group"), context2, SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("unrestrictedReadView"), new OctetString("unrestrictedWriteView"), new OctetString("unrestrictedNotifyView"), StorageType.nonVolatile); //|AgenPro:| }
Related articles