summaryrefslogtreecommitdiff
path: root/docs/source/faq/pass-custom-mib-to-manager.rst
blob: af2d5c00b8ba8094b9d8843c7d76bbe15cbaadbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

How to pass custom MIB to the Manager
-------------------------------------

Q. How to make use of my own MIBs at my Manager application?

A. First you have to convert your plain-text MIB files into 
   pysnmp-compliant Python modules using libsmi2pysnmp tool.

   Once you have your own pysnmp MIB files at hand, you'd have to put them 
   somewhere on the filesystem (possibly bundling them with your application). 
   In order to let pysnmp engine locating and using these modules, pysnmp 
   MIB search path has to be modified.

.. code-block:: python

    from pysnmp.entity.rfc3413.oneliner import cmdgen
    from pysnmp.smi import builder

    cmdGen = cmdgen.CommandGenerator()

    mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController
    .mibBuilder

    mibSources = mibBuilder.getMibSources() + (
        builder.DirMibSource('/opt/my_pysnmp_mibs'),
        )

    mibBuilder.setMibSources(*mibSources)

    # Rest of CommandGenerator app would follow

   The same effect could be achieved by exporting the PYSNMP_MIB_DIRS variable 
   to process environment. Individual directories should be separated with 
   semicolons.

   In case you'd like to .egg your application or just the pysnmp MIB 
   modules, the following code would work.

.. code-block:: python

    from pysnmp.entity.rfc3413.oneliner import cmdgen
    from pysnmp.smi import builder

    cmdGen = cmdgen.CommandGenerator()

    mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController
    .mibBuilder

    mibSources = mibBuilder.getMibSources() + (
        builder.ZipMibSource('my_pysnmp_mibs_pkg.mibs'),
        )

    mibBuilder.setMibSources(*mibSources)

    # Rest of CommandGenerator app would follow

   The PYSNMP_MIB_PKGS environment variable holding semicolon-separated 
   list of modules could also be used for the same purpose.

   Please, note, that Python should be able to import the [.egg] package 
   holding your MIB modules (my_pysnmp_mibs_pkg in the example above). 
   That requires either putting your module into site-packages or modifying 
   Python search math (PYTHONPATH variable).

   Then in your application you could refer to your MIB by its name (when
   resolving symbolic names to OIDs) or import MIB explicitly (with 
   mibBuilder.loadModules()) so that you could resolve OIDs to symbolic 
   names (as well as other MIB information).