Package Products :: Package ZenEvents :: Module zentrap :: Class TrapTask
[hide private]
[frames] | no frames]

Class TrapTask

source code

         ZenCollector.tasks.BaseTask --+
                                       |
                          object --+   |
                                   |   |
ZenUtils.captureReplay.CaptureReplay --+
                                       |
                                      TrapTask

Listen for SNMP traps and turn them into events Connects to the TrapService service in zenhub.

Instance Methods [hide private]
 
__init__(self, taskName, configId, scheduleIntervalSeconds=3600, taskConfig=None) source code
 
doTask(self)
This is a wait-around task since we really are called asynchronously.
source code
 
isReplaying(self)
@returns True if we are replaying a packet instead of capturing one
source code
string
getEnterpriseString(self, pdu)
Get the enterprise string from the PDU or replayed packet
source code
dictionary
getResult(self, pdu)
Get the values from the PDU or replayed packet
source code
string
getCommunity(self, pdu)
Get the community string from the PDU or replayed packet
source code
Python FakePacket object
convertPacketToPython(self, addr, pdu)
Store the raw packet for later examination and troubleshooting.
source code
 
replay(self, pdu)
Replay a captured packet
source code
Twisted deferred object
oid2name(self, oid, exactMatch=True, strip=False)
Returns a MIB name based on an OID and special handling flags.
source code
 
_pre_parse(self, session, transport, transport_data, transport_data_length)
Called before the net-snmp library parses the PDU.
source code
 
receiveTrap(self, pdu)
Accept a packet from the network and spin off a Twisted deferred to handle the packet.
source code
 
getPacketIp(self, addr)
For IPv4, convert a pointer to 4 bytes to a dotted-ip-address For IPv6, convert a pointer to 16 bytes to a canonical IPv6 address.
source code
 
processPacket(self, ip_address, port, pdu, ts)
Wrapper around asyncHandleTrap to process the provided packet.
source code
 
_value_from_dateandtime(self, value)
Tries converting a DateAndTime value to a printable string.
source code
 
_convert_value(self, value) source code
 
snmpInform(self, addr, pdu)
A SNMP trap can request that the trap recipient return back a response.
source code
 
decodeSnmpv1(self, addr, pdu) source code
 
decodeSnmpv2(self, addr, pdu) source code
Twisted deferred object
asyncHandleTrap(self, addr, pdu, startProcessTime)
Twisted callback to process a trap
source code
 
displayStatistics(self) source code
 
cleanup(self) source code

Inherited from ZenUtils.captureReplay.CaptureReplay: buildCaptureReplayOptions, capturePacket, processCaptureReplayOptions, replayAll, replayStop

Method Details [hide private]

__init__(self, taskName, configId, scheduleIntervalSeconds=3600, taskConfig=None)
(Constructor)

source code 
Overrides: object.__init__
(inherited documentation)

getEnterpriseString(self, pdu)

source code 

Get the enterprise string from the PDU or replayed packet

Parameters:
  • pdu (binary) - raw packet
Returns: string
enterprise string

getResult(self, pdu)

source code 

Get the values from the PDU or replayed packet

Parameters:
  • pdu (binary) - raw packet
Returns: dictionary
variables from the PDU or Fake packet

getCommunity(self, pdu)

source code 

Get the community string from the PDU or replayed packet

Parameters:
  • pdu (binary) - raw packet
Returns: string
SNMP community

convertPacketToPython(self, addr, pdu)

source code 

Store the raw packet for later examination and troubleshooting.

Parameters:
  • addr ((string, number)) - packet-sending host's IP address and port
  • pdu (binary) - raw packet
Returns: Python FakePacket object
Python FakePacket object
Overrides: ZenUtils.captureReplay.CaptureReplay.convertPacketToPython

replay(self, pdu)

source code 

Replay a captured packet

Parameters:
  • pdu (binary) - raw packet
Overrides: ZenUtils.captureReplay.CaptureReplay.replay

oid2name(self, oid, exactMatch=True, strip=False)

source code 

Returns a MIB name based on an OID and special handling flags.

Parameters:
  • oid (string) - SNMP Object IDentifier
  • exactMatch (boolean) - find the full OID or don't match
  • strip (boolean) - show what matched, or matched + numeric OID remainder
Returns: Twisted deferred object
Twisted deferred object

_pre_parse(self, session, transport, transport_data, transport_data_length)

source code 

Called before the net-snmp library parses the PDU. In the case where a v3 trap comes in with unkwnown credentials, net-snmp silently discards the packet. This method gives zentrap a way to log that these packets were received to help with troubleshooting.

receiveTrap(self, pdu)

source code 

Accept a packet from the network and spin off a Twisted deferred to handle the packet.

Parameters:
  • pdu (netsnmp_pdu object) - Net-SNMP object

processPacket(self, ip_address, port, pdu, ts)

source code 

Wrapper around asyncHandleTrap to process the provided packet.

Parameters:
  • pdu (netsnmp_pdu object) - Net-SNMP object
  • ts (datetime) - time stamp

_value_from_dateandtime(self, value)

source code 

Tries converting a DateAndTime value to a printable string.

A date-time specification.
field  octets  contents                  range
-----  ------  --------                  -----
1      1-2     year*                     0..65536
2        3     month                     1..12
3        4     day                       1..31
4        5     hour                      0..23
5        6     minutes                   0..59
6        7     seconds                   0..60
              (use 60 for leap-second)
7        8     deci-seconds              0..9
8        9     direction from UTC        '+' / '-'
9       10     hours from UTC*           0..13
10      11     minutes from UTC          0..59

snmpInform(self, addr, pdu)

source code 

A SNMP trap can request that the trap recipient return back a response. This is where we do that.

asyncHandleTrap(self, addr, pdu, startProcessTime)

source code 

Twisted callback to process a trap

Parameters:
  • addr (( host-ip, port)) - packet-sending host's IP address, port info
  • pdu (netsnmp_pdu object) - Net-SNMP object
  • startProcessTime (datetime) - time stamp
Returns: Twisted deferred object
Twisted deferred object