Exemple #1
0
    def __exit__(self, type, value, tb):
        """
        Handles logging and notification in the event that processing terminated
        with an exception.

        Also ensures that statistical information is assembled and dispatched.
        """
        try:
            if isinstance(value, _PacketSourceBlacklist):
                self._server.addToTempBlacklist(self.mac, self._packet_type,
                                                str(value))
                return True
            elif isinstance(value, Exception):
                _logger.critical(
                    "Unable to handle %(type)s from  %(mac)s:\n%(error)s" % {
                        'type':
                        self._packet_type,
                        'mac':
                        self.mac,
                        'error':
                        "\n".join(traceback.format_exception(type, value, tb)),
                    })
                return True
        finally:
            if self._discarded:
                _logger.debug(
                    "Discarded packet of type %(type)s from %(mac)s" % {
                        'type': self._packet_type,
                        'mac': self.mac,
                    })

            time_taken = time.time() - self._start_time
            _logger.debug(
                "%(type)s request from %(mac)s processed in %(seconds).4f seconds"
                % {
                    'type': self._packet_type,
                    'mac': self.mac,
                    'seconds': time_taken,
                })

            if self._definition:
                ip = self._definition.ip
                subnet = self._definition.subnet
                serial = self._definition.serial
            else:
                subnet = serial = None
                ip = self._associated_ip
            statistics.emit(
                statistics.Statistics(
                    self.source_address,
                    self.mac,
                    ip,
                    subnet,
                    serial,
                    self._packet_type,
                    time_taken,
                    not self._discarded,
                    self.port,
                ))
Exemple #2
0
 def getNextDHCPPacket(self):
     """
     Listens for a DHCP packet and initiates processing upon receipt.
     """
     (dhcp_received, source_address) = self._getNextDHCPPacket()
     if not dhcp_received and source_address:
         statistics.emit(
             statistics.Statistics(source_address, None, None, None, None,
                                   None, 0.0, False, False))