mib2c.conf - How to write mib2c.conf files to do ANYTHING based on MIB input.
% cat > mib2c.test.conf << EOF @foreach $t table@ Starting table $t @foreach $c column@ echo $t has column $c which has a syntax of $c.syntax @end@
@end@ EOF
% mib2c -c mib2c.test.conf internet
The mib2c.conf script language is a MIB-particular language designed to easily process MIB nodes in ways that you want. mib2c is a misnomer (for historical purposes), because you can produce anything (not just C code). Look in the Net-SNMP "local" directory for a bunch of example mib2c.*.conf files and behold the power before you.
All commands within mib2c.conf files are embraced by @ signs. Anything with an @ sign at the front and back of the line is generally supposed to be a mib2c specific command. These are detailed here:
writes generated output to FILE note that for file specifications, opening '-' will print to stdout.
appends the given FILE
closes the given FILE
save the current outputs, then clear outputs. Use with @open@ and @pop@ to write to a new file without interfering with current outputs.
pop up the process() stack one level. Use after a @push@ to return to the previous set of open files.
repeat iterate over code until @end@ setting $VAR to all known scalars
repeat iterate over code until @end@ setting $VAR to all known tables
repeat iterate over code until @end@ setting $VAR to all known columns within a given table. Obviously this must be called within a foreach-table clause.
repeat iterate over code until @end@ setting $VAR to all known non-index columns within a given table. Obviously this must be called within a foreach-table clause.
repeat iterate over code until @end@ setting $VAR to all known internal index columns within a given table. Obviously this must be called within a foreach-table clause.
repeat iterate over code until @end@ setting $VAR to all known external index columns within a given table. Obviously this must be called within a foreach-table clause.
repeat iterate over code until @end@ setting $VAR to all known indexes within a given table. Obviously this must be called within a foreach-table clause.
repeat iterate over code until @end@ setting $VAR to all known notifications
repeat iterate over code until @end@ setting $VAR to all known varbinds Obviously this must be called within a foreach-notifications clause.
repeat iterate over code until @end@ setting $LABEL and $VALUE to the label and values from the enum list.
repeat iterate over code until @end@ setting $RANGE_START and $RANGE_END to the legal accepted range set for a given mib NODE.
repeat iterate over values a, b, c, d as assigned generically (ie, the values are taken straight from the list with no mib-expansion, etc).
repeat iterate over code until the expression is false
evaluates expression and assigns the results to $VAR. This is not a full perl eval, but sort of a ""psuedo"" eval useful for simple expressions while keeping the same variable name space. See below for a full-blown export to perl.
evaluates STUFF directly in perl. Note that all mib2c variables interpereted within .conf files are in $vars{NAME} and that a warning will be printed if STUFF does not return 0. (adding a 'return 0;' at the end of STUFF is a workaround.
treats everything between these tags as perl code, and evaluates it.
restart foreach; should only be used inside a conditional. skips out of current conditional, then continues to skip to end for the current foreach clause.
evaluates expression, and if expression is true processes contained part until appropriate @end@ is reached. If the expression is false, the next @elsif expression@ expression (if it exists) will be evaluated, until an expression is true. If no such expression exists and an @else@ clause is found, it will be evaluated.
If the specified file can be found in the conf file search path, and if found processes contained part until an appropriate @end@ is found. As with a regular @if expression@, @elsif expression@ and @else@ can be used.
If the specified directory exists, process contained part until an appropriate @end@ is found. As with a regular @if expression@, @elsif expression@ and @else@ can be used.
Memorizes ""stuff"" between the define and enddefine tags for later calling as NAME by @calldefine NAME@.
Executes stuff previously memorized as NAME.
Like all the other printf's you know and love.
Sources the contents of FILE as a mib2c file, but does not affect current files opened.
Sources the contents of FILE as a mib2c file and appends its output to the current output.
Presents the user with QUESTION, expects a response and puts it in $var
Prints stuff directly to the users screen (ie, not to where normal mib2c output goes)
Bail out (silently)
Bail out!
Variables in the mib2c language look very similar to perl variables, in that they start with a "$". They can be used for anything you want, but most typically they'll hold mib node names being processed by @foreach ...@ clauses.
They also have a special properties when they are a mib node, such that adding special suffixes to them will allow them to be interpreted in some fashion. The easiest way to understand this is through an example. If the variable 'x' contained the word 'ifType' then some magical things happen. In mib2c output, anytime $x is seen it is replaced with "ifType". Additional suffixes can be used to get other aspects of that mib node though. If $x.objectID is seen, it'll be replaced by the OID for ifType: ".1.3.6.1.2.1.2.2.1.3". Other suffixes that can appear after a dot are listed below.
One last thing: you can use things like $vartext immediately ending in some other text, you can use {}s to get proper expansion of only part of the mib2c input. IE, $xtext will produce "$xtext", but ${x}text will produce "ifTypetext" instead.
all upper case version of $var
dotted, fully-qualified, and numeric OID
comma separated numeric OID for array initialization
length of the oid
last number component of oid
MIB name that the object comes from
contains the label of the parent node of $var.
returns 1 if var contains the name of a scalar
returns 1 if var contains the name of a column
returns 1 if var has children
node's perl SYNTAX ($SNMP::MIB{node}{'syntax'})
node's ASN_XXX type (Net-SNMP specific #define)
C data type (char, u_long, ...)
1 if an object is readable, 0 if not
1 if an object is writable, 0 if not
1 if a column object can be created as part of a new row, 0 if not
1 if not-accessible, 0 if not
1 if accessible, 0 if not
1 if an object is a StorageType object, 0 if not
1 if an object is a RowStatus object, 0 if not 'settable', 'creatable', 'lastchange', 'storagetype' and 'rowstatus' can also be used with table variables to indicate whether it contains writable, creatable, LastChange, StorageType or RowStatus column objects
returns 1 if var has a DEFVAL clause
node's DEFVAL
returns 1 if var has a HINT clause
node's HINT
returns 1 if var has a value range defined
returns 1 if var has enums defined for it.
node's access type
node's status
node's syntax
node's reference
node's description
mib2c(1)