MIB2C.CONF(5)
π NAME π
mib2c.conf β literally the whole guide to writing mib2c.conf files so you can do ANYTHING based on MIB input. no cap. π¦
β¨ SYNOPSIS β¨
okay so here's the vibe, bestie β you write a conf file, then you run it:
% 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
πΈ DESCRIPTION πΈ
The mib2c.conf script language is a MIB-particular language designed to easily process MIB nodes in ways that you want. π
And yeah, mib2c is kind of a misnomer (it's a historical thing, don't @ me), because you can produce anything β not just C code. Look in the Net-SNMP "local" directory for a whole bunch of example mib2c.*.conf files and behold the power before you. π
π COMMANDS π
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: π«Ά
@open FILE@β writes generated output toFILE. note that for file specifications, opening-will print to stdout. β¨@append FILE@β appends the givenFILE@close FILE@β closes the givenFILE@push@β save the current outputs, then clear outputs. Use with@open@and@pop@to write to a new file without interfering with current outputs.@pop@β pop up theprocess()stack one level. Use after a@push@to return to the previous set of open files.@foreach $VAR scalar@β repeat iterate over code until@end@, setting$VARto all known scalars@foreach $VAR table@β repeat iterate over code until@end@, setting$VARto all known tables@foreach $VAR column@β repeat iterate over code until@end@, setting$VARto all known columns within a given table. Obviously this must be called within a foreach-table clause.@foreach $VAR nonindex@β repeat iterate over code until@end@, setting$VARto all known non-index columns within a given table. Obviously this must be called within a foreach-table clause.@foreach $VAR internalindex@β repeat iterate over code until@end@, setting$VARto all known internal index columns within a given table. Obviously this must be called within a foreach-table clause.@foreach $VAR externalindex@β repeat iterate over code until@end@, setting$VARto all known external index columns within a given table. Obviously this must be called within a foreach-table clause.@foreach $VAR index@β repeat iterate over code until@end@, setting$VARto all known indexes within a given table. Obviously this must be called within a foreach-table clause.@foreach $VAR notifications@β repeat iterate over code until@end@, setting$VARto all known notifications@foreach $VAR varbinds@β repeat iterate over code until@end@, setting$VARto all known varbinds. Obviously this must be called within a foreach-notifications clause.@foreach $LABEL, $VALUE enum@β repeat iterate over code until@end@, setting$LABELand$VALUEto the label and values from the enum list.@foreach $RANGE_START, $RANGE_END range NODE@β repeat iterate over code until@end@, setting$RANGE_STARTand$RANGE_ENDto the legal accepted range set for a given mibNODE.@foreach $var stuff a b c d@β repeat iterate over valuesa,b,c,das assigned generically (ie, the values are taken straight from the list with no mib-expansion, etc).@while expression@β repeat iterate over code until the expression is false@eval $VAR = expression@β 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.@perleval STUFF@β evaluatesSTUFFdirectly in perl. Note that all mib2c variables interpereted within.conffiles are in$vars{NAME}and that a warning will be printed ifSTUFFdoes not return 0. (adding areturn 0;at the end ofSTUFFis a workaround.)@startperl@/@endperl@β treats everything between these tags as perl code, and evaluates it. π§@next@β 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.@if expression@β 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.@ifconf file@β 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.@ifdir dir@β 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.@define NAME@/@enddefine@β Memorizes ""stuff"" between the define and enddefine tags for later calling asNAMEby@calldefine NAME@.@calldefine NAME@β Executes stuff previously memorized asNAME.@printf "expression" stuff1, stuff2, ...@β Like all the other printf's you know and love. π@run FILE@β Sources the contents ofFILEas a mib2c file, but does not affect current files opened.@include FILE@β Sources the contents ofFILEas a mib2c file and appends its output to the current output.@prompt $var QUESTION@β Presents the user withQUESTION, expects a response and puts it in$var@print STUFF@β Prints stuff directly to the users screen (ie, not to where normal mib2c output goes)@quit@β Bail out (silently) π€«@exit@β Bail out! π
π¦ VARIABLES π¦
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 property 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. π«Ά
$var.ucβ all upper case version of$var$var.objectIDβ dotted, fully-qualified, and numeric OID$var.commaoidβ comma separated numeric OID for array initialization$var.oidlengthβ length of the oid$var.subidβ last number component of oid$var.moduleβ MIB name that the object comes from$var.parentβ contains the label of the parent node of$var.$var.isscalarβ returns 1 if var contains the name of a scalar$var.iscolumnβ returns 1 if var contains the name of a column$var.childrenβ returns 1 if var has children$var.perltypeβ node's perl SYNTAX ($SNMP::MIB{node}{'syntax'})$var.typeβ node'sASN_XXXtype (Net-SNMP specific#define)$var.declβ C data type (char,u_long, ...)$var.readableβ 1 if an object is readable, 0 if not$var.settableβ 1 if an object is writable, 0 if not$var.creatableβ 1 if a column object can be created as part of a new row, 0 if not$var.noaccessβ 1 if not-accessible, 0 if not$var.accessibleβ 1 if accessible, 0 if not$var.storagetypeβ 1 if an object is a StorageType object, 0 if not$var.rowstatusβ 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$var.hasdefvalβ returns 1 if var has a DEFVAL clause$var.defvalβ node's DEFVAL$var.hashintβ returns 1 if var has a HINT clause$var.hintβ node's HINT$var.rangesβ returns 1 if var has a value range defined$var.enumsβ returns 1 if var has enums defined for it.$var.accessβ node's access type$var.statusβ node's status$var.syntaxβ node's syntax$var.referenceβ node's reference$var.descriptionβ node's description
π SEE ALSO π
mib2c(1)β go read it bestie, it's the main character fr fr π
and that's the whole page, mwah π this icon was brought to you by VVERSIONINFO, dated 28 Apr 2004 β yes it's giving vintage, yes it still ate, periodt. ππ¦β¨
π¦ where this page comes from
- alpine 3.23: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- alpine 3.24: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- arch rolling: net-snmp 5.9.5.2-2 Β· BSD
- fedora 44: net-snmp-perl 1:5.9.5.2-4.fc44 Β· MIT-CMU AND BSD-3-Clause AND MIT
- ubuntu stonking: libsnmp-base 5.9.5.2+dfsg-2.1ubuntu5 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms