def crawl(self, container_id=None, **kwargs):

        try:
            import redis
        except ImportError:
            import pip
            pip.main(['install', 'redis'])
            import redis

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        port = self.get_port(c)

        if not port:
            return

        state = c.inspect['State']
        pid = str(state['Pid'])
        ips = run_as_another_namespace(
            pid, ['net'], utils.misc.get_host_ip4_addresses)

        for each_ip in ips:
            if each_ip != "127.0.0.1":
                ip = each_ip
                break

        client = redis.Redis(host=ip, port=port)

        try:
            metrics = client.info()
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]
        except:
            logger.info("redis does not listen on port:%d", port)
            raise ConnectionError("no listen at %d", port)
    def crawl(self, container_id=None, **kwargs):

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        if c.image_name.find(self.feature_key) == -1:
            logger.debug("%s is not %s container" %
                         (c.image_name, self.feature_key))
            raise NameError("this is not target crawl container")

        # extract IP and Port information
        ip = c.get_container_ip()
        ports = c.get_container_ports()

        # set default port number
        if len(ports) == 0:
            ports.append(self.default_port)

        # query to all available ports
        for port in ports:
            client = redis.Redis(host=ip, port=port)
            try:
                metrics = client.info()
            except ConnectionError:
                logger.info("redis does not listen on port:%d", port)
                continue
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]

        # any ports are not available
        raise ConnectionError("no listen ports")
    def crawl(self, container_id=None, **kwargs):

        import pip
        pip.main(['install', 'redis'])
        import redis

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        if c.image_name.find(self.feature_key) == -1:
            logger.debug("%s is not %s container" %
                         (c.image_name, self.feature_key))
            raise NameError("this is not target crawl container")

        # extract IP and Port information
        ip = c.get_container_ip()
        ports = c.get_container_ports()

        # set default port number
        if len(ports) == 0:
            ports.append(self.default_port)

        # query to all available ports
        for port in ports:
            client = redis.Redis(host=ip, port=port)
            try:
                metrics = client.info()
            except ConnectionError:
                logger.info("redis does not listen on port:%d", port)
                continue
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]

        # any ports are not available
        raise ConnectionError("no listen ports")
Пример #4
0
    def crawl(self, container_id=None, **kwargs):

        try:
            import redis
        except ImportError:
            import pip
            pip.main(['install', 'redis'])
            import redis

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        port = self.get_port(c)

        if not port:
            return

        state = c.inspect['State']
        pid = str(state['Pid'])
        ips = run_as_another_namespace(pid, ['net'],
                                       utils.misc.get_host_ip4_addresses)

        for each_ip in ips:
            if each_ip != "127.0.0.1":
                ip = each_ip
                break

        client = redis.Redis(host=ip, port=port)

        try:
            metrics = client.info()
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]
        except:
            logger.info("redis does not listen on port:%d", port)
            raise ConnectionError("no listen at %d", port)
    def crawl(self, root_dir='/', **kwargs):
        try:
            client = redis.Redis(host='localhost', port=self.default_port)
            metrics = client.info()
        except ConnectionError:
            logger.info("redis does not listen on port:%d", self.default_port)
            raise ConnectionError("no listen at %d", self.default_port)

        feature_attributes = feature.create_feature(metrics)

        return [(self.feature_key, feature_attributes, self.feature_type)]
Пример #6
0
    def crawl(self, root_dir='/', **kwargs):
        import pip
        pip.main(['install', 'redis'])
        import redis

        try:
            client = redis.Redis(host='localhost', port=self.default_port)
            metrics = client.info()
        except ConnectionError:
            logger.info("redis does not listen on port:%d", self.default_port)
            raise ConnectionError("no listen at %d", self.default_port)

        feature_attributes = feature.create_feature(metrics)

        return [(self.feature_key, feature_attributes, self.feature_type)]
Пример #7
0
 def test_redis_host_crawler_dummy(self):
     import redis
     client = redis.Redis()
     feature_attributes = create_feature(client.info())
     self.assertEqual(feature_attributes[0], -1)
 def test_redis_host_crawler_dummy(self):
     import redis
     client = redis.Redis()
     feature_attributes = create_feature(client.info())
     self.assertEqual(feature_attributes[0], -1)