File: snmp-data-constraints-verification-failure.rst

package info (click to toggle)
python-pysnmp4 7.1.22-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: python: 33,673; makefile: 169; javascript: 4
file content (40 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (2)
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

SNMP data constraints verification error
----------------------------------------

Q. Will PySNMP Manager verify the values it sends to and receives from
   a distant Agent against local MIB constraints?

A. Yes, it can do that. The Manager will verify the values you pass to SET
   request against a MIB if:

   The values are not already PyASN1 objects but some basic Python types
   (like integer or string). You tell PySNMP engine to load appropriate
   MIB where it could lookup the constraints (via the use of MibVariable)
   So, the following code fragment makes PySNMP engine loading SNMPv2-MIB
   and verifying that the 'new system name' value satisfies sysName
   constraints (if any).

.. code-block:: python

    errorIndication, errorStatus, errorIndex, varBinds = await cmdGen.set_cmd(
        cmdgen.CommunityData('public'),
        await cmdgen.UdpTransportTarget(('localhost', 161)),
        ( cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new system name' )
    )

To verify the response values, you should pass at least lookupValues flag
to CommandGenerator \*_cmd() method you use. In the following example
PySNMP will make sure that Agent-supplied value for SNMPv2-MIB::sysName
Managed Object satisfies MIB constraints (if any).

.. code-block:: python

    errorIndication, errorStatus, errorIndex, varBinds = await cmdGen.get_cmd(
        cmdgen.CommunityData('public'),
        await cmdgen.UdpTransportTarget(('localhost', 161)),
        cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0),
        lookupValues=True
    )

In case of constraint violation, a PySNMP exception will be raised.