diff options
author | elie <elie> | 2014-06-21 14:15:11 +0000 |
---|---|---|
committer | elie <elie> | 2014-06-21 14:15:11 +0000 |
commit | 7145d433105bc569dc5a09a4189da17bebc41f1c (patch) | |
tree | af853fc58d9b5d9ab3ede81db068eeec2bebd345 | |
parent | 212aae86e701d001461c39effd9760dda028d2a8 (diff) | |
download | pysnmp-7145d433105bc569dc5a09a4189da17bebc41f1c.tar.gz |
TRAP PDU agent address evaluation made lazy to improve startup time
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pysnmp/proto/api/v1.py | 14 |
2 files changed, 10 insertions, 6 deletions
@@ -53,6 +53,8 @@ Revision 4.2.6rc0 - Handle the case of null writer at Debug printer. - Do not cache snmpEngineId & snmpAdminString at CommandGenerator to let it be reused with many different snmpEngines. +- TRAP PDU agent address evaluation at proto.api made lazy to improve + startup time. - Multiple fixes to verify pyasn1 decoder.decode() return to withstand broken SNMP messages or its components. - Fix to authoritative engine side snmpEngineID discovery procedure: diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py index ee58b59..0e06fe1 100644 --- a/pysnmp/proto/api/v1.py +++ b/pysnmp/proto/api/v1.py @@ -122,17 +122,19 @@ class PDUAPI: apiPDU = PDUAPI() class TrapPDUAPI: - try: - import socket - agentAddress = IpAddress(socket.gethostbyname(socket.gethostname())) - except: - agentAddress = IpAddress('0.0.0.0') - _networkAddress = NetworkAddress().setComponentByPosition(0, agentAddress) + _networkAddress = None _entOid = ObjectIdentifier((1,3,6,1,4,1,20408)) _genericTrap = rfc1157._genericTrap.clone('coldStart') _zeroInt = univ.Integer(0) _zeroTime = TimeTicks(0) def setDefaults(self, pdu): + if self._networkAddress is None: + try: + import socket + agentAddress = IpAddress(socket.gethostbyname(socket.gethostname())) + except: + agentAddress = IpAddress('0.0.0.0') + self._networkAddress = NetworkAddress().setComponentByPosition(0, agentAddress) pdu.setComponentByPosition(0, self._entOid, verifyConstraints=False) pdu.setComponentByPosition(1, self._networkAddress, verifyConstraints=False) pdu.setComponentByPosition(2, self._genericTrap,verifyConstraints=False) |