How to use the mib2c command?

11,118

Solution 1

You need to do exactly what it says: get the MIB to load first into the parser. Start with using snmptranslate to make sure you can load and parse the MIB:

# export MIBS="+NAME-OF-YOUR-MIB"
# snmptranslate -IR sysSwYear

If that doesn't work, then your MIB isn't being found or loaded because it has errors (or both). If so, run snmptranslate with the -Dparse option and it'll give you way too much information about what it's doing, but it'll let you know where the problems are if you read it all.

Once snmptranslate works as above, then mib2c should work fine (assuming you leave the MIBS environment variable set).

[note: I used export assuming you're using a sh-based shell; use setenv instead and no = sign if you are using a csh-based shell]

Solution 2

If you are on Linux, the default permissions for /var/lib/net-snmp/mib_indexes are 0700 resulting in interesting errors for normal users.

The fix for this is

linux ~ $ mkdir -p ~/.snmp/persist
linux ~ $ echo "persistentDir ~/.snmp/persist" >> ~/.snmp/snmp.conf

Try this if the commands work for superuser but not normal users. Please note that the accepted answer is right but does not address using those commands as a normal user as denoted by '#'.

I found it more intuitive to issue the command as follows:

mib2c -c mib2c.scalar.conf MY-PERSONAL-MIB::sysSwYear.0

The mib must be in one of the directories listed in the output of the following command:

linux ~ $ net-snmp-config --default-mibdirs
Share:
11,118
Gaurav
Author by

Gaurav

Updated on June 14, 2022

Comments

  • Gaurav
    Gaurav almost 2 years

    Actually I'm trying to generate .h & .c files by given sysSwYear as MIBNODE and I'm using following command:

    mib2c -c mib2c.scalar.conf sysSwYear
    

    but it produces the following error:

    You didn't give mib2c a valid OID to start with. IE, I could not find any information about the mib node "sysSwYear.0". This could be caused because you supplied an incorrectly node, or by the MIB that you're trying to generate code from isn't loaded. To make sure your mib is loaded, run mib2c using this as an example:

       env MIBS="+MY-PERSONAL-MIB" mib2c -c mib2c.scalar.conf sysSwYear.0
    

    You might wish to start by reading the MIB loading tutorial at:

    http://www.net-snmp.org/tutorial-5/commands/mib-options.html

    And making sure you can get snmptranslate to display information about your MIB node. Once snmptranslate works, then come back and try mib2c again.

    I have already done everything needed like setting environment variable for MIB and defining a private MIB file in /usr/share/snmp/mibs ...but still no success. What to do?

  • Gaurav
    Gaurav almost 12 years
    Hi Wes,after takin your suggestion on account & doing all the described things,m unable to get it then I ran the snmptranslate with -Dparse option as-> snmptranslate -Dparse ZYXEL-ES2108G-MIB::sysSwYear,And its showed up with this result--- Cannot find module (ZYXEL-ES2108G-MIB): At line 0 in (none) parse-mibs: Module ZYXEL-ES2108G-MIB not found ZYXEL-ES2108G-MIB::sysSwYear: Unknown Object Identifier Even Though I already set the Env variable path and my MIB file is placed in /usr/share/snmp/mibs directory.....What else shall I do?????
  • Wes Hardaker
    Wes Hardaker almost 12 years
    Try setting the MIBDIRS environment variable to "/usr/share/snmp/mibs" if that's where you put it.
  • Gaurav
    Gaurav over 11 years
    Hi Wes, I am struggling very much to find out that why hostname keeps coming as <UNKNOWN> in SNMP-Trap v2...Will u please help me out to rectify this problem..I shall be highly thankful to you...Please help me out.Here is the trap example--<UNKNOWN> UDP: [192.168.1.150]:1028->[192.168.1.23] .iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.sysUpTimeI‌​nstance 0:0:01:07.00 .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObje‌​cts.snmpTrap.snmpTra‌​pOID.0 .iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObje‌​cts.snmpTraps.linkDo‌​wn
  • Wes Hardaker
    Wes Hardaker over 11 years
    Gaurav: you should post that as a new question, probably. But I'm not sure off the top of my head which is why you need to give full details (including the net-snmp version number).
  • Gaurav
    Gaurav over 11 years
    Hi Wess ,Thanks for your Feedback,I got it...simply describes the respective Ip & its corresponding host-name in /etc/hosts file.Actually its for customer requirement,but I didn't ask for net-snmp version number.And I have already posted it as a new question,but didn't find out the proper answer from anyone..That's why at the end ,I asked u about it.Sorry if u felt bad about it
  • Gaurav
    Gaurav over 11 years
    You can check that corresponding link of that question--- stackoverflow.com/questions/13007601/…
  • Ctrl S
    Ctrl S almost 6 years
    env MIBS=+THE-MIB net-snmp/local/mib2c mibNode works as well.