sleepinggenius2 / mib2go

CLI to generate Go models from MIB files
MIT License
6 stars 3 forks source link

Fail to load mib files #1

Open wxzSpirent opened 4 years ago

wxzSpirent commented 4 years ago

hi,

I'm trying out mib2go to load IETF mib files and running into various errors.

Parse file: ...\mib\ietf_rfcs\rfc1157-SNMP.mib:101:27: unexpected "OBJECT IDENTIFIER" (expected "(" ...) Error: Loading module rfc1157-SNMP: Could not load module at rfc1157-SNMP

Parse module: Parse file: ...\mib\ietf_rfcs\rfc1905-SNMPv2-PDU.mib:90:6: unexpected "max-bindings" (expected "END") Error: Loading module rfc1905-SNMPv2-PDU: Could not load module at rfc1905-SNMPv2-PDU

I downloaded mib files from mibDepot. Is there anywhere else to get these files?

I also tried to load from cisco mib files, but also got errors:

[E] Module SNMP-PROXY-MIB: Type not found for node snmpProxyStorageType

sleepinggenius2 commented 4 years ago

The RFCs referenced (1157 and 1905) contain ASN.1 modules that define the SNMP protocol and are not imported by any MIBs. The current parser doesn't understand full ASN.1 syntax, only the subset that I have seen used in SMI v1 and v2 (see sleepinggenius2/gosmi#11). As they are not imported, they should never need to be loaded. I would suggest generating files for only the MIBs that you're looking to use OIDs from, starting from the top and letting the imports be loaded and pruned automatically. I remember you were originally talking about traps, so for that I would grep for all the files that have TRAP-TYPE or NOTIFICATION-TYPE in them and just generate those files.

I'm not familiar with mibDepot, but their data is probably fine, especially for RFCs. I get most of my MIBs from the vendors I work with. Some vendors, like Cisco, make most of their MIBs available to the public, while others bundle them with their firmware or along side it on their support sites, but there are a few that make it almost impossible. The key in most cases is getting the minimum revision to fully support the equipment that you're working with. If you have a support contract with the vendors you're looking to work with, then I highly recommend reaching out to them to determine what you need for the firmware version that you're running. I usually have good luck with sites like http://www.circitor.fr/Mibs or the MIBs bundled with LibreNMS (https://github.com/librenms/librenms/tree/master/mibs) for one-offs and other MIBs that I have difficulty getting from vendors.

The error you're getting with SNMP-PROXY-MIB looks like it's not able to autoload the file for SNMPv2-TC (RFC 2579), which contains the definition for StorageType. The autoloading mechanism will only find files in the search paths that are named the same as the module, with either no extension or one of .mib, .my, .mi2, or .txt.

If you're finding yourself loading a file with RFC in the name, then you're probably doing something wrong, as those should mostly be SMI v1 modules and have been superseded by newer RFCs with SMI v2 modules that use more descriptive names. The library tries its best to map the old imports to the correct new versions, to avoid issues mixing old and new versions of related modules.

wxzSpirent commented 4 years ago

Thank you for your detailed explanation. I'll start with files that have TRAP-TYPE & NOTIFICATION-TYPE.

Regarding the error for generating SNMP-PROXY-MIB, SNMPv2-TC is in the same location. when I ran: mib2go.exe generate -o test.go -M .\mib\ietf_rfcs\ SNMPv2-TC

it generates a snmpv2-tc.go, test.go is empty. I found StorageType in mib file, but not in the generated file. Is this normal? My goal is to load modules from mib files and generate go files for it. So later I can compile those modules directly into the executable and search by OIDs etc. I thought mib2go can be a tool to help me with that, is that correct?

I also tried to load SNMPv2-MIB, but got error: [E] Module SNMPv2-MIB: Type not found for node sysUpTime

I'm puzzled because sysUpTime is defined in SNMPv2-MIB itself right?

Thanks again for your time.