Example #1
0
    def test_sender_with_default_logger(self):
        """
        Test that tries to check that Sender class can still use an internal
        logger and shows both local and remote
        traces
        """
        try:

            engine_config = SenderConfigSSL(address=(self.server, self.port),
                                            key=self.key,
                                            cert=self.cert,
                                            chain=self.chain,
                                            check_hostname=False,
                                            verify_mode=CERT_NONE)
            con = Sender.for_logging(config=engine_config,
                                     tag=self.my_app,
                                     level=TEST_FACILITY)
            # NOTE: this logger logging traces will be visible in console
            con.logger.info("Testing Sender default handler functionality in "
                            "local console... INFO - log")
            # NOTE: this logger logging traces will be visible in the remote
            # table
            con.info("Testing Sender default handler functionality in remote "
                     "table... INFO - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % str(error))
Example #2
0
    def test_sender_as_handler_static(self):
        """
        Test that tries to check that Sender class can be used as a Handler
        through the static functions
        and related logs are send to remote server
        """
        try:
            engine_config = {"address": self.server, "port": self.port,
                             "key": self.key, "cert": self.cert,
                             "chain": self.chain, "check_hostname": False,
                             "verify_mode": CERT_NONE}

            con = Sender.for_logging(config=engine_config, tag=self.my_app,
                                     level=TEST_FACILITY)
            logger = get_log(name="DevoLogger2", handler=con,
                             level=TEST_FACILITY)

            print("Testing logger info")
            logger.info("Testing Sender static handler functionality... "
                        "INFO - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger error")
            logger.error("Testing Sender static logging handler "
                         "functionality... ERROR - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger warning")
            logger.warning("Testing Sender static logging handler "
                           "functionality... WARNING - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger debug")
            logger.debug("Testing Sender static logging handler "
                         "functionality... DEBUG - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger critical")
            logger.critical("Testing Sender static logging handler "
                            "functionality... CRITICAL - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % str(error))
Example #3
0
    def test_sender_as_handler(self):
        """
        Test that tries to check that Sender class can be used as a Handler
        and related logs are send to remote server
        """
        try:
            engine_config = SenderConfigSSL(address=(self.server, self.port),
                                            key=self.key, cert=self.cert,
                                            chain=self.chain,
                                            check_hostname=False,
                                            verify_mode=CERT_NONE)
            con = Sender.for_logging(config=engine_config, tag=self.my_app,
                                     level=TEST_FACILITY)
            logger = get_log(name="DevoLogger", handler=con,
                             level=TEST_FACILITY)
            print("Testing logger info")
            logger.info("Testing Sender inherit logging handler functio"
                        "nality... INFO - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger error")
            logger.error("Testing Sender inherit logging handler function"
                         "ality... ERROR - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger warning")
            logger.warning("Testing Sender inherit logging handler functio"
                           "nality... WARNING - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger debug")
            logger.debug("Testing Sender inherit logging handler functiona"
                         "lity... DEBUG - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            print("Testing logger critical")
            logger.critical("Testing Sender inherit logging handler functio"
                            "nality... CRITICAL - log")
            data_received = con.socket.recv(5000)
            print(b"\n" + data_received)
            if len(data_received) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % str(error))
Example #4
0
    def test_sender_as_handler_static(self):
        """
        Test that tries to check that Sender class can be used as a Handler
        through the static functions
        and related logs are send to remote server
        """
        try:
            engine_config = {
                "address": self.server,
                "port": self.port,
                "key": self.key,
                "cert": self.cert,
                "chain": self.chain,
                "type": "SSL",
                "cert_regs": True
            }
            con = Sender.for_logging(engine_config, "SSL", self.my_app)
            logger = logging.getLogger('DEVO_logger_static')
            logger.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s|%(levelname)s|'
                                          '%(message)s')
            con.setFormatter(formatter)
            con.setLevel(logging.DEBUG)
            logger.addHandler(con)

            logger.info("Testing Sender static handler functionality... "
                        "INFO - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.error("Testing Sender static logging handler "
                         "functionality... ERROR - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.warning("Testing Sender static logging handler "
                           "functionality... WARNING - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.debug("Testing Sender static logging handler "
                         "functionality... DEBUG - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.critical("Testing Sender static logging handler "
                            "functionality... CRITICAL - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % error)
Example #5
0
    def test_sender_as_handler_static(self):
        """
        Test that tries to check that Sender class can be used as a Handler
        through the static functions
        and related logs are send to remote server
        """
        try:
            engine_config = {
                "address": self.server,
                "port": self.port,
                "key": self.key,
                "cert": self.cert,
                "chain": self.chain
            }

            con = Sender.for_logging(config=engine_config, tag=self.my_app)
            logger = get_log(name="DevoLogger2", handler=con)

            logger.info("Testing Sender static handler functionality... "
                        "INFO - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.error("Testing Sender static logging handler "
                         "functionality... ERROR - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.warning("Testing Sender static logging handler "
                           "functionality... WARNING - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.debug("Testing Sender static logging handler "
                         "functionality... DEBUG - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.critical("Testing Sender static logging handler "
                            "functionality... CRITICAL - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % str(error))
Example #6
0
    def test_sender_as_handler(self):
        """
        Test that tries to check that Sender class can be used as a Handler
        and related logs are send to remote server
        """
        try:
            engine_config = SenderConfigSSL(address=(self.server, self.port),
                                            key=self.key,
                                            cert=self.cert,
                                            chain=self.chain)
            con = Sender.for_logging(config=engine_config, tag=self.my_app)
            logger = get_log(name="DevoLogger", handler=con)
            logger.info("Testing Sender inherit logging handler functio"
                        "nality... INFO - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.error("Testing Sender inherit logging handler function"
                         "ality... ERROR - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.warning("Testing Sender inherit logging handler functio"
                           "nality... WARNING - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.debug("Testing Sender inherit logging handler functiona"
                         "lity... DEBUG - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            logger.critical("Testing Sender inherit logging handler functio"
                            "nality... CRITICAL - log")
            if len(con.socket.recv(5000)) == 0:
                raise Exception('Not msg sent!')

            con.close()
        except Exception as error:
            self.fail("Problems with test: %s" % str(error))