]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.recursor-dnssec/test_SNMP.py
3 from pysnmp
.hlapi
import *
5 from recursortests
import RecursorTest
7 class TestSNMP(RecursorTest
):
10 _snmpServer
= '127.0.0.1'
12 _snmpV2Community
= 'secretcommunity'
13 _snmpV3User
= 'secretuser'
14 _snmpV3AuthKey
= 'mysecretauthkey'
15 _snmpV3EncKey
= 'mysecretenckey'
16 _snmpOID
= '1.3.6.1.4.1.43315.2'
19 _config_template
= """
23 def _checkStatsValues(self
, results
):
24 for i
in list(range(1, 93)):
25 oid
= self
._snmpOID
+ '.1.' + str(i
) + '.0'
26 self
.assertTrue(oid
in results
)
27 self
.assertTrue(isinstance(results
[oid
], Counter64
))
30 self
.assertGreater(results
['1.3.6.1.4.1.43315.2.1.75.0'], 0)
31 # check memory usage > 0
32 self
.assertGreater(results
['1.3.6.1.4.1.43315.2.1.76.0'], 0)
34 def _getSNMPStats(self
, auth
):
36 for (errorIndication
, errorStatus
, errorIndex
, varBinds
) in nextCmd(SnmpEngine(),
38 UdpTransportTarget((self
._snmpServer
, self
._snmpPort
), timeout
=self
._snmpTimeout
),
40 ObjectType(ObjectIdentity(self
._snmpOID
)),
42 self
.assertFalse(errorIndication
)
43 self
.assertFalse(errorStatus
)
44 self
.assertTrue(varBinds
)
45 for key
, value
in varBinds
:
46 keystr
= key
.prettyPrint()
47 if not keystr
.startswith(self
._snmpOID
):
49 results
[keystr
] = value
53 def _checkStats(self
, auth
):
54 # wait 1s so that the uptime is > 0
57 results
= self
._getSNMPStats
(auth
)
58 self
._checkStatsValues
(results
)
60 def testSNMPv2Stats(self
):
62 SNMP: Retrieve statistics via SNMPv2c
65 auth
= CommunityData(self
._snmpV
2Community
, mpModel
=1)
66 self
._checkStats
(auth
)
68 def testSNMPv3Stats(self
):
70 SNMP: Retrieve statistics via SNMPv3
73 auth
= UsmUserData(self
._snmpV
3User
,
74 authKey
=self
._snmpV
3AuthKey
,
75 privKey
=self
._snmpV
3EncKey
,
76 authProtocol
=usmHMACSHAAuthProtocol
,
77 privProtocol
=usmAesCfb128Protocol
)
78 self
._checkStats
(auth
)