Example #1
0
    def dispatch(self, event):
        log.debug("TrapEventDispatcher: Dispatching TrapEvent: %r" % (event))
        try:
            self._connect()

            # Send event
            self._socket.sendall(event.to_json())

            if self._config['dispatcher']['check_response']:
                # Receive event confirmation
                self._socket.setblocking(0)
                timer = int(time.time())
                data = ""
                while (int(time.time()) - timer) < self._socket_timeout:
                    try:
                        data = self._socket.recv(512)
                        break
                    except socket.error, e:
                        pass
                self._socket.setblocking(1)
                if len(data) <= 0 or data.strip() != "ok":
                    log.error("TrapEventDispatcher: Error dispatching event. Response was: %s" % (data))
                    return False

            log.info("TrapEventDispatcher: Dispatched TrapEvent: %r" % (event))

            return True
Example #2
0
    def dispatch(self, event):
        log.debug("TrapEventDispatcher: Dispatching TrapEvent: %r" % (event))
        try:
            self._connect()

            # Send event
            self._socket.sendall(event.to_json())

            if self._config['dispatcher']['check_response']:
                # Receive event confirmation
                self._socket.setblocking(0)
                timer = int(time.time())
                data = ""
                while (int(time.time()) - timer) < self._socket_timeout:
                    try:
                        data = self._socket.recv(512)
                        break
                    except socket.error, e:
                        pass
                self._socket.setblocking(1)
                if len(data) <= 0 or data.strip() != "ok":
                    log.error(
                        "TrapEventDispatcher: Error dispatching event. Response was: %s"
                        % (data))
                    return False

            log.info("TrapEventDispatcher: Dispatched TrapEvent: %r" % (event))

            return True
Example #3
0
    def _handle_trap(self, trap):
        LOG.info("SensuTrapServer: Received Trap: %s" % (trap))

        # Find TrapHandler for this Trap 
        trap_handler = None
        for trap_handler_id, th in self._trap_handlers.items():
            if th.handles(trap):
                LOG.info("SensuTrapServer: %s handling trap %r" % (trap_handler_id, trap))
                # Transform Trap
                trap_event = th.transform(trap)
                # Dispatch TrapEvent
                self._dispatch_trap_event(trap_event)
                return
        LOG.warning("No trap handler found for %r" % (trap))
Example #4
0
    def _handle_trap(self, trap):
        LOG.info("SensuTrapServer: Received Trap: %s" % (trap))

        # Find TrapHandler for this Trap 
        trap_handler = None
        for trap_handler_id, th in self._trap_handlers.items():
            if th.handles(trap):
                LOG.info("SensuTrapServer: %s handling trap %r" % (trap_handler_id, trap))
                # Transform Trap
                trap_event = th.transform(trap)
                # Dispatch TrapEvent
                self._dispatch_trap_event(trap_event)
                return
        LOG.warning("No trap handler found for %r" % (trap))
Example #5
0
    def dispatch(self, event):
        # TODO: send event!
        log.debug("TrapEventDispatcher: Dispatching TrapEvent: %r" % (event))
        try:
            # try to (re)connect
            if self._socket is None:
                log.debug("TrapEventDispatcher: Socket is not connected. Reconnecting")
                self._connect()

            if self._socket is not None:
                # Send event
                self._socket.sendall(event.to_json())

                if self._config["dispatcher"]["check_response"]:
                    # Receive event confirmation
                    self._socket.setblocking(0)
                    timer = int(time.time())
                    data = ""
                    while (int(time.time()) - timer) < self._socket_timeout:
                        try:
                            data = self._socket.recv(512)
                            break
                        except socket.error, e:
                            pass
                    self._socket.setblocking(1)
                    if len(data) <= 0 or data.strip() != "ok":
                        log.error("TrapEventDispatcher: Error dispatching event. Response was: %s" % (data))
                        return False

                # TODO: send event!
                log.info("TrapEventDispatcher: Dispatched TrapEvent: %r" % (event))

                return True

        except:
            self._close()
            log.exception("TrapEventDispatcher: Error dispatching event")
        return False
Example #6
0
 def _configure_udp_transport(self, listen_address, listen_port):
     pysnmp.entity.config.addSocketTransport(self._snmp_engine, udp.domainName,
         udp.UdpTransport().openServerMode((listen_address, listen_port)))
     log.info("TrapReceiver: Initialized SNMP UDP Transport on %s:%s" % (listen_address, listen_port))
Example #7
0
 def _configure_udp_transport(self, listen_address, listen_port):
     pysnmp.entity.config.addSocketTransport(
         self._snmp_engine, udp.domainName,
         udp.UdpTransport().openServerMode((listen_address, listen_port)))
     log.info("TrapReceiver: Initialized SNMP UDP Transport on %s:%s" %
              (listen_address, listen_port))