コード例 #1
0
ファイル: http.py プロジェクト: netixx/NetProbes
    def send(self, message):
        """Send this message on the network
        :param message: Message instance to send
        """
        try:
            target = ProbeStorage.getProbeById(message.recipientId)
            # serialize our message
            serializedMessage = Params.CODEC.encode(message)
            # put it in a dictionary
            params = {Parameters.POST_MESSAGE_KEYWORD: serializedMessage}
            # transform dictionary into string
            params = urllib.parse.urlencode(
                params, doseq=True, encoding=Parameters.POST_MESSAGE_ENCODING)
            # set the header as header for POST
            headers = {
                "Content-type":
                "application/x-www-form-urlencoded;charset=%s" %
                Parameters.POST_MESSAGE_ENCODING,
                "Accept":
                "text/plain"
            }
            urlQuery = ""
            if isinstance(message, TestMessage):
                urlQuery = Parameters.URL_SRV_TESTS_QUERY

            response = self._sendMessage(target, Parameters.HTTP_POST_REQUEST,
                                         urlQuery, params, headers)

            if response.status != 200:
                self.logger.warning("Wrong status received!")
                # self.send(message)
        except NoSuchProbe:
            self.logger.error(
                "The probe you requested to send a message to : '%s', is currently unknown to me.",
                message.recipientId)
        except socket.timeout as e:
            self.logger.warning(
                'Timeout occurred while sending message to %s@%s',
                message.recipientId, target.getAddress())
            raise ProbeConnectionException(e)
        except HTTPException as e:
            self.logger.error("Cannot send message to %s@%s",
                              message.recipientId, target.getAddress())
            self.logger.debug("Cannot send message", exc_info=1)
            raise ProbeConnectionException(e)
コード例 #2
0
ファイル: client.py プロジェクト: netixx/NetProbes
    def sendMessage(self, message):
        """Send this message using the Params.PROTOCOL
        :param message: The message to send
        """
        if not ProbeStorage.isKnownId(message.recipientId):
            self.logger.warning("The probe %s is not currently known to me, message will not be sent", message.targetId)
            return
        self.logger.debug("Sending the message : %s for %s to %s with ip %s",
                          message.__class__.__name__,
                          message.getTarget(),
                          message.recipientId,
                          ProbeStorage.getProbeById(message.recipientId).getIp())
        try:

            Retry.retry(times = Consts.SEND_RETRY,
                        interval = Consts.SEND_RETRY_INTERVAL,
                        failure = ProbeConnectionException,
                        eraise = ProbeConnectionException
            )(self.sender.send)(message)
        except ProbeConnectionException as e:
            raise SendError(e)
コード例 #3
0
    def sendMessage(self, message):
        """Send this message using the Params.PROTOCOL
        :param message: The message to send
        """
        if not ProbeStorage.isKnownId(message.recipientId):
            self.logger.warning(
                "The probe %s is not currently known to me, message will not be sent",
                message.targetId)
            return
        self.logger.debug(
            "Sending the message : %s for %s to %s with ip %s",
            message.__class__.__name__, message.getTarget(),
            message.recipientId,
            ProbeStorage.getProbeById(message.recipientId).getIp())
        try:

            Retry.retry(times=Consts.SEND_RETRY,
                        interval=Consts.SEND_RETRY_INTERVAL,
                        failure=ProbeConnectionException,
                        eraise=ProbeConnectionException)(
                            self.sender.send)(message)
        except ProbeConnectionException as e:
            raise SendError(e)
コード例 #4
0
ファイル: tests.py プロジェクト: netixx/NetProbes
 def getProbeIpById(probeId):
     """Returns the Ip of a probe given it's Id
     :param probeId: ID of the probe"""
     return ProbeStorage.getProbeById(probeId).getIp()
コード例 #5
0
ファイル: tests.py プロジェクト: netixx/NetProbes
 def getProbeIpById(probeId):
     """Returns the Ip of a probe given it's Id
     :param probeId: ID of the probe"""
     return ProbeStorage.getProbeById(probeId).getIp()