]>
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
):
25 for i
in list(range(1, count
)):
26 oid
= self
._snmpOID
+ '.1.' + str(i
) + '.0'
27 self
.assertTrue(oid
in results
)
28 self
.assertTrue(isinstance(results
[oid
], Counter64
))
30 oid
= self
._snmpOID
+ '.1.' + str(count
+ 1) + '.0'
31 self
.assertFalse(oid
in results
)
34 self
.assertGreater(results
['1.3.6.1.4.1.43315.2.1.75.0'], 0)
35 # check memory usage > 0
36 self
.assertGreater(results
['1.3.6.1.4.1.43315.2.1.76.0'], 0)
38 def _getSNMPStats(self
, auth
):
40 for (errorIndication
, errorStatus
, errorIndex
, varBinds
) in nextCmd(SnmpEngine(),
42 UdpTransportTarget((self
._snmpServer
, self
._snmpPort
), timeout
=self
._snmpTimeout
),
44 ObjectType(ObjectIdentity(self
._snmpOID
)),
46 self
.assertFalse(errorIndication
)
47 self
.assertFalse(errorStatus
)
48 self
.assertTrue(varBinds
)
49 for key
, value
in varBinds
:
50 keystr
= key
.prettyPrint()
51 if not keystr
.startswith(self
._snmpOID
):
53 results
[keystr
] = value
57 def _checkStats(self
, auth
):
58 # wait 1s so that the uptime is > 0
61 results
= self
._getSNMPStats
(auth
)
62 self
._checkStatsValues
(results
)
64 def testSNMPv2Stats(self
):
66 SNMP: Retrieve statistics via SNMPv2c
69 auth
= CommunityData(self
._snmpV
2Community
, mpModel
=1)
70 self
._checkStats
(auth
)
72 def testSNMPv3Stats(self
):
74 SNMP: Retrieve statistics via SNMPv3
77 auth
= UsmUserData(self
._snmpV
3User
,
78 authKey
=self
._snmpV
3AuthKey
,
79 privKey
=self
._snmpV
3EncKey
,
80 authProtocol
=usmHMACSHAAuthProtocol
,
81 privProtocol
=usmAesCfb128Protocol
)
82 self
._checkStats
(auth
)