summaryrefslogtreecommitdiff
path: root/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py
blob: 385e869ca5e54395d5a797dac3ef48c37bc58f26 (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
"""
SNMP GETNEXT over SNMPv1
++++++++++++++++++++++++

Send a series of SNMP GETNEXT requests using the following options:

  * with SNMPv1, community 'public'
  * over IPv4/UDP
  * to an Agent at demo.snmplabs.com:161
  * for the 1.3.6.1.2.1.1 OID (e.g. SNMPv2-MIB::system MIB branch)

Functionally similar to:

| $ snmpwalk -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1

"""#

from pysnmp.hlapi.v1arch.asyncore import *


def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context):
    if errorIndication:
        print(errorIndication)
        return

    elif errorStatus:
        print('%s at %s' % (errorStatus.prettyPrint(),
                            errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
        return

    else:
        for varBindRow in varBindTable:
            for varBind in varBindRow:
                print(' = '.join([x.prettyPrint() for x in varBind]))

    return context.get('nextVarBinds')

snmpDispatcher = SnmpDispatcher()

stateHandle = nextCmd(
    snmpDispatcher,
    CommunityData('public', mpModel=0),
    UdpTransportTarget(('demo.snmplabs.com', 161)),
    ('1.3.6.1.5.1.1', None),
    cbFun=cbFun
)

snmpDispatcher.transportDispatcher.runDispatcher()