jonnystorm / snmp-elixir

An SNMP client library for Elixir
Mozilla Public License 2.0
33 stars 13 forks source link

Could not import CounterBasedGauge64 from HCNUM-TC.bin #58

Closed workgena closed 1 year ago

workgena commented 1 year ago

Hi,

In 0.4.0, 0.6.0 and even in master I see this weird warning, which does not impact application.

UCD-SNMP-MIB.mib: 37: Could not import [{type,'CounterBasedGauge64'}] from mib HCNUM-TC.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.
LM-SENSORS-MIB.mib: 17: Could not import [{node,ucdExperimental}] from mib UCD-SNMP-MIB.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.
NET-SNMP-PASS-MIB.mib: 72: Undefined type ''Counter64''
NET-SNMP-PASS-MIB.mib: 79: Undefined type ''Opaque''
UCD-DEMO-MIB.mib: 5: Could not import [{node,ucdavis}] from mib UCD-SNMP-MIB.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.
UCD-DISKIO-MIB.mib: 17: Could not import [{node,ucdExperimental}] from mib UCD-SNMP-MIB.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.
UCD-DLMOD-MIB.mib: 11: Could not import [{node,ucdExperimental}] from mib UCD-SNMP-MIB.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.
UCD-IPFWACC-MIB.mib: 9: Could not import [{node,ucdExperimental}] from mib UCD-SNMP-MIB.bin. File not found. Check that the MIB to be IMPORTED is compiled and present in the import path.

It is visible during compilation and during mix test, polluting output.

The application is built inside Docker container from image debian-bullseye elixir-1.15.2 erlang-25.3.2.3

jonnystorm commented 1 year ago

Hi, @workgena ! Thanks for contributing.

First, let's look at the application configuration, found here:

        mib_sources: [
          "/usr/share/snmp/mibs",
        ],

By default, we copy and compile, in order of ascending dependence (via topological sort), whatever MIBs we can find in /usr/share/snmp/mibs. Unfortunately, it is exceedingly common for MIBs to contain syntax errors and obsolete references, and it is also common for installations to leave out some MIBs altogether. These problems inevitably must be dealt with manually.

That said, we do not strictly rely on object name resolution, so it is quite reasonable to do without MIBs, entirely; instead, you can simply point :snmp_ex to an empty directory (to which we have read/execute permissions), then use only OIDs in your application. One way to do this would be to configure :mib_sources with the empty priv/snmp/mibs directory. In this case, your config/config.exs would contain the following.

import Config

config :snmp_ex, mib_sources: ["priv/snmp/mibs"]

Feel free to rm -rf priv/snmp, as it will simply be rebuilt during compilation.

And in the other direction, if you'd like to supplement the missing MIBs, here is a good source.

I hope the above helps. Please let me know if you still have trouble!

workgena commented 1 year ago

Thanks for quick and detailed response.

import Config

config :snmp_ex, mib_sources: ["priv/snmp/mibs"]

By adding this line to config/test.exs the warning message disappeared. And everything works well.

Thank you! 🙏 Ticket can be closed.

jonnystorm commented 1 year ago

I'm glad to hear it, @workgena. Thanks again for contributing!