FAQ:Coding 22
From Net-SNMP Wiki
How can I register a MIB module in a different (SNMPv3) context?
Contexts are a mechanism within SNMPv3 (and AgentX) whereby an agent can support parallel versions of the same MIB objects, referring to different underlying data sets. By default, a MIB module registrations will use the default empty context of "". But it's also possible to explicitly register an individual MIB module using a different context.
With the v4 API, this uses the call 'register_mib_context()'
rather than the REGISTER_MIB macro. This is significantly more
detailed, but most of the additional parameters can take fixed
values, if all that's needed is to change the registration context.
Instead of the macro call:
REGISTER_MIB("my_token", my_variables, variable1, my_variables_oid);
use the function call:
register_mib_context( "my_token",
my_variables, sizeof(variable1),
sizeof(my_variables)/sizeof(variable1),
my_variables_oid,
sizeof(my_variables_oid)/sizeof(oid),
DEFAULT_MIB_PRIORITY, 0, 0, NULL,
"my_context", -1, 0);
Things are much easier with the v5 helper-based API. Having created the registration structure, this just requires setting the 'contextName' field before actually registering the MIB module:
netsnmp_handler_registration *reg;
reg = netsnmp_create_handler_registration(.....);
reg->contextName = strdup("my_context");
netsnmp_register_handler(reg);
In either case, it will also be necessary to define suitable
access control entries to cover requests using the new context.
This can either list each context explicitly:
access {group} "my_context" any noauth exact ......
or use a single entry to cover all possible contexts:
access {group} "" any noauth prefix ......
But note that both steps are required. Changing the access control settings won't affect the default context used for MIB registrations, and registering a MIB in a non-default context won't automatically configure the necessary access control settings.
FAQ:Coding
- How do I write C code to integrate with the agent?
- How does the agent fetch the value of a MIB variable from the system?
- Mib2c complains about a missing "mib reference" - what does this mean?
- Mib2c complains about not having a "valid OID" - what does this mean?
- Why doesn't mib2c like the MIB file I'm giving it?
- Mib2c ignores my MIB and generates a pair of 'mib-2' code files. Why?
- What's the difference between the various mib2c configuration files?
- Which mib2c configuration file should I use?
- How can I have mib2c generate code for both scalars and tables?
- Are there any examples, or documentation?
- Where should I put the files produced by 'mib2c'?
- I've created a new module with 'mib2c' but it doesn't work. Why not?
- I've added my code to this template and it still doesn't work. Why not?
- Why does the iterator call my get_{first,next} routines so often?
- How can I get the agent to generate a trap (or inform)?
- How can I get the agent to send an SNMPv1 (or SNMPv2c) trap?
- How can I get the agent to include varbinds with an SNMPv1 trap?
- How can I get the agent to send an SNMPv1 enterprise-specific trap?
- How can I get the agent to send an SNMPv3 trap (or inform)?
- Why does calling 'send_v2trap' generate an SNMPv1 trap (or vice versa)?
- What if I'm using an AgentX sub-agent instead?
- How can I register a MIB module in a different (SNMPv3) context?
