Beispiel #1
0
    def process_clients(self, file_path):
        """This method is used to parse the clients.xml and provides the IP,
        PORT, USERNAME, PASSWORD and EMAIL to upload_collector

        Attributes:
                file_path (str): path for clients.xml
        """
        logger.info(f"Clients file path: {file_path}")

        logger.info("Started parsing clients file")
        try:
            tree = ET.parse(file_path)
        except (ET.ParseError, FileNotFoundError) as exe:
            logger.exception(exe)
            return False

        try:
            root = tree.getroot()
            for client in root.findall("client"):
                data = self.parse_client(client)
                stats = Stats.get_or_create(**data)
                Stats.save(stats)
                upload_collector.delay(
                    data["ip"], data["port"], data["username"], data["password"]
                )
        except socket.error as e:
            logger.exception(f"Rabbitmq is not accessible. {e}")
            return False