0

To interface with a Cordex of Alpha Technologies, I need to use the SNMP protocol. I've been going through the documentation and examples from pysnmp in order to get some aspects working, and I have particular issues when using external MIB files from alpha technologies. My first test was the following:

from pysnmp.hlapi import *
from pysnmp.smi import builder, view, compiler, rfc1902
from pysnmp import debug
#debug.setLogger(debug.Debug('all'))
debug.setLogger(debug.Debug('msgproc', 'mibbuild'))
mibBuilder = builder.MibBuilder()

mibViewController = view.MibViewController(mibBuilder)
test = ObjectIdentity('SNMPv2-MIB', 'sysDescr').addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/@mib@')
test.resolveWithMib(mibViewController)
test.getOid()

when I do this it correctly prints out the correct OID:

>>> ObjectName('1.3.6.1.2.1.1.1')

However, when looking at the debug logs, it seems to be using the compiled MIB files from the pysnmp library instead of the ASN.1 files located in "C:/Users/SLN9000/Repositories/cordex/MIB/@mib@". When I do something similar for the MIB file from Alpha technologies

from pysnmp.hlapi import *
from pysnmp.smi import builder, view, compiler, rfc1902
from pysnmp import debug
#debug.setLogger(debug.Debug('all'))
debug.setLogger(debug.Debug('msgproc', 'mibbuild'))
mibBuilder = builder.MibBuilder()

mibViewController = view.MibViewController(mibBuilder)
test = ObjectIdentity('03409602D__Alpha_System_Controller', 'dcpower', 1).addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/')
test.resolveWithMib(mibViewController)
test.getOid()

It fails at the step test.resolveWithMib(mibViewController) with the error

pysnmp.smi.error.MibNotFoundError: 03409602D__Alpha_System_Controller compilation error(s): missing

It's not completely clear to me what I am doing wrong. The MIB file I am using can be downloaded from here. Any help is appreciated!

Zafi
  • 619
  • 6
  • 16

2 Answers2

0

My current workaround is to manually compile all the MIB files with the mibdump.py tool. Not really scalable, but at least it allows me to continue my work.

Zafi
  • 619
  • 6
  • 16
-1

It looks like the canonical name of the MIB they ship in 03409602D__Alpha_System_Controller file is AlphaPowerSystem-MIB (from first line of that file). I think you should better rename this file into the canonical name to simplify matters.

Other files in that .zip archive seem to be copies of standard SNMP MIBs. It is okay that pysnmp uses these of its own -- these core MIBs are implementation-specific. Therefore you do not need the rest of the MIBs from that .zip.

Once you are done with the above, you should be able to perform MIB query like this:

test = ObjectIdentity('AlphaPowerSystem-MIB', 'dcpower', 1).addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/')

It works with the snmptranslate.py tool which is based on pysnmp:

$ snmptranslate.py -On  AlphaPowerSystem-MIB::dcpower

1.3.6.1.4.1.7309.4

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
  • This still doesn't work: it's failing with the same error as before. Inspection of the debug lines say that it cannot find the pyc file (file AlphaPowerSystem-MIB.pyc access error: [Errno 2] No such file:) – Zafi Mar 16 '17 at 13:32
  • I'll have a look at the snmptranslate.py tool, maybe I can reverse engineer it from there. – Zafi Mar 16 '17 at 13:37
  • Even the snmptranslate.py tool you mention does not seem to work, it gives me the error: Error: AlphaPowerSystem-MIB compilation error(s): missing – Zafi Mar 16 '17 at 13:46
  • The snmptranslate.py tool (as installed fresh by "pip install pysnmp-apps") works for me. Do you give any paths to MIBs to the tool? By default it fetches MIB sources from the Internet e.g. not requiring anything from you. – Ilya Etingof Mar 16 '17 at 16:02
  • Make sure you have the latest packages (pysnmp/pysmi) installed, clean up "...PySNMP Configuration\mibs\" directory from stall .pyc files. If it still failing for you, file an issue for pysnmp at Github along with your reproducer code snippet and traceback you are getting. – Ilya Etingof Mar 16 '17 at 16:07
  • I used the exact same parameters as you for snmptranslate.py. My pysnmp version is 4.3.4 and pysmi version is 0.0.8 (and I'm running on Windows 7). As far as I can see those are the latest versions. – Zafi Mar 17 '17 at 09:05